Odin 是目前最牛的编辑器定制化工具,可以轻松完成属性的可视化编辑.
开始使用
#if UNITY_EDITOR
using Sirenix.Utilities.Editor;
#endif
基础
- 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 属性展示顺序
image
-
[TabGroup] 分组显示
image
进阶
-
校验数据有效性
Valid
Required
Array
-
下拉列表选择
image -
Range 支持 array
[Range(0, 1)]
public float[] FloatRangeArray;
- 设置列表自动分页
[ListDrawerSettings(NumberOfItemsPerPage = 5)]
public int[] FiveItemsPerPage;
屏幕快照 2018-02-04 上午7.40.01.png
- 为列表项设置标签
[ListDrawerSettings(ShowIndexLabels = true, ListElementLabelName = "SomeString")]
屏幕快照 2018-02-04 上午7.43.50.png
- 自定义显示样式和按钮方法
[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
屏幕快照 2018-02-04 上午8.19.21.png
网友评论