UnityEditorUnity编辑器开发分享插件推荐

Unity插件 Odininspector 使用小记 (一)

2018-02-04  本文已影响304人  amosbake

Odin 是目前最牛的编辑器定制化工具,可以轻松完成属性的可视化编辑.

开始使用

#if UNITY_EDITOR

    using Sirenix.Utilities.Editor;

#endif

基础

   [Title("Advanced List Customization")]
   [InfoBox("Using [ListDrawerSettings], lists can be customized in a wide variety of ways.")]
 [ReadOnly]
 public int[] ReadOnlyArray2 = new int[] { 1, 2, 3 };

进阶

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
上一篇下一篇

猜你喜欢

热点阅读