本文主要是介绍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 系列教程
这篇关于Odin Inspector 系列教程 --- Display As String Attribute的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!