コード例 #1
0
        public static void RevertPrefabPropertyOverride(object userData)
        {
            RuntimeSerializedProperty runtimeSerializedProperty = userData as RuntimeSerializedProperty;
            SerializedProperty        serializedProperty        = runtimeSerializedProperty.RuntimeSerializedObject.ParentProperty as SerializedProperty;

            if (serializedProperty == null)
            {
                Debug.LogError("Revert Value to Prefab is not supported on Nested Runtime Serialized Property!");
                return;
            }
            int index;
            var parentProperty = serializedProperty.GetBelongArrayAndIndex(out index);

            if (index >= 0)
            {
#if UNITY_2018_2_OR_NEWER
                Object prefab = PrefabUtility.GetCorrespondingObjectFromSource(parentProperty.serializedObject.targetObject);
#else
                Object prefab = PrefabUtility.GetPrefabParent(parentProperty.serializedObject.targetObject);
#endif
                SerializedObject   serializedObject = new SerializedObject(prefab);
                SerializedProperty prop             = serializedObject.FindProperty(parentProperty.propertyPath);

                parentProperty.arraySize = prop.arraySize;
                for (int i = 0; i < parentProperty.arraySize; i++)
                {
                    var obj1 = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(parentProperty.GetArrayElementAtIndex(i));
                    var obj2 = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(prop.GetArrayElementAtIndex(i), RuntimeObject.FromJson(prop.GetArrayElementAtIndex(i).stringValue));
                    obj1.Target = obj2.Target;
                    obj1.ForceReloadProperties();
                }

                EditorUtilityHelper.ForceReloadInspectors();
            }
        }
コード例 #2
0
        public static void DeleteArrayElement(object userData)
        {
            RuntimeSerializedProperty runtimeSerializedProperty = userData as RuntimeSerializedProperty;

            runtimeSerializedProperty.DeleteCommand();
            EditorUtilityHelper.ForceReloadInspectors();
        }
コード例 #3
0
        public static void PasteAllComponents(object userData)
        {
            SerializedProperty serializedProperty = userData as SerializedProperty;

            if (CanPaste(serializedProperty))
            {
                List <string> pastedTypes = new List <string>();
                for (int i = 0; i < serializedProperty.arraySize; i++)
                {
                    var obj = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(serializedProperty.GetArrayElementAtIndex(i));

                    if (Clipboard.ContainsKey(obj.Type))
                    {
                        obj.Target = Clipboard[obj.Type].Target;
                        obj.ForceReloadProperties();
                        pastedTypes.Add(obj.Type);
                    }
                }

                foreach (var kvp in Clipboard)
                {
                    if (pastedTypes.Contains(kvp.Key))
                    {
                        continue;
                    }
                    serializedProperty.arraySize++;
                    var prop = serializedProperty.GetArrayElementAtIndex(serializedProperty.arraySize - 1);
                    var obj  = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(prop);
                    obj.Target = Clipboard[obj.Type].Target;
                    obj.ForceReloadProperties();
                }

                EditorUtilityHelper.ForceReloadInspectors();
            }
        }
コード例 #4
0
        public static void PasteComponentValues(object userData)
        {
            RuntimeSerializedProperty runtimeSerializedProperty = userData as RuntimeSerializedProperty;

            runtimeSerializedProperty.RuntimeSerializedObject.Target = Clipboard[runtimeSerializedProperty.RuntimeSerializedObject.Type].Target;
            runtimeSerializedProperty.RuntimeSerializedObject.ForceReloadProperties();
            EditorUtilityHelper.ForceReloadInspectors();
        }
コード例 #5
0
        public static void PasteComponentAsNew(object userData)
        {
            RuntimeSerializedProperty runtimeSerializedProperty = userData as RuntimeSerializedProperty;
            SerializedProperty        serializedProperty        = runtimeSerializedProperty.RuntimeSerializedObject.ParentProperty as SerializedProperty;

            if (serializedProperty == null)
            {
                Debug.LogError("Paste Component As New is not supported on Nested Runtime Serialized Property!");
                return;
            }
            int index;
            var parentProperty = serializedProperty.GetBelongArrayAndIndex(out index);

            if (index >= 0)
            {
                parentProperty.arraySize++;
                parentProperty.GetArrayElementAtIndex(parentProperty.arraySize - 1).stringValue = Data;
                parentProperty.serializedObject.ApplyModifiedProperties();
            }
            EditorUtilityHelper.ForceReloadInspectors();
        }
コード例 #6
0
        public static void RevertPrefabPropertyOverride(object userData)
        {
            SerializedProperty parentProperty = userData as SerializedProperty;

#if UNITY_2018_2_OR_NEWER
            Object prefab = PrefabUtility.GetCorrespondingObjectFromSource(parentProperty.serializedObject.targetObject);
#else
            Object prefab = PrefabUtility.GetPrefabParent(parentProperty.serializedObject.targetObject);
#endif
            SerializedObject   serializedObject = new SerializedObject(prefab);
            SerializedProperty prop             = serializedObject.FindProperty(parentProperty.propertyPath);

            parentProperty.arraySize = prop.arraySize;
            for (int i = 0; i < parentProperty.arraySize; i++)
            {
                var obj1 = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(parentProperty.GetArrayElementAtIndex(i));
                var obj2 = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(prop.GetArrayElementAtIndex(i), RuntimeObject.FromJson(prop.GetArrayElementAtIndex(i).stringValue));
                obj1.Target = obj2.Target;
                obj1.ForceReloadProperties();
            }

            EditorUtilityHelper.ForceReloadInspectors();
        }