制作一个显示transform, rotation, scal
在Editor文件夹中创建脚本InspectorTest
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(Test))]
public class InspectorTest : Editor {
public override void OnInspectorGUI()
{
Test myTest = (Test)target;
myTest.myTransform = myTest.transform;
myTest.myTransform.position = EditorGUILayout.Vector3Field("MyPosition", myTest.transform.position);
EditorGUILayout.Space();
Quaternion rot = myTest.transform.rotation; //将Quaternion转换为 Vector3
Vector3 rotation = new Vector3(rot.eulerAngles.x, rot.eulerAngles.y, rot.eulerAngles.z);
myTest.myRotation = EditorGUILayout.Vector3Field("myRotation", rotation);
myTest.myLocal = EditorGUILayout.Vector3Field("myLocal",
myTest.transform.localScale);
myTest.number = EditorGUILayout.IntField("number ", myTest.number);
}
}
Test脚本如下,将其拖拽到需要绘制的对象即可
using UnityEngine;
using System.Collections;
using UnityEditor;
public class Test : MonoBehaviour {
public Transform myTransform;
public Vector3 myRotation;
public Vector3 myLocal;
public int number;
}