69 lines
1.8 KiB
C#
69 lines
1.8 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
[CanEditMultipleObjects]
|
|
[CustomEditor(typeof(UAVSimulator))]
|
|
public class UAVSimulatorEditor : Editor
|
|
{
|
|
private UAVSimulator tar;
|
|
|
|
private void OnEnable()
|
|
{
|
|
tar = (UAVSimulator)target;
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
serializedObject.Update();
|
|
EditorGUILayout.BeginVertical();
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
if (GUILayout.Button("开机"))
|
|
tar.StartUav();
|
|
if (GUILayout.Button("关机"))
|
|
tar.ShutDownUAV();
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
EditorGUILayout.Space(5);
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
if (GUILayout.Button("手动旋翼"))
|
|
tar.ManualSpeed();
|
|
if (GUILayout.Button("自动旋翼"))
|
|
tar.AutoSpeed();
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
EditorGUILayout.Space(5);
|
|
|
|
if(GUILayout.Button("重置无人机"))
|
|
tar.ResetUAV();
|
|
|
|
EditorGUILayout.EndVertical();
|
|
|
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
base.OnInspectorGUI();
|
|
}
|
|
|
|
private void OnSceneGUI()
|
|
{
|
|
//操作句柄
|
|
//Handles.Label(tar.transform.position, tar.transform.name + " : " + tar.transform.position);
|
|
|
|
//绘制GUI的内容必须要在BeginGUI、EndGUI的方法对中
|
|
Handles.BeginGUI();
|
|
//设置GUI绘制的区域
|
|
GUILayout.BeginArea(new Rect(50, 50, 200, 200));
|
|
GUILayout.Label("Scene 扩展练习");
|
|
GUILayout.Label("三周姿态角:" + tar.controller.transform.rotation.eulerAngles);
|
|
GUILayout.Label("加速度:" + tar.controller.rigid_acceleration);
|
|
GUILayout.Label("坐标:" + tar.controller.transform.position);
|
|
GUILayout.EndArea();
|
|
Handles.EndGUI();
|
|
}
|
|
}
|