DisplayAsString特性:用于任何屬性,對應的值在檢查器中以文本形式顯示字符串。如果屬性的值要在檢查器中顯示字符串,但不允許進行任何編輯,請使用此選項。
【DisplayAsString】直接以文本的展示value
[DisplayAsString]
public Color SomeColor;
[PropertySpace(40)]
[DisplayAsString]
public GameObject Obj;
[PropertySpace(40)]
[HideLabel]
[DisplayAsString]
public string SomeText = "SomeText對應的Label已經被隱藏,你現在看到的是他對應的內容(Value)";
【Overflow】也可以控制顯示是否自動換行
[PropertySpace(40)]
[HideLabel]
[DisplayAsString]
public string Overflow = "A very very very very very very very very very long string that has been configured to overflow.";
[PropertySpace(40)]
[HideLabel]
[DisplayAsString(false)]//這是為false時,如果inspector顯示空間不足,則自動換行
public string DisplayAllOfIt = "A very very very very very very very very long string that has been configured to not overflow.";
完整示例代碼
using UnityEngine;
using Sirenix.OdinInspector;
public class DisplayAsStringAttributeExample : MonoBehaviour
{
[DisplayAsString]
public Color SomeColor;
[PropertySpace(40)]
[DisplayAsString]
public GameObject Obj;
[PropertySpace(40)]
[HideLabel]
[DisplayAsString]
public string SomeText = "SomeText對應的Label已經被隱藏,你現在看到的是他對應的內容(Value)";
[PropertySpace(40)]
[HideLabel]
[DisplayAsString]
public string Overflow = "A very very very very very very very very very long string that has been configured to overflow.";
[PropertySpace(40)]
[HideLabel]
[DisplayAsString(false)]//這是為false時,如果inspector顯示空間不足,則自動換行
public string DisplayAllOfIt = "A very very very very very very very very long string that has been configured to not overflow.";
}