[英]How to tell if a SerializedProperty is part of an array in Unity?
I have a struct Stat
我有一个结构
Stat
[Serializable]
public struct Stat {
public string key;
public string value;
}
I want it to display in the editor as a single line property with the label when it is a single non-array field, but when it is a part of an array I want to hide the label, how can I do this?当它是单个非数组字段时,我希望它在编辑器中显示为带有 label 的单行属性,但是当它是数组的一部分时,我想隐藏 label,我该怎么做?
This can be done in a PropertyDrawer
as follows,这可以在
PropertyDrawer
中完成,如下所示,
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label ) {
if(!property.propertyPath.EndsWidth(']')) {// This tells if the property is a member of an array
position = EditorGUI.PrefixLabel(position,label);
// Remainder of Property Drawer
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.