Пример #1
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));
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        protected override bool DoElementHeader(Rect position, GUIContent label, InspectableObject inspectableObject)
        {
            EditorGUI.BeginChangeCheck();
            var property       = inspectableObject.FindProperty(IsOn);
            var boolReactive   = (BoolReactiveProperty)property.Value;
            var togglePosition = new Rect(position);

            togglePosition.xMin -= 8;
            togglePosition.width = 15;
            var isOn = EditorGUI.Toggle(togglePosition, boolReactive.Value);

            if (EditorGUI.EndChangeCheck())
            {
                boolReactive.Value = isOn;
                property.Value     = boolReactive;
                inspectableObject.ApplyModifiedProperties();
            }
            EditorGUI.indentLevel++;
            return(base.DoElementHeader(position, label, inspectableObject));
        }