用于单独Reset transform的三个属性:localposition、localrotation、localScale。
//----------------------------------------------
// Transform值一键复位
// Copyright © 2012-2015 xiaobao1993.com
//----------------------------------------------
using unityEngine;
using UnityEditor;
[CanEditMultipleObjects]
[CustomEditor(typeof(Transform), true)]
public class TransformInspector : Editor
{
static public TransformInspector instance;
SerializedProperty mPos;
SerializedProperty mRot;
SerializedProperty mScale;
void OnEnable()
{
instance = this;
mPos = serializedObject.FindProperty("m_LocalPosition");
mRot = serializedObject.FindProperty("m_LocalRotation");
mScale = serializedObject.FindProperty("m_LocalScale");
}
void OnDestroy() { instance = null; }
///
/// 开始绘制Transform
///
public override void OnInspectorGUI()
{
EditorGUIUtility.labelWidth = 15;
serializedObject.Update();
DrawPosition();
DrawRotation();
DrawScale();
serializedObject.ApplyModifiedProperties();
}
///
/// 绘制坐标
///
void DrawPosition()
{
GUILayout.BeginHorizontal();
{
bool reset = GUILayout.Button("P", GUILayout.Width(20f));
EditorGUILayout.PropertyField(mPos.FindPropertyRelative("x"));
EditorGUILayout.PropertyField(mPos.FindPropertyRelative("y"));
EditorGUILayout.PropertyField(mPos.FindPropertyRelative("z"));
if (reset) mPos.vector3Value = Vector3.zero;
}
GUILayout.EndHorizontal();
}
///
/// 绘制形变
///
void DrawScale()
{
GUILayout.BeginHorizontal();
{
bool reset = GUILayout.Button("S", GUILayout.Width(20f));
EditorGUILayout.PropertyField(mScale.FindPropertyRelative("x"));
EditorGUILayout.PropertyField(mScale.FindPropertyRelative("y"));
EditorGUILayout.PropertyField(mScale.FindPropertyRelative("z"));
if (reset) mScale.vector3Value = Vector3.one;
}
GUILayout.EndHorizontal();
}
#region 旋转个坑爹玩意......因为四元属性绘制没有原生支持
enum Axes : int
{
None = 0,
X = 1,
复制代码
联系方式:0755-81699111
课程网址 : http://www.vrkuo.com/course/vr.html