protected override void ApplyOurs()
 {
     if (ourComponent == null)
     {
         ourComponent = ours.AddComponent(copy);
         ObjectDictionaries.SetAsOurObject(ourComponent);
     }
 }
 protected override void ApplyTheirs()
 {
     if (ourComponent != null)
     {
         ObjectDictionaries.RemoveOurObject(ourComponent);
         Object.DestroyImmediate(ourComponent, true);
     }
 }
Exemple #3
0
 protected override void ApplyTheirs()
 {
     if (!ours)
     {
         ours = ObjectDictionaries.InstantiateFromMerging(theirs);
         ObjectDictionaries.SetAsCopy(ours, theirs);
     }
 }
Exemple #4
0
 protected override void ApplyTheirs()
 {
     if (!ourComponent)
     {
         ourComponent = ours.AddComponent(theirComponent);
         ObjectDictionaries.SetAsCopy(ourComponent, theirComponent);
     }
 }
Exemple #5
0
 protected override void ApplyOurs()
 {
     if (ours)
     {
         ObjectDictionaries.RemoveCopyOf(theirs);
         GameObject.DestroyImmediate(ours, true);
     }
 }
Exemple #6
0
 protected override void ApplyOurs()
 {
     if (ourComponent)
     {
         ObjectDictionaries.RemoveCopyOf(theirComponent);
         Object.DestroyImmediate(ourComponent, true);
     }
 }
Exemple #7
0
        public bool InitializeMerge()
        {
            var activeScene = EditorSceneManager.GetActiveScene();

            if (activeScene.isDirty)
            {
                window.ShowNotification(new GUIContent("Please make sure there are no unsaved changes before attempting to merge."));
                return(false);
            }

            isMergingScene = true;
            var scenePath = activeScene.path;

            // Overwrite the current scene to prevent the reload/ignore dialog that pops up after the upcoming changes to the file.
            // Pressing "reload" on it would invalidate the GameObject references we're about to collect.
            EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);

            vcs.CheckoutOurs(scenePath);
            CheckoutTheirVersionOf(scenePath);
            AssetDatabase.Refresh();

            activeScene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);

            MergeAction.inMergePhase = false;
            ObjectDictionaries.Clear();

            List <GameObject> ourObjects;

            try
            {
                // Find all of "our" objects
                ourObjects = GetAllSceneObjects();
                ObjectDictionaries.AddToOurObjects(ourObjects);

                // Add "their" objects
                theirScene = EditorSceneManager.OpenScene(theirFilename, OpenSceneMode.Additive);

                var addedObjects = GetAllNewSceneObjects(ourObjects);
                ObjectDictionaries.AddToTheirObjects(addedObjects);
                BuildAllMergeActions(ourObjects, addedObjects);

                MoveGameObjectsToScene(theirScene.GetRootGameObjects(), activeScene);
            }
            finally
            {
                EditorSceneManager.UnloadSceneAsync(theirScene);
                AssetDatabase.DeleteAsset(theirFilename);
            }

            if (allMergeActions.Count == 0)
            {
                window.ShowNotification(new GUIContent("No conflict found for this scene."));
                return(false);
            }

            MergeAction.inMergePhase = true;
            return(true);
        }
        public bool InitializeMerge(GameObject prefab)
        {
            if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                return(false);
            }

            isMergingScene           = false;
            MergeAction.inMergePhase = false;

            ObjectDictionaries.Clear();

            //checkout "their" version
            GetTheirVersionOf(AssetDatabase.GetAssetOrScenePath(prefab));
            AssetDatabase.Refresh();

            ourPrefab = prefab;

            //Open a new Scene that will only display the prefab
            previouslyOpenedScene = SceneManager.GetActiveScene().path;

            var sceneSetup = new NewSceneSetup();

            EditorSceneManager.NewScene(sceneSetup);

            //make the new scene empty
            Object.DestroyImmediate(Camera.main.gameObject);

            //instantiate our object in order to view it while merging
            ourPrefabInstance = PrefabUtility.InstantiatePrefab(prefab) as GameObject;

            //find all of "our" objects in the prefab
            var ourObjects = GetAllObjects(prefab);

            theirPrefab           = AssetDatabase.LoadAssetAtPath(theirFilename, typeof(GameObject)) as GameObject;
            theirPrefab.hideFlags = HideFlags.HideAndDontSave;
            var theirObjects = GetAllObjects(theirPrefab);

            //create list of differences that have to be merged
            BuildAllMergeActions(ourObjects, theirObjects);

            if (allMergeActions.Count == 0)
            {
                AssetDatabase.DeleteAsset(theirFilename);
                OpenPreviousScene();
                window.ShowNotification(new GUIContent("No conflict found for this prefab."));
                return(false);
            }
            MergeAction.inMergePhase = true;
            ourPrefabInstance.Highlight();
            return(true);
        }
        public virtual void AbortMerge()
        {
            MergeAction.inMergePhase = false;

            foreach (var actions in allMergeActions)
            {
                actions.UseOurs();
            }
            ObjectDictionaries.DestroyTheirObjects();
            ObjectDictionaries.Clear();
            allMergeActions = null;

            window.ShowNotification(new GUIContent("Merge aborted."));
        }
Exemple #10
0
        /// <summary>
        /// Completes the merge process after solving all conflicts.
        /// Cleans up the scene by deleting "their" GameObjects, clears merge related data structures,
        /// executes git add scene_name.
        /// </summary>
        public override void CompleteMerge()
        {
            MergeAction.inMergePhase = false;

            ObjectDictionaries.DestroyTheirObjects();
            ObjectDictionaries.Clear();
            EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());

            allMergeActions = null;

            vcs.MarkAsMerged(fileName);

            // Directly committing here might not be that smart, since there might be more conflicts

            window.ShowNotification(new GUIContent("Scene successfully merged."));
        }
        public bool InitializeMerge()
        {
            isMergingScene = true;

            //Ask if the scene should be saved, because...
            if (!EditorApplication.SaveCurrentSceneIfUserWantsTo())
            {
                return(false);
            }
            //...we are reloading it to prevent objects from not having a scene id.
            EditorApplication.OpenScene(EditorApplication.currentScene);

            MergeAction.inMergePhase = false;

            ObjectDictionaries.Clear();

            //checkout "their" version
            GetTheirVersionOf(EditorApplication.currentScene);
            AssetDatabase.Refresh();

            //find all of "our" objects
            var ourObjects = GetAllSceneObjects();

            ObjectDictionaries.SetAsOurObjects(ourObjects);

            //add "their" objects
            EditorApplication.OpenSceneAdditive(theirFilename);

            //delete scene file
            AssetDatabase.DeleteAsset(theirFilename);

            //find all of "their" objects
            var addedObjects = GetAllNewSceneObjects(ourObjects);

            ObjectDictionaries.SetAsTheirObjects(addedObjects);

            //create list of differences that have to be merged
            BuildAllMergeActions(ourObjects, addedObjects);

            if (allMergeActions.Count == 0)
            {
                window.ShowNotification(new GUIContent("No conflict found for this scene."));
                return(false);
            }
            MergeAction.inMergePhase = true;
            return(true);
        }
Exemple #12
0
        public bool InitializeMerge(GameObject prefab)
        {
            if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                return(false);
            }

            isMergingScene           = false;
            MergeAction.inMergePhase = false;

            ObjectDictionaries.Clear();

            var filePath = AssetDatabase.GetAssetOrScenePath(prefab);

            vcs.CheckoutOurs(filePath);
            CheckoutTheirVersionOf(filePath);
            AssetDatabase.Refresh();

            ourPrefab = prefab;

            // Open a new Scene that will only display the prefab.
            previouslyOpenedScene = EditorSceneManager.GetActiveScene();
            EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);

            // Instantiate our object in order to view it while merging.
            ourPrefabInstance = PrefabUtility.InstantiatePrefab(prefab) as GameObject;

            var ourObjects = GetAllObjects(prefab);

            theirPrefab           = AssetDatabase.LoadAssetAtPath(theirFilename, typeof(GameObject)) as GameObject;
            theirPrefab.hideFlags = HideFlags.HideAndDontSave;
            var theirObjects = GetAllObjects(theirPrefab);

            BuildAllMergeActions(ourObjects, theirObjects);

            if (allMergeActions.Count == 0)
            {
                AssetDatabase.DeleteAsset(theirFilename);
                OpenPreviousScene();
                window.ShowNotification(new GUIContent("No conflict found for this prefab."));
                return(false);
            }
            MergeAction.inMergePhase = true;
            ourPrefabInstance.Highlight();
            return(true);
        }
Exemple #13
0
        protected override void ApplyTheirs()
        {
            var ourVersion = ObjectDictionaries.GetOurCounterpartFor(theirParent) as Transform;

            if (theirParent && !ourVersion)
            {
                if (EditorUtility.DisplayDialog("The chosen parent currently does not exist.", "Do you want do add it?", "Yes", "No"))
                {
                    ObjectDictionaries.EnsureExistence(theirParent.gameObject);
                    ourVersion = ObjectDictionaries.GetOurCounterpartFor(theirParent) as Transform;

                    transform.parent = ourVersion;
                }
                else
                {
                    throw new System.Exception("User Abort.");
                }
            }
            else
            {
                transform.parent = ourVersion;
            }
        }
Exemple #14
0
        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  = ObjectID.GetFor(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();
        }
Exemple #15
0
 public MergeActionExistence(GameObject ours, GameObject theirs)
     : base(ours, theirs)
 {
     ObjectDictionaries.AddToSchroedingersObjects(ours ?? theirs, this);
 }