Odin 是目前最牛的編輯器定制化工具,可以輕松完成屬性的可視化編輯.
開始使用
#if UNITY_EDITOR
using Sirenix.Utilities.Editor;
#endif
基礎(chǔ)
- Title
- InfoBox
[Title("Advanced List Customization")]
[InfoBox("Using [ListDrawerSettings], lists can be customized in a wide variety of ways.")]
- ReadOnly -- 只讀屬性
[ReadOnly]
public int[] ReadOnlyArray2 = new int[] { 1, 2, 3 };
-
PropertyOrder 屬性展示順序
-
[TabGroup] 分組顯示
進(jìn)階
-
校驗(yàn)數(shù)據(jù)有效性
Array
-
下拉列表選擇
Range 支持 array
[Range(0, 1)]
public float[] FloatRangeArray;
- 設(shè)置列表自動分頁
[ListDrawerSettings(NumberOfItemsPerPage = 5)]
public int[] FiveItemsPerPage;
- 為列表項(xiàng)設(shè)置標(biāo)簽
[ListDrawerSettings(ShowIndexLabels = true, ListElementLabelName = "SomeString")]
- 自定義顯示樣式和按鈕方法
[ListDrawerSettings(OnBeginListElementGUI = "BeginDrawListElement", OnEndListElementGUI = "EndDrawListElement")]
public SomeStruct[] InjectListElementGUI;
[ListDrawerSettings(HideAddButton = true, OnTitleBarGUI = "DrawAddButton")]
public List<int> CustomButtons;
#if UNITY_EDITOR
private void BeginDrawListElement(int index)
{
SirenixEditorGUI.BeginBox(this.InjectListElementGUI[index].SomeString);
}
private void EndDrawListElement(int index)
{
SirenixEditorGUI.EndBox();
}
private void DrawAddButton()
{
if (SirenixEditorGUI.ToolbarButton(EditorIcons.Plus))
{
this.CustomButtons.Add(Random.Range(0, 100));
}
GUIHelper.PushGUIEnabled(GUI.enabled && this.CustomButtons.Count > 0);
if (SirenixEditorGUI.ToolbarButton(EditorIcons.Minus))
{
this.CustomButtons.RemoveAt(this.CustomButtons.Count - 1);
}
GUIHelper.PopGUIEnabled();
}
#endif