コード例 #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 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();
            }
        }
コード例 #3
0
        public override float GetPropertyHeight(RuntimeSerializedProperty property, GUIContent label)
        {
            var height = 0f;

            if (string.IsNullOrEmpty(property.StringValue))
            {
                height += EditorGUIUtility.singleLineHeight;
            }
            else
            {
                var runtimeSerializedObject = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(property);

                height += GetRuntimeObjectHeight(runtimeSerializedObject);
            }
            return(height);
        }
コード例 #4
0
        public override void OnGUI(Rect position, RuntimeSerializedProperty property, GUIContent label)
        {
            if (string.IsNullOrEmpty(property.StringValue))
            {
                var style = new GUIStyle();
                style.richText = true;
                EditorGUI.LabelField(position, "<color=red>Missing</color>", style);
            }
            else
            {
                var runtimeSerializedObject = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(property);

                DrawRuntimeObject(position, runtimeSerializedObject);

                runtimeSerializedObject.ApplyModifiedProperties();
            }
        }
コード例 #5
0
        public static void CopyAllComponents(object userData)
        {
            SerializedProperty serializedProperty = userData as SerializedProperty;

            if (serializedProperty != null && serializedProperty.isArray && serializedProperty.arrayElementType == StringType)
            {
                Clipboard.Clear();
                for (int i = 0; i < serializedProperty.arraySize; i++)
                {
                    var obj = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(serializedProperty.GetArrayElementAtIndex(i));

                    if (Clipboard.ContainsKey(obj.Type))
                    {
                        Clipboard[obj.Type] = obj;
                    }
                    else
                    {
                        Clipboard.Add(obj.Type, obj);
                    }
                }
            }
        }
コード例 #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();
        }