找回密码
 立即注册
查看: 561|回复: 0

Unity 插件 Odin

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

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-23 19:03 , Processed in 0.309068 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表