Odin Inspector 系列教程 --- Display As String Attribute

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.";
}

更多教程內容詳見:革命性Unity 編輯器擴展工具 --- Odin Inspector 系列教程

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容