示例#1
0
        public static void Copy(SerializedProperty feedbackList)
        {
            if (feedbackList == null)
            {
                return;
            }

            CopiedFeedbacks.Clear();

            for (int i = 0; i < feedbackList.arraySize; i++)
            {
                SerializedProperty prop = feedbackList.GetArrayElementAtIndex(i);

                FeedbackCopyData data = new FeedbackCopyData {
                    type = prop.objectReferenceValue.GetType(),
                };

                SerializedProperty property = new SerializedObject(prop
                                                                   .objectReferenceValue).GetIterator();
                property.Next(true);

                do
                {
                    if (!FeedbackCopyHelper.IgnoreList.Contains(property.name))
                    {
                        data.properties.Add(property.Copy());
                    }
                } while (property.Next(false));

                CopiedFeedbacks.Add(data);
            }
        }
示例#2
0
        public override void OnInspectorGUI()
        {
            if (GUILayout.Button("Regenerate ItemDatabase"))
            {
                ItemDatabaseUtility.GenerateItemDatabase();
            }
            GUILayout.Space(5);

            var listProperty = new SerializedObject((ItemDatabase)target).FindProperty("items");

            if (listProperty.propertyType == SerializedPropertyType.Generic)
            {
                // Use Copy() to avoid unwanted iterating.
                var listCount = listProperty.Copy().arraySize;
                GUILayout.Label("Items (" + listCount + ")");

                foreach (SerializedProperty itemProperty in listProperty)
                {
                    if (itemProperty.propertyType == SerializedPropertyType.ObjectReference)
                    {
                        using (new EditorGUI.DisabledScope(true)) {
                            EditorGUILayout.PropertyField(itemProperty, GUIContent.none);
                        }
                    }
                }
            }
        }
 public static T Copy <T>(this SerializedObject srcSO, T dest)
     where T : Object
 {
     Assert.IsNotNull(srcSO.targetObject);
     Assert.AreEqual(typeof(T), srcSO.targetObject.GetType(), $"Don't be different type...");
     return(srcSO.Copy(new SerializedObject(dest)).targetObject as T);
 }
        public static T Copy <T>(T src, T dest)
            where T : Object
        {
            var srcSO = new SerializedObject(src);

            return(srcSO.Copy(new SerializedObject(dest)).targetObject as T);
        }
        void FindMissingReference(Object obj)
        {
            if (!objectHS.Add(obj))
            {
                return;
            }

            EditorUtility.DisplayProgressBar("Search Objects", objectHS.Count.ToString() + " " + obj.GetType().Name + " " + obj, 0);

            var sp = new SerializedObject(obj).GetIterator();

            while (sp.NextVisible(true))
            {
                if (sp.propertyType == SerializedPropertyType.ObjectReference)
                {
                    var value = sp.objectReferenceValue;
                    if (value == null && sp.objectReferenceInstanceIDValue != 0)
                    {
                        propertyList.Add(sp.Copy());
                    }
                    else if (value != null)
                    {
                        FindMissingReference(value);
                    }
                }
            }
        }
    internal static void SetValue <T>(SerializedProperty target, T data, bool applyModifiedProperties = true)
    {
        if (!ValueContainerRegistry.TryGetContainerType(typeof(T), out var containerType))
        {
            var typeName = typeof(T).Name;
            Debug.LogError(
                $"Trying to set a value of type {typeName}, but it's not got a registered container type!\n" +
                $"Please ensure that this type exists: internal class {typeName}Container : ValueContainer<{typeName}> {{}}");
            return;
        }

        ValueContainer <T> dataValueContainer = (ValueContainer <T>)ScriptableObject.CreateInstance(containerType);

        dataValueContainer.t = data;
        var dataSp = new SerializedObject(dataValueContainer).FindProperty("t");

        var dataIter   = dataSp.Copy();
        var targetIter = target.Copy();

        bool next;

        do
        {
            CopySerializedProp(dataIter, targetIter);
            next = dataIter.NextVisible(true);
            targetIter.NextVisible(true);
        } while (next);

        if (applyModifiedProperties)
        {
            target.serializedObject.ApplyModifiedProperties();
        }
    }
        /// <summary>
        /// Check a UnityObject for missing serialized references
        /// </summary>
        /// <param name="obj">The UnityObject to be scanned</param>
        /// <param name="properties">A list to which properties with missing references will be added</param>
        /// <param name="options">User-configurable options for this view</param>
        /// <returns>True if the object has any missing references</returns>
        protected static void CheckForMissingReferences(UnityObject obj, List <SerializedProperty> properties, Options options)
        {
            if (obj == null)
            {
                return;
            }

            var property = new SerializedObject(obj).GetIterator();

            while (property.NextVisible(true)) // enterChildren = true to scan all properties
            {
                if (CheckForMissingReferences(property, options))
                {
                    properties.Add(property.Copy()); // Use a copy of this property because we are iterating on it
                }
            }
        }
        private static IEnumerable <string> GetInputManagerAxes()
        {
            List <string>      inputAxes         = new List <string>();
            SerializedProperty inputAxesProperty =
                new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0])
                .FindProperty("m_Axes");

            inputAxesProperty.Next(true);
            inputAxesProperty.Next(true);
            while (inputAxesProperty.Next(false))
            {
                SerializedProperty axes = inputAxesProperty.Copy();
                axes.Next(true);
                inputAxes.Add(axes.stringValue);
            }

            return(inputAxes);
        }
示例#9
0
        public void CopyPasses()
        {
            var obj = ScriptableObject.CreateInstance <TestClass>();

            obj.value = 100;
            obj.sub   = new TestSubClass(100);
            var SO = new SerializedObject(obj);

            var destObj = ScriptableObject.CreateInstance <TestClass>();
            var dest    = new SerializedObject(destObj);

            SO.Copy(dest);

            Assert.AreEqual(100, destObj.value);
            Assert.AreEqual(100, dest.FindProperty("value").intValue);

            Assert.AreEqual(obj.sub, destObj.sub);
            Assert.AreEqual(SO.FindProperty("sub").FindPropertyRelative("v").floatValue,
                            dest.FindProperty("sub").FindPropertyRelative("v").floatValue);
        }
        private static IEnumerable <SerializedProperty> GatherProperties(UnityEngine.Object profile)
        {
            List <SerializedProperty> properties = new List <SerializedProperty>();
            SerializedProperty        iterator   = new SerializedObject(profile).GetIterator();
            bool hasNextProperty = iterator.Next(true);

            while (hasNextProperty)
            {
                if (!serializedPropertiesToIgnore.Contains(iterator.name) && iterator.depth < maxChildSearchDepth)
                {
                    properties.Add(iterator.Copy());
                }

                if (serializedPropertyTypesToFlatten.Contains(iterator.type))
                {
                    hasNextProperty = iterator.Next(false);
                }
                else
                {
                    hasNextProperty = iterator.Next(true);
                }
            }
            return(properties);
        }