private static void RemoveOurSingleObject(Object o)
        {
            if (o == null)
            {
                return;
            }

            ourObjects.Remove(ObjectIDFinder.GetIdentifierFor(o));
        }
        private static void AddOurObject(Object o)
        {
            if (o == null)
            {
                return;
            }

            ourObjects.Add(ObjectIDFinder.GetIdentifierFor(o), o);
        }
示例#3
0
        /// <summary>
        /// Returns:
        /// * the given object if it is "ours"
        /// * "our" counterpart of obj if it is "theirs"
        /// * null if the object is deleted for some reason
        /// The returned object can be an instance of "their" object temporarily added for the merge
        /// </summary>
        /// <param name="obj">the original object</param>
        /// <returns>the counterpart of the object in "our" version</returns>
        public static Object GetOurCounterpartFor(Object obj)
        {
            var result = obj;

            if (IsTheirs(obj))
            {
                result = GetOurObject(ObjectIDFinder.GetIdentifierFor(obj));
                if (!result)
                {
                    result = GetOurInstanceOfCopy(obj);
                }
            }
            return(result);
        }
        /// <summary>
        /// Check for Components that one of the sides doesn't have, and/or for defferent values
        /// on Components.
        /// </summary>
        private void FindComponentDifferences()
        {
            var ourComponents   = ours.GetComponents <Component>();
            var theirComponents = theirs.GetComponents <Component>();

            //Map "their" Components to their respective ids
            var theirDict = new Dictionary <int, Component>();

            foreach (var theirComponent in theirComponents)
            {
                //Ignore null components
                if (theirComponent != null)
                {
                    theirDict.Add(ObjectIDFinder.GetIdentifierFor(theirComponent), theirComponent);
                }
            }

            foreach (var ourComponent in ourComponents)
            {
                //Ignore null components
                if (ourComponent == null)
                {
                    continue;
                }

                //Try to find "their" equivalent to our Components
                var       id = ObjectIDFinder.GetIdentifierFor(ourComponent);
                Component theirComponent;
                theirDict.TryGetValue(id, out theirComponent);

                if (theirComponent) //Both Components exist
                {
                    FindPropertyDifferences(ourComponent, theirComponent);
                    //Remove "their" Component from the dict to only keep those new to us
                    theirDict.Remove(id);
                }
                else //Component doesn't exist in their version, offer a deletion
                {
                    actions.Add(new MergeActionDeleteComponent(ours, ourComponent));
                }
            }

            //Everything left in the dict is a...
            foreach (var theirComponent in theirDict.Values)
            {
                //...new Component from them
                actions.Add(new MergeActionNewComponent(ours, theirComponent));
            }
        }
示例#5
0
        /// <summary>
        /// Finds all specific merge conflicts between two sets of GameObjects,
        /// representing "our" scene and "their" scene.
        /// </summary>
        /// <param name="ourObjects">The GameObjects of "our" version of the scene.</param>
        /// <param name="theirObjects">The GameObjects of "their" version of the scene.</param>
        protected void BuildAllMergeActions(List <GameObject> ourObjects, List <GameObject> theirObjects)
        {
            allMergeActions = new List <GameObjectMergeActions>();

            //Map "their" GameObjects to their respective ids
            var theirObjectsDict = new Dictionary <int, GameObject>();

            foreach (var theirs in theirObjects)
            {
                theirObjectsDict.Add(ObjectIDFinder.GetIdentifierFor(theirs), theirs);
            }

            foreach (var ours in ourObjects)
            {
                //Try to find "their" equivalent to "our" GameObjects
                var        id = ObjectIDFinder.GetIdentifierFor(ours);
                GameObject theirs;
                theirObjectsDict.TryGetValue(id, out theirs);

                //If theirs is null, mergeActions.hasActions will be false
                var mergeActions = new GameObjectMergeActions(ours, theirs);
                if (mergeActions.hasActions)
                {
                    allMergeActions.Add(mergeActions);
                }
                //Remove "their" GameObject from the dict to only keep those new to us
                theirObjectsDict.Remove(id);
            }

            //Every GameObject left in the dict is a...
            foreach (var theirs in theirObjectsDict.Values)
            {
                //...new GameObject from them
                var mergeActions = new GameObjectMergeActions(null, theirs);
                if (mergeActions.hasActions)
                {
                    allMergeActions.Add(mergeActions);
                }
            }
        }
        protected override void ApplyTheirs()
        {
            var value = theirInitialValue;

            //If we're about references here, get "our" version of the object.
            if (ourProperty.propertyType == SerializedPropertyType.ObjectReference)
            {
                var id  = ObjectIDFinder.GetIdentifierFor(theirInitialValue as Object);
                var obj = ObjectDictionaries.GetOurObject(id);

                //If we didn't have our own version of the object before, it must be new
                if (!obj)
                {
                    //Get our copy of the new object if it exists
                    obj = ObjectDictionaries.GetOurInstanceOfCopy(value as Object);
                }

                value = obj;
            }

            ourProperty.SetValue(value);
            ourProperty.serializedObject.ApplyModifiedProperties();
        }
示例#7
0
 private static void RemoveOurSingleObject(Object o)
 {
     ourObjects.Remove(ObjectIDFinder.GetIdentifierFor(o));
 }
示例#8
0
 private static void AddOurObject(Object o)
 {
     ourObjects.Add(ObjectIDFinder.GetIdentifierFor(o), o);
 }
        public static object GetValue(this SerializedProperty p, bool forComparison = false)
        {
            switch (p.propertyType)
            {
            case SerializedPropertyType.AnimationCurve:
                return(p.animationCurveValue);

            case SerializedPropertyType.ArraySize:
                return(p.intValue);

            case SerializedPropertyType.Boolean:
                return(p.boolValue);

            case SerializedPropertyType.Bounds:
                return(p.boundsValue);

            case SerializedPropertyType.Character:
                return(p.stringValue);    //TODO: might be bullshit

            case SerializedPropertyType.Color:
                return(p.colorValue);

            case SerializedPropertyType.Enum:
                return(p.enumValueIndex);

            case SerializedPropertyType.Float:
                return(p.floatValue);

            case SerializedPropertyType.Generic:     //(arrays)
                if (p.isArray)
                {
                    var arr = new object[p.arraySize];
                    for (int i = 0; i < arr.Length; ++i)
                    {
                        arr[i] = p.GetArrayElementAtIndex(i).GetValue();
                    }
                    return(arr);
                }
                else
                {
                    return(null);
                }

            case SerializedPropertyType.Gradient:
                return(0);    //TODO: erm

            case SerializedPropertyType.Integer:
                return(p.intValue);

            case SerializedPropertyType.LayerMask:
                return(p.intValue);

            case SerializedPropertyType.ObjectReference:
                if (forComparison)
                {
                    return(ObjectIDFinder.GetIdentifierFor(p.objectReferenceValue));
                }
                else
                {
                    return(p.objectReferenceValue);
                }

            case SerializedPropertyType.Quaternion:
                return(p.quaternionValue);

            case SerializedPropertyType.Rect:
                return(p.rectValue);

            case SerializedPropertyType.String:
                return(p.stringValue);

            case SerializedPropertyType.Vector2:
                return(p.vector2Value);

            case SerializedPropertyType.Vector3:
                return(p.vector3Value);

            case SerializedPropertyType.Vector4:
                return(p.vector4Value);

            default:
                return(0);
            }
        }