Example #1
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);
        }
Example #3
0
        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."));
        }
Example #4
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);
        }
Example #6
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);
        }