Show In Inspector Attribute特性:用于任何成員,并在inspector中顯示該值。請記住,ShowInInspector特性不會序列化任何內容; 這意味著您所做的任何更改都不會僅僅使用ShowInInspector屬性進行保存。
如果需要序列化,需要配合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}");
}
}