|
FilePath放到string变量上你会得到一个按钮,可以打开资源浏览器来选择文件,并且复制给这个字符串
- [FilePath(Extensions = ".unity")]
- public string ScenePath;
复制代码Button无参函数上,可以传入枚举,申明大小得到按钮,点击会调用该函数
- [Button(ButtonSizes.Large)]
- public void SayHello()
- {
- Debug.Log("Hello button!");
- }
复制代码HideInInspector 和 ShowInInspector显示或隐藏到Inspector面板支持属性,没有序列化功能
- [HideInInspector]
- public int NormallyVisible;
- [ShowInInspector]
- private bool normallyHidden;
- [ShowInInspector]
- public ScriptableObject Property { get; set; }
复制代码PreviewField可以预览GameObject
- [PreviewField]
- public GameObject Prefab;
复制代码Required放在可null参数上如string,如果为null,报错
- [Required]
- public string username;
复制代码AssetsOnly可以申明GameObject的来源为Prefab,而不是Scenes
- [PreviewField, AssetsOnly]
- public GameObject Prefab;
复制代码PropertyOrder(数值)数值越低,越在上面,越高越在下面,可以负值
- [PropertyOrder(-5)]
- public GameObject Prefab;
复制代码HideLabel 隐藏标签PreviewField 设置大小HorizontalGroup 和 VerticalGroup水平布局和数值布局
- [HorizontalGroup("Split", Width = 50), HideLabel, PreviewField(50)]
- public Texture2D Icon;
- [VerticalGroup("Split/Properties")]
- public string MinionName;
- [VerticalGroup("Split/Properties")]
- public float Health;
- [VerticalGroup("Split/Properties")]
- public float Damage;
复制代码- [LabelText("$IAmLabel")]
- public string IAmLabel;
复制代码ListDrawSettings设置List的增加按钮和删除按钮的功能
- [ListDrawerSettings(
- CustomAddFunction = "CreateNewGUID",
- CustomRemoveIndexFunction = "RemoveGUID")]
- public List<string> GuidList;
- private string CreateNewGUID()
- {
- return Guid.NewGuid().ToString();
- }
- private void RemoveGUID(int index)
- {
- this.GuidList.RemoveAt(index);
- }
复制代码- [TabGroup(&#34;First Tab&#34;)]
- public int FirstTab;
- [ShowInInspector, TabGroup(&#34;First Tab&#34;)]
- public int SecondTab { get; set; }
- [TabGroup(&#34;Second Tab&#34;)]
- public float FloatValue;
- [TabGroup(&#34;Second Tab&#34;), Button]
- public void Button()
- {
- ...
- }
复制代码复杂布局FoldoutGroup 和 HorizontalGroup 和 BoxGroup
- [Button(ButtonSizes.Large)]
- [FoldoutGroup(&#34;Buttons in Boxes&#34;)]
- [HorizontalGroup(&#34;Buttons in Boxes/Horizontal&#34;, Width = 60)]
- [BoxGroup(&#34;Buttons in Boxes/Horizontal/One&#34;)]
- public void Button1() { }
- [Button(ButtonSizes.Large)]
- [BoxGroup(&#34;Buttons in Boxes/Horizontal/Two&#34;)]
- public void Button2() { }
- [Button]
- [BoxGroup(&#34;Buttons in Boxes/Horizontal/Double&#34;)]
- public void Accept() { }
- [Button]
- [BoxGroup(&#34;Buttons in Boxes/Horizontal/Double&#34;)]
- public void Cancel() { }
复制代码ValidateInput 验证输入传入函数,函数返回bool,如果为false,会在Inspector报错
- [ValidateInput(&#34;IsValid&#34;)]
- public int GreaterThanZero;
- private bool IsValid(int value)
- {
- return value > 0;
- }
复制代码OnValueChanged 只改变传入函数,值改变时调用
- [OnValueChanged(&#34;UpdateRigidbodyReference&#34;)]
- public GameObject Prefab;
- private Rigidbody prefabRigidbody;
- private void UpdateRigidbodyReference()
- {
- if (this.Prefab != null)
- {
- this.prefabRigidbody = this.Prefab.GetComponent<Rigidbody>();
- }
- else
- {
- this.prefabRigidbody = null;
- }
- }
复制代码InfoBox 信息盒子传入信息和函数,如果函数返回true,Inspector显示信息
- [InfoBox(&#34;This message is only shown when MyInt is even&#34;, &#34;IsEven&#34;)]
- public int MyInt;
- private bool IsEven()
- {
- return this.MyInt % 2 == 0;
- }
复制代码@ 申明字符串为代码$property访问当前成员#能够引用范围内变量ShowIf 能够直接进行判断是否应该显示该字段
- [InfoBox(&#34;@myStr&#34;)]
- public string myStr;
- [InfoBox(@&#34;@&#34;&#34;The current time is: &#34;&#34; + DateTime.Now.ToString(&#34;&#34;HH:mm:ss&#34;&#34;)&#34;)]
- public string myStr;
- [ShowIf(&#34;@this.someNumber >= 0f && this.someNumber <= 10f&#34;)]
- public string myStr;
- public List<string> someList;
- [OnValueChanged(&#34;@#(someList).State.Expanded = $value&#34;)]
- public bool expandList;
复制代码OdinEditorWindow 制作一个Window
- public class SomeWindow : OdinEditorWindow
- {
- [MenuItem(&#34;My Game/My Window&#34;)]
- private static void OpenWindow()
- {
- GetWindow<SomeWindow>().Show();
- }
-
- [PropertyOrder(-10)]
- [HorizontalGroup]
- [Button(ButtonSizes.Large)]
- public void SomeButton1() { }
- [HorizontalGroup]
- [Button(ButtonSizes.Large)]
- public void SomeButton2() { }
- [HorizontalGroup]
- [Button(ButtonSizes.Large)]
- public void SomeButton3() { }
- [HorizontalGroup]
- [Button(ButtonSizes.Large), GUIColor(0, 1, 0)]
- public void SomeButton4() { }
- [HorizontalGroup]
- [Button(ButtonSizes.Large), GUIColor(1, 0.5f, 0)]
- public void SomeButton5() { }
- [TableList]
- public List<SomeType> SomeTableData;
- }
- public class SomeType
- {
- [TableColumnWidth(50)]
- public bool Toggle;
- [AssetsOnly]
- public GameObject SomePrefab;
- public string Message;
- [TableColumnWidth(160)]
- [HorizontalGroup(&#34;Actions&#34;)]
- public void Test1() { }
- [HorizontalGroup(&#34;Actions&#34;)]
- public void Test2() { }
- }
复制代码 |
|