Unity Odin (实现如图所示效果)(五)
代码
using UnityEngine;
public class Test5 : MonoBehaviour
{
public string top;
public string middle;
public string bottom;
public int value1;
public int value2;
public int value3;
}
public enum MyEnum
{
Zero,
One,
Two,
Three,
Four
}
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using UnityEngine;
public class Test5PropertyProcessor<T> : OdinPropertyProcessor<T> where T : Test5
{
public override void ProcessMemberProperties(List<InspectorPropertyInfo> propertyInfos)
{
for (var i = 0; i < propertyInfos.Count; i++)
{
if (propertyInfos[i].PropertyName != "bottom") continue;
propertyInfos.Insert(0, propertyInfos[i]);
propertyInfos.RemoveAt(i + 1);
}
propertyInfos.AddDelegate("Print Hello", () => Debug.Log("Hello"),
new BoxGroupAttribute("Box Tool", centerLabel: true), new PropertySpaceAttribute(10));
propertyInfos.AddValue("New Value", (ref Test5 t) => t.value1 + t.value2 + t.value3,
(ref Test5 instance, int value) => { }, new BoxGroupAttribute("New"));
propertyInfos.AddValue("New Enum", (ref Test5 t) => (MyEnum) t.value1,
(ref Test5 instance, MyEnum value) => instance.value1 = (int) value, new EnumToggleButtonsAttribute(),
new BoxGroupAttribute("New"));
}
}
|