Odin Attributes 为Unity开发者提供了更多的自定义选项,使得开发过程更加高效和愉悦。通过使用这些特性,开发者可以创建更加专业和用户友好的编辑器界面,从而提升整个开发团队的工作效率。
Show In Inspector 特性:用于任何成员,并在 Inspector 中显示该值。
注意,ShowInInspector 特性不会序列化任何内容;这意味着您所做的任何更改都不会保存(仅使用 ShowInInspector 特性)。
根据经验:任何未显示在 Inspector 中且没有 ShowInInspector 特性的字段或属性都不会被序列化。 使用 Serialization Debugger 可以更好地了解类中序列化的内容和未序列化的内容。
如果需要序列化,需要配合 SerializeField 特性使用。
using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShowInInspectorExample : MonoBehaviour
{
[ShowInInspector]
private int myPrivateInt;
[ShowInInspector]
public int MyPropertyInt { get; set; }
[ShowInInspector]
public int ReadOnlyProperty
{
get { return this.myPrivateInt; }
}
[ShowInInspector]
public static bool StaticProperty { get; set; }
private void Start()
{
Debug.Log($"{MyPropertyInt}");
}
}