コード例 #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (_displayScriptableAttribute is null)
            {
                _displayScriptableAttribute = attribute as DisplayScriptableAttribute;
            }
            EditorGUI.BeginProperty(position, label, property);
            if (property.objectReferenceValue != null)
            {
                DisplayScriptableObject(position, property, label);
            }
            else
            {
                DisplayEmptyObject(position, property, label);
            }

            property.serializedObject.ApplyModifiedProperties();
            EditorGUI.EndProperty();
        }
コード例 #2
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            if (_displayScriptableAttribute is null)
            {
                _displayScriptableAttribute = attribute as DisplayScriptableAttribute;
            }
            var totalHeight = EditorGUIUtility.singleLineHeight;

            if (!IsThereAnyVisibleProperty(property))
            {
                return(totalHeight);
            }
            if (property.isExpanded)
            {
                var data = property.objectReferenceValue as ScriptableObject;
                if (data == null)
                {
                    return(EditorGUIUtility.singleLineHeight);
                }
                var serializedObject = new SerializedObject(data);
                var prop             = serializedObject.GetIterator();
                if (prop.NextVisible(true))
                {
                    do
                    {
                        if (prop.name == "m_Script" && !_displayScriptableAttribute.DisplayScript)
                        {
                            continue;
                        }
                        var subProp = serializedObject.FindProperty(prop.name);
                        var height  = EditorGUI.GetPropertyHeight(subProp, null, true) +
                                      EditorGUIUtility.standardVerticalSpacing;
                        totalHeight += height;
                    } while (prop.NextVisible(false));
                }

                // Add a tiny bit of height if open for the background
                totalHeight += EditorGUIUtility.standardVerticalSpacing;
            }

            return(totalHeight);
        }