Пример #1
0
        public IEnumerator Copy(bool toMine)
        {
            IEnumerator enumerator;

#if !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0_0 && !UNITY_3_0
            if (propertyType == SerializedPropertyType.ArraySize)
            {
                var destArray   = propertyParent.GetProperty(toMine);
                var sourceArray = propertyParent.GetProperty(!toMine);
                destArray.arraySize = sourceArray.arraySize;

                var children = propertyParent.children;
                if (children != null)
                {
                    children.Clear();                     //Clear PropertyHelpers whenever we add or remove array elements
                }
                destArray.serializedObject.ApplyModifiedProperties();

                enumerator = BubbleRefresh();
                while (enumerator.MoveNext())
                {
                    yield return(null);
                }

                yield break;
            }
#endif

            var dest   = GetProperty(toMine);
            var source = GetProperty(!toMine);

            if (sceneMerge != null && property.propertyPath.Contains("m_Sun"))
            {
                foreach (var ph in propertyParent.children)
                {
                    if (ph.propertyPath.Contains("sunPath"))
                    {
                        var sun = GetProperty(!toMine).objectReferenceValue;
                        if (sun)
                        {
                            var helper     = root.FindObject(((Light)sun).gameObject);
                            var destObject = helper.GetObject(toMine);
                            if (destObject)
                            {
                                foreach (var component in helper.components)
                                {
                                    if (component.GetComponent(!toMine) == sun && !component.GetComponent(toMine))
                                    {
                                        enumerator = component.Copy(toMine);
                                        while (enumerator.MoveNext())
                                        {
                                            yield return(null);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                enumerator = helper.Copy(toMine);
                                while (enumerator.MoveNext())
                                {
                                    yield return(null);
                                }
                            }
                        }

                        if (toMine)
                        {
                            ph.mine.stringValue = ph.theirs.stringValue;
                        }
                        else
                        {
                            ph.theirs.stringValue = ph.mine.stringValue;
                        }

                        break;
                    }
                }
            }

#if !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0_0 && !UNITY_3_0
            if (dest == null)
            {
                //Insert should only occur for arrays
                var array = propertyParent.GetProperty(toMine);
                var count = array.arraySize;
                array.InsertArrayElementAtIndex(count);
                Util.SetProperty(source, array.GetArrayElementAtIndex(count));
                enumerator = BubbleRefresh();
                while (enumerator.MoveNext())
                {
                    yield return(null);
                }

                yield break;
            }
#endif

            var destSerializedObject = dest.serializedObject;
            var destTargetObject     = destSerializedObject.targetObject;
            if (objectMerge && objectMerge.deepCopy)
            {
                switch (dest.propertyType)
                {
                case SerializedPropertyType.ObjectReference:
                    var sourceObjectReferenceValue = source.objectReferenceValue;
                    if (sourceObjectReferenceValue != null)
                    {
                        var t    = sourceObjectReferenceValue.GetType();
                        var root = this.root;
                        if (root != null)
                        {
                            if (t == typeof(GameObject))
                            {
                                var g = root.GetObjectSpouse((GameObject)sourceObjectReferenceValue, true);
                                // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                                if (g == null)
                                {
                                    dest.objectReferenceValue = sourceObjectReferenceValue;
                                }
                                else
                                {
                                    dest.objectReferenceValue = g;
                                }
                            }
                            else if (t.IsSubclassOf(typeof(Component)))
                            {
                                var g = root.GetObjectSpouse(((Component)sourceObjectReferenceValue).gameObject, true);
                                if (g)
                                {
                                    var c = g.GetComponent(t);
                                    dest.objectReferenceValue = c ? c : g.AddComponent(t);
                                }
                                else
                                {
                                    dest.objectReferenceValue = sourceObjectReferenceValue;
                                }
                            }
                            else
                            {
                                dest.objectReferenceValue = sourceObjectReferenceValue;
                            }
                        }
                        else
                        {
                            dest.objectReferenceValue = sourceObjectReferenceValue;
                        }
                    }

                    break;

                case SerializedPropertyType.Generic:
                    for (var i = 0; i < children.Count; i++)
                    {
                        enumerator = children[i].Copy(toMine);
                        while (enumerator.MoveNext())
                        {
                            yield return(null);
                        }
                    }
                    break;

                default:
#if Unity3
                    Util.SetProperty(source, dest);
#else
                    destSerializedObject.CopyFromSerializedProperty(source);
#endif
                    break;
                }
            }

            if (destTargetObject != null)
            {
                destSerializedObject.ApplyModifiedProperties();
            }

            enumerator = BubbleRefresh();
            while (enumerator.MoveNext())
            {
                yield return(null);
            }
        }
Пример #2
0
        public void Copy(bool toMine)
        {
#if !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0_0 && !UNITY_3_0
            if (propertyType == SerializedPropertyType.ArraySize)
            {
                var leftArray  = propertyParent.GetProperty(toMine);
                var rightArray = propertyParent.GetProperty(!toMine);
                leftArray.arraySize = rightArray.arraySize;

                var children = propertyParent.children;
                if (children != null)
                {
                    children.Clear();                     //Clear PropertyHelpers whenever we remove array elements
                }
                return;
            }
#endif

            var left  = GetProperty(toMine);
            var right = GetProperty(!toMine);

#if !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0_0 && !UNITY_3_0
            if (left == null)
            {
                //Insert should only occur for arrays
                var array = propertyParent.GetProperty(toMine);
                var count = array.arraySize;
                array.InsertArrayElementAtIndex(count);
                Util.SetProperty(right, array.GetArrayElementAtIndex(count));
                return;
            }
#endif

            var leftSerializedObject = left.serializedObject;
            var leftTargetObject     = leftSerializedObject.targetObject;
            if (left.propertyType == SerializedPropertyType.ObjectReference)
            {
                var rightObjectReferenceValue = right.objectReferenceValue;
                if (rightObjectReferenceValue != null)
                {
                    var t = rightObjectReferenceValue.GetType();
                    if (window)
                    {
                        if (t == typeof(GameObject))
                        {
                            var g = root.GetObjectSpouse((GameObject)rightObjectReferenceValue, true);
                            // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                            if (g == null)
                            {
                                left.objectReferenceValue = rightObjectReferenceValue;
                            }
                            else
                            {
                                left.objectReferenceValue = g;
                            }
                        }
                        else if (t.IsSubclassOf(typeof(Component)))
                        {
                            var g = root.GetObjectSpouse(((Component)rightObjectReferenceValue).gameObject, true);
                            if (g)
                            {
                                var c = g.GetComponent(t);
                                left.objectReferenceValue = c ? c : g.AddComponent(t);
                            }
                            else
                            {
                                left.objectReferenceValue = rightObjectReferenceValue;
                            }
                        }
                        else
                        {
                            left.objectReferenceValue = rightObjectReferenceValue;
                        }
                    }
                    else
                    {
                        left.objectReferenceValue = rightObjectReferenceValue;
                    }

                    if (leftTargetObject != null)
                    {
                        leftSerializedObject.ApplyModifiedProperties();
                    }

                    return;
                }
            }

#if Unity3
            Util.SetProperty(right, left);
#else
            leftSerializedObject.CopyFromSerializedProperty(right);
#endif

            if (leftTargetObject != null)
            {
                leftSerializedObject.ApplyModifiedProperties();
            }
        }