Пример #1
0
        public static bool TryDrawInspectableObject(Rect position, SerializedProperty property, bool drawObjectReference = false, System.Func <Rect, GUIContent, InspectableObject, bool> elementHeaderHandler = null, System.Action <Rect, InspectableObject> elementFooterHandler = null)
        {
            var data = property.GetInspectableObjectData();

            if (data != null)
            {
                var inspectableObject = InspectableObject.CreateInstance(property, data);
                if (inspectableObject != null)
                {
                    var iterProp = inspectableObject.GetIterator();
                    var depth    = iterProp.Depth;
                    var index    = 0;

                    position.height = 0f;
                    do
                    {
                        if (depth != iterProp.Depth || (index > 0 && !inspectableObject.IsExpanded))
                        {
                            break;
                        }

                        var displayName = new GUIContent(iterProp.DisplayName);

                        if (index == 0)
                        {
                            position.height = GetPropertyHeight(iterProp, GUIContent.none, iterProp.IsExpanded);
                            PropertyField(position, iterProp, GUIContent.none, iterProp.IsExpanded);
                            if (elementHeaderHandler != null)
                            {
                                elementHeaderHandler(position, displayName, inspectableObject);
                            }
                            else
                            {
                                TryDrawDefaultElementHeader(position, displayName, inspectableObject);
                            }
                        }

                        position.yMin += position.height;

                        EditorGUI.indentLevel++;
                        position.height = GetObjectReferenceHeight(iterProp, drawObjectReference);
                        if (TryDrawObjectReference(position, iterProp, displayName, drawObjectReference))
                        {
                        }
                        else if (index > 0)
                        {
                            position.height = GetPropertyHeight(iterProp, displayName, iterProp.IsExpanded);
                            PropertyField(position, iterProp, displayName, iterProp.IsExpanded);
                        }
                        EditorGUI.indentLevel--;
                        index++;
                    } while (iterProp.NextVisible(false));

                    elementFooterHandler?.Invoke(position, inspectableObject);
                    inspectableObject.ApplyModifiedProperties();
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        public static void SetPrefabOverride(object userData)
        {
            InspectableProperty inspectableProperty = userData as InspectableProperty;

            if (inspectableProperty != null && inspectableProperty.Type != NullableStr)
            {
#if UNITY_2018_2_OR_NEWER
                Object prefab = PrefabUtility.GetCorrespondingObjectFromSource(inspectableProperty.InspectableObject.SerializedObject.targetObject);
#else
                Object prefab = PrefabUtility.GetPrefabParent(inspectableProperty.InspectableObject.SerializedObject.targetObject);
#endif
                SerializedObject   serializedObject   = new SerializedObject(prefab);
                SerializedProperty serializedProperty = serializedObject.FindProperty(inspectableProperty.InspectableObject.Path);
                InspectableObject  inspectableObject  = InspectableObject.CreateInstance(serializedProperty);
                inspectableProperty.Value = inspectableObject.FindProperty(inspectableProperty.PropertyPath).Value;
                inspectableProperty.InspectableObject.ApplyModifiedProperties();
            }
            else
            {
                InspectableObject inspectableObject = inspectableProperty == null ? userData as InspectableObject : inspectableProperty.InspectableObject;
                if (inspectableObject != null)
                {
                    InspectableProperty prop = inspectableObject.GetIterator();
                    while (prop.Next(true))
                    {
                        SetPrefabOverride(prop);
                    }
                }
                else
                {
                    SerializedProperty serializedProperty = userData as SerializedProperty;
                    if (serializedProperty != null && serializedProperty.IsInspectableObjectDataArrayOrList())
                    {
                        for (int i = 0; i < serializedProperty.arraySize; i++)
                        {
                            SerializedProperty prop = serializedProperty.GetArrayElementAtIndex(i);
                            if (prop.IsInspectableObjectData())
                            {
                                SetPrefabOverride(InspectableObject.CreateInstance(prop));
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        public static float GetInspectableObjectHeight(SerializedProperty property, bool drawObjectReference = false)
        {
            var height  = 0f;
            var height2 = 0f;
            var data    = property.GetInspectableObjectData();

            if (data != null)
            {
                var inspectableObject = InspectableObject.CreateInstance(property, data);
                if (inspectableObject != null)
                {
                    var iterProp = inspectableObject.GetIterator();
                    int depth    = iterProp.Depth;
                    do
                    {
                        if (depth != iterProp.Depth)
                        {
                            break;
                        }
                        height2 = GetObjectReferenceHeight(iterProp, drawObjectReference);
                        if (height2 == 0f)
                        {
                            height += GetPropertyHeight(iterProp, new GUIContent(iterProp.DisplayName), iterProp.IsExpanded);
                        }
                        else
                        {
                            height += height2;
                        }
                        if (!inspectableObject.IsExpanded)
                        {
                            break;
                        }
                    } while (iterProp.NextVisible(false));
                }
                else
                {
                    height += EditorGUIUtility.singleLineHeight;
                }
            }
            return(height);
        }