public static void PrepareDragAndDrop(string prefabName, EditorApplication.HierarchyWindowItemCallback acceptDragAndDrop, Action removeListener)
			{
				if (PrefabIconPosition.Contains (Event.current.mousePosition)) {
					if (Event.current.type == EventType.mouseDown) {
						pressed = true;
					}
					if (Event.current.type == EventType.mouseUp) {
						pressed = false;
					}
				}

				DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

				Event current = Event.current;
				if (pressed && current.type == EventType.MouseDrag) {
					DragAndDrop.PrepareStartDrag ();
					DragAndDrop.paths = null;
					DragAndDrop.objectReferences = new UnityEngine.Object[0];
					DragAndDrop.SetGenericData ("object", Event.current);
					DragAndDrop.StartDrag (prefabName);

					removeListener ();
					EditorApplication.hierarchyWindowItemOnGUI += acceptDragAndDrop;

					current.Use ();
				}
			}
Example #2
0
        public IEnumerator MergeAsync(string myPath, string theirPath)
        {
            if (string.IsNullOrEmpty(myPath) || string.IsNullOrEmpty(theirPath))
            {
                yield break;
            }

            if (myPath.EndsWith("prefab") || theirPath.EndsWith("prefab"))
            {
                PrefabMerge(myPath, theirPath);
                yield break;
            }

            if (AssetDatabase.LoadAssetAtPath(myPath, typeof(UnityObject)) &&
                AssetDatabase.LoadAssetAtPath(theirPath, typeof(UnityObject)))
            {
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
                if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
                {
#else
                if (EditorApplication.SaveCurrentSceneIfUserWantsTo())
                {
#endif

                    var enumerator = CollectSceneSettings(myPath, theirPath);
                    while (enumerator.MoveNext())
                    {
                        yield return(null);
                    }

                    MergeScenes(myPath, theirPath);

                    RecaptureSettings();

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

                    yield return(null);

                    var objectMerge = (ObjectMerge)GetWindow(typeof(ObjectMerge));
                    var root        = objectMerge.root;
                    root.SetGameObjects(myContainer, theirContainer);
                    objectMerge.update     = root.Refresh();
                    objectMerge.sceneMerge = this;
                    objectMerge.Repaint();
                    yield return(null);

                    merged = true;
                }
            }
            loading = false;
        }
Example #3
0
        static IEnumerator CollectSceneSettings(string myPath, string theirPath)
        {
            yield return(null);

            EditorSceneManager.OpenScene(myPath);
            SceneData.Capture(true);

            yield return(null);

            EditorSceneManager.OpenScene(theirPath);
            SceneData.Capture(false);
        }
Example #4
0
        void DrawSaveGUI(bool isMine)
        {
            var name   = isMine ? "Mine" : "Theirs";
            var saveAs = GUILayout.Button(string.Format("Save {0} as...", name));

            if (GUILayout.Button(string.Format("Save To {0}", name)) || saveAs)
            {
                var scene = isMine ? mine : theirs;
#if !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0_0 && !UNITY_3_0
                var path = AssetDatabase.GetAssetOrScenePath(scene);
#else
                var path = AssetDatabase.GetAssetPath(scene);
#endif

                if (saveAs)
                {
                    var fileName = Path.GetFileNameWithoutExtension(path);
                    path = EditorUtility.SaveFilePanelInProject("Save Mine", fileName, "unity", string.Empty);
                }

                if (!string.IsNullOrEmpty(path))
                {
                    var myContainer    = this.myContainer;
                    var theirContainer = this.theirContainer;
                    DestroyImmediate(isMine ? theirContainer : myContainer);

                    var tmp       = new List <Transform>();
                    var container = isMine ? myContainer : theirContainer;
                    foreach (Transform t in container.transform)
                    {
                        tmp.Add(t);
                    }

                    foreach (var t in tmp)
                    {
                        t.parent = null;
                    }

                    DestroyImmediate(container);

                    (isMine ? mySceneData : theirSceneData).ApplySettings();

#if UNITY_5_3 || UNITY_5_3_OR_NEWER
                    EditorSceneManager.SaveScene(SceneManager.GetActiveScene(), path);
#else
                    EditorApplication.SaveScene(path);
#endif
                    GUIUtility.ExitGUI();
                }
            }
        }
 internal static void CallDelayed(EditorApplication.CallbackFunction function, float timeFromNow)
 {
   EditorApplication.delayedCallback = function;
   EditorApplication.s_DelayedCallbackTime = Time.realtimeSinceStartup + timeFromNow;
   EditorApplication.update += new EditorApplication.CallbackFunction(EditorApplication.CheckCallDelayed);
 }
Example #6
0
        void MergeScenes(string myPath, string theirPath)
        {
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
            var newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
            var myScene  = EditorSceneManager.OpenScene(myPath, OpenSceneMode.Additive);
#else
#if UNITY_5
            EditorApplication.NewEmptyScene();
#else
            EditorApplication.NewScene();
            var _allObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject));
            foreach (var obj in _allObjects)
            {
                if (obj.transform.parent == null && PrefabUtility.GetPrefabType(obj) != PrefabType.Prefab &&
                    PrefabUtility.GetPrefabType(obj) != PrefabType.ModelPrefab &&
                    obj.hideFlags == 0)                        //Want a better way to filter out "internal" objects
                {
                    DestroyImmediate(obj);
                }
            }
#endif
            EditorApplication.OpenSceneAdditive(myPath);
#endif

            var split = myPath.Split('/');
            myContainerName  = split[split.Length - 1].Replace(".unity", "");
            this.myContainer = new GameObject {
                name = myContainerName
            };
            var myContainer = this.myContainer;
            Undo.RegisterCreatedObjectUndo(myContainer, "UniMerge");

            var myTransform = myContainer.transform;
            var allObjects  = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject));

            foreach (var obj in allObjects)
            {
                if (obj.transform.parent == null && PrefabUtility.GetPrefabType(obj) != PrefabType.Prefab &&
                    PrefabUtility.GetPrefabType(obj) != PrefabType.ModelPrefab &&
                    obj.hideFlags == 0)                        //Want a better way to filter out "internal" objects
                {
                    obj.transform.parent = myTransform;
                }
            }

#if UNITY_5_3 || UNITY_5_3_OR_NEWER
            SceneManager.MergeScenes(myScene, newScene);
#endif

#if UNITY_5_3 || UNITY_5_3_OR_NEWER
            var theirScene = EditorSceneManager.OpenScene(theirPath, OpenSceneMode.Additive);
            SceneManager.MergeScenes(theirScene, newScene);
#else
            EditorSceneManager.OpenSceneAdditive(theirPath);
#endif

            split = theirPath.Split('/');
            theirContainerName = split[split.Length - 1].Replace(".unity", "");

            this.theirContainer = new GameObject {
                name = theirContainerName
            };
            var theirContainer = this.theirContainer;
            Undo.RegisterCreatedObjectUndo(theirContainer, "UniMerge");

            allObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject));

            foreach (var obj in allObjects)
            {
                if (obj.transform.parent == null && obj.name != myContainerName &&
                    PrefabUtility.GetPrefabType(obj) != PrefabType.Prefab &&
                    PrefabUtility.GetPrefabType(obj) != PrefabType.ModelPrefab &&
                    obj.hideFlags == 0)                        //Want a better way to filter out "internal" objects
                {
                    obj.transform.parent = theirContainer.transform;
                }
            }
        }
 static object HandleExitEvent(string type, object[] args)
 {
     EditorApplication.delayCall += () => EditorApplication.Exit(Convert.ToInt32(args[0]));
     return(null);
 }
 public void Invoke(this EditorApplication app, EditorApplication.CallbackFunction func)
 {
     EditorApplication.delayCall += () =>
     {
         func();
     };
 }