DisplayAsString特性:用于任何屬性路鹰,對應的值在檢查器中以文本形式顯示字符串岭皂。如果屬性的值要在檢查器中顯示字符串,但不允許進行任何編輯铅碍,請使用此選項。
【DisplayAsString】直接以文本的展示value
[DisplayAsString]
public Color SomeColor;
[PropertySpace(40)]
[DisplayAsString]
public GameObject Obj;
[PropertySpace(40)]
[HideLabel]
[DisplayAsString]
public string SomeText = "SomeText對應的Label已經(jīng)被隱藏捌治,你現(xiàn)在看到的是他對應的內(nèi)容(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已經(jīng)被隱藏肖油,你現(xiàn)在看到的是他對應的內(nèi)容(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.";
}