Unity Odin (实现如图所示效果)(六)
代码
using UnityEngine;
public class Test6 : MonoBehaviour
{
public MySubClass mySubClass;
}
[System.Serializable]
public class MySubClass
{
public string text;
public int num;
public Vector3 location;
}
using Sirenix.OdinInspector.Editor;
using Sirenix.Utilities;
using Sirenix.Utilities.Editor;
using UnityEditor;
using UnityEngine;
public class MySubClassDraw : OdinValueDrawer<MySubClass>
{
private InspectorProperty text;
private InspectorProperty number;
private InspectorProperty location;
protected override void Initialize()
{
text = this.Property.Children["text"];
number = this.Property.Children["num"];
location = this.Property.Children["location"];
}
protected override void DrawPropertyLayout(GUIContent label)
{
var rect = EditorGUILayout.GetControlRect();
EditorGUI.PrefixLabel(rect, label);
rect = EditorGUILayout.GetControlRect();
GUIHelper.PushLabelWidth(75);
text.ValueEntry.WeakSmartValue = SirenixEditorFields.TextField(rect.Split(1, 2), "Text", (string)text.ValueEntry.WeakSmartValue);
number.ValueEntry.WeakSmartValue = SirenixEditorFields.IntField(rect.Split(0, 2), "Number", (int)number.ValueEntry.WeakSmartValue);
location.ValueEntry.WeakSmartValue = SirenixEditorFields.Vector3Field("Location", (Vector3)location.ValueEntry.WeakSmartValue);
GUIHelper.PopLabelWidth();
}
}