private bool IsValidHierarchyInstanceID(int instanceID)
        {
            bool flag  = SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(EditorSceneManager.GetSceneByHandle(instanceID));
            bool flag2 = InternalEditorUtility.GetClassIDWithoutLoadingObject(instanceID) == this.kGameObjectClassID;

            return(flag || flag2);
        }
Ejemplo n.º 2
0
        private bool IsValidHierarchyInstanceID(int instanceID)
        {
            bool isScene      = SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(EditorSceneManager.GetSceneByHandle(instanceID));
            bool isGameObject = InternalEditorUtility.GetTypeWithoutLoadingObject(instanceID) == typeof(GameObject);

            return(isScene || isGameObject);
        }
        private List <int> GetSelectedGameObjects()
        {
            List <int> intList = new List <int>();

            foreach (int handle in this.m_TreeView.GetSelection())
            {
                if (!SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(EditorSceneManager.GetSceneByHandle(handle)))
                {
                    intList.Add(handle);
                }
            }
            return(intList);
        }
        private List <Scene> GetDraggedScenes(List <int> draggedItemIDs)
        {
            List <Scene> list = new List <Scene>();

            foreach (int current in draggedItemIDs)
            {
                Scene sceneByHandle = EditorSceneManager.GetSceneByHandle(current);
                if (!SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(sceneByHandle))
                {
                    return(null);
                }
                list.Add(sceneByHandle);
            }
            return(list);
        }
        private void ItemContextClick(int contextClickedItemID)
        {
            Event.current.Use();
            GenericMenu menu = new GenericMenu();

            if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(EditorSceneManager.GetSceneByHandle(contextClickedItemID)))
            {
                this.CreateMultiSceneHeaderContextClick(menu, contextClickedItemID);
            }
            else
            {
                this.CreateGameObjectContextClick(menu, contextClickedItemID);
            }
            menu.ShowAsContext();
        }
Ejemplo n.º 6
0
        private List <int> GetSelectedGameObjects()
        {
            List <int> list = new List <int>();

            int[] selection = this.m_TreeView.GetSelection();
            int[] array     = selection;
            for (int i = 0; i < array.Length; i++)
            {
                int num = array[i];
                if (!SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(EditorSceneManager.GetSceneByHandle(num)))
                {
                    list.Add(num);
                }
            }
            return(list);
        }
Ejemplo n.º 7
0
        private void TreeViewItemDoubleClicked(int instanceID)
        {
            Scene sceneByHandle = EditorSceneManager.GetSceneByHandle(instanceID);

            if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(sceneByHandle))
            {
                if (sceneByHandle.isLoaded)
                {
                    SceneManager.SetActiveScene(sceneByHandle);
                }
            }
            else
            {
                SceneView.FrameLastActiveSceneView();
            }
        }
Ejemplo n.º 8
0
        private List <Scene> GetDraggedScenes(List <int> draggedItemIDs)
        {
            List <Scene> scenes = new List <Scene>();

            foreach (int id in draggedItemIDs)
            {
                Scene scene = EditorSceneManager.GetSceneByHandle(id);
                if (!SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(scene))
                {
                    return(null);
                }
                scenes.Add(scene);
            }

            return(scenes);
        }
Ejemplo n.º 9
0
        private List <Scene> GetDraggedScenes(List <int> draggedItemIDs)
        {
            List <Scene> sceneList = new List <Scene>();

            using (List <int> .Enumerator enumerator = draggedItemIDs.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Scene sceneByHandle = EditorSceneManager.GetSceneByHandle(enumerator.Current);
                    if (!SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(sceneByHandle))
                    {
                        return((List <Scene>)null);
                    }
                    sceneList.Add(sceneByHandle);
                }
            }
            return(sceneList);
        }
        private DragAndDropVisualMode DoDragScenes(GameObjectTreeViewItem parentItem, GameObjectTreeViewItem targetItem, bool perform, TreeViewDragging.DropPosition dropPos)
        {
            List <Scene> list  = DragAndDrop.GetGenericData("SceneHeaderList") as List <Scene>;
            bool         flag  = list != null;
            bool         flag2 = false;

            if (!flag && DragAndDrop.objectReferences.Length > 0)
            {
                int num = 0;
                UnityEngine.Object[] objectReferences = DragAndDrop.objectReferences;
                for (int i = 0; i < objectReferences.Length; i++)
                {
                    UnityEngine.Object @object = objectReferences[i];
                    if (@object is SceneAsset)
                    {
                        num++;
                    }
                }
                flag2 = (num == DragAndDrop.objectReferences.Length);
            }
            if (!flag && !flag2)
            {
                return(DragAndDropVisualMode.None);
            }
            if (perform)
            {
                List <Scene> list2 = null;
                if (flag2)
                {
                    List <Scene>         list3             = new List <Scene>();
                    UnityEngine.Object[] objectReferences2 = DragAndDrop.objectReferences;
                    for (int j = 0; j < objectReferences2.Length; j++)
                    {
                        UnityEngine.Object assetObject = objectReferences2[j];
                        string             assetPath   = AssetDatabase.GetAssetPath(assetObject);
                        Scene scene = SceneManager.GetSceneByPath(assetPath);
                        if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(scene))
                        {
                            this.m_TreeView.Frame(scene.handle, true, true);
                        }
                        else
                        {
                            bool alt = Event.current.alt;
                            if (alt)
                            {
                                scene = EditorSceneManager.OpenScene(assetPath, OpenSceneMode.AdditiveWithoutLoading);
                            }
                            else
                            {
                                scene = EditorSceneManager.OpenScene(assetPath, OpenSceneMode.Additive);
                            }
                            if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(scene))
                            {
                                list3.Add(scene);
                            }
                        }
                    }
                    if (targetItem != null)
                    {
                        list2 = list3;
                    }
                    if (list3.Count > 0)
                    {
                        Selection.instanceIDs = (from x in list3
                                                 select x.handle).ToArray <int>();
                        this.m_TreeView.Frame(list3.Last <Scene>().handle, true, false);
                    }
                }
                else
                {
                    list2 = list;
                }
                if (list2 != null)
                {
                    if (targetItem != null)
                    {
                        Scene scene2 = targetItem.scene;
                        if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(scene2))
                        {
                            if (!targetItem.isSceneHeader || dropPos == TreeViewDragging.DropPosition.Upon)
                            {
                                dropPos = TreeViewDragging.DropPosition.Below;
                            }
                            if (dropPos == TreeViewDragging.DropPosition.Above)
                            {
                                for (int k = 0; k < list2.Count; k++)
                                {
                                    EditorSceneManager.MoveSceneBefore(list2[k], scene2);
                                }
                            }
                            else if (dropPos == TreeViewDragging.DropPosition.Below)
                            {
                                for (int l = list2.Count - 1; l >= 0; l--)
                                {
                                    EditorSceneManager.MoveSceneAfter(list2[l], scene2);
                                }
                            }
                        }
                    }
                    else
                    {
                        Scene sceneAt = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
                        for (int m = list2.Count - 1; m >= 0; m--)
                        {
                            EditorSceneManager.MoveSceneAfter(list2[m], sceneAt);
                        }
                    }
                }
            }
            return(DragAndDropVisualMode.Move);
        }
Ejemplo n.º 11
0
        private void CreateMultiSceneHeaderContextClick(GenericMenu menu, int contextClickedItemID)
        {
            Scene sceneByHandle = EditorSceneManager.GetSceneByHandle(contextClickedItemID);

            if (!SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(sceneByHandle))
            {
                Debug.LogError("Context clicked item is not a scene");
                return;
            }
            if (sceneByHandle.isLoaded)
            {
                menu.AddItem(EditorGUIUtility.TextContent("Set Active Scene"), false, new GenericMenu.MenuFunction2(this.SetSceneActive), contextClickedItemID);
                menu.AddSeparator(string.Empty);
            }
            if (sceneByHandle.isLoaded)
            {
                if (!EditorApplication.isPlaying)
                {
                    menu.AddItem(EditorGUIUtility.TextContent("Save Scene"), false, new GenericMenu.MenuFunction2(this.SaveSelectedScenes), contextClickedItemID);
                    menu.AddItem(EditorGUIUtility.TextContent("Save Scene As"), false, new GenericMenu.MenuFunction2(this.SaveSceneAs), contextClickedItemID);
                    menu.AddItem(EditorGUIUtility.TextContent("Save All"), false, new GenericMenu.MenuFunction2(this.SaveAllScenes), contextClickedItemID);
                }
                else
                {
                    menu.AddDisabledItem(EditorGUIUtility.TextContent("Save Scene"));
                    menu.AddDisabledItem(EditorGUIUtility.TextContent("Save Scene As"));
                    menu.AddDisabledItem(EditorGUIUtility.TextContent("Save All"));
                }
                menu.AddSeparator(string.Empty);
            }
            bool flag = EditorSceneManager.loadedSceneCount != this.GetNumLoadedScenesInSelection();

            if (sceneByHandle.isLoaded)
            {
                bool flag2 = flag && !EditorApplication.isPlaying && !string.IsNullOrEmpty(sceneByHandle.path);
                if (flag2)
                {
                    menu.AddItem(EditorGUIUtility.TextContent("Unload Scene"), false, new GenericMenu.MenuFunction2(this.UnloadSelectedScenes), contextClickedItemID);
                }
                else
                {
                    menu.AddDisabledItem(EditorGUIUtility.TextContent("Unload Scene"));
                }
            }
            else
            {
                bool flag3 = !EditorApplication.isPlaying;
                if (flag3)
                {
                    menu.AddItem(EditorGUIUtility.TextContent("Load Scene"), false, new GenericMenu.MenuFunction2(this.LoadSelectedScenes), contextClickedItemID);
                }
                else
                {
                    menu.AddDisabledItem(EditorGUIUtility.TextContent("Load Scene"));
                }
            }
            bool flag4 = this.GetSelectedScenes().Count == SceneManager.sceneCount;
            bool flag5 = flag && !flag4 && !EditorApplication.isPlaying;

            if (flag5)
            {
                menu.AddItem(EditorGUIUtility.TextContent("Remove Scene"), false, new GenericMenu.MenuFunction2(this.RemoveSelectedScenes), contextClickedItemID);
            }
            else
            {
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Remove Scene"));
            }
            menu.AddSeparator(string.Empty);
            if (!string.IsNullOrEmpty(sceneByHandle.path))
            {
                menu.AddItem(EditorGUIUtility.TextContent("Select Scene Asset"), false, new GenericMenu.MenuFunction2(this.SelectSceneAsset), contextClickedItemID);
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Select Scene Asset"));
            }
            if (sceneByHandle.isLoaded)
            {
                menu.AddSeparator(string.Empty);
                this.AddCreateGameObjectItemsToMenu(menu, (from t in Selection.transforms
                                                           select t.gameObject).ToArray <GameObject>(), false, true, sceneByHandle.handle);
            }
        }
Ejemplo n.º 12
0
        private DragAndDropVisualMode DoDragScenes(GameObjectTreeViewItem parentItem, GameObjectTreeViewItem targetItem, bool perform, DropPosition dropPos)
        {
            // We allow dragging SceneAssets on any game object in the Hierarchy to make it easy to drag in a Scene from
            // the project browser. If dragging on a game object (not a sceneheader) we place the dropped scene
            // below the game object's scene

            // Case: 1
            List <Scene> scenes = DragAndDrop.GetGenericData(kSceneHeaderDragString) as List <Scene>;
            bool         reorderExistingScenes = (scenes != null);

            // Case: 2
            bool insertNewScenes = false;

            if (!reorderExistingScenes && DragAndDrop.objectReferences.Length > 0)
            {
                int sceneAssetCount = 0;
                foreach (var dragged in DragAndDrop.objectReferences)
                {
                    if (dragged is SceneAsset)
                    {
                        sceneAssetCount++;
                    }
                }
                insertNewScenes = (sceneAssetCount == DragAndDrop.objectReferences.Length);
            }

            // Early out if not case 1 or 2
            if (!reorderExistingScenes && !insertNewScenes)
            {
                return(DragAndDropVisualMode.None);
            }

            if (perform)
            {
                List <Scene> scenesToBeMoved = null;
                if (insertNewScenes)
                {
                    List <Scene> insertedScenes = new List <Scene>();
                    foreach (var sceneAsset in DragAndDrop.objectReferences)
                    {
                        string scenePath = AssetDatabase.GetAssetPath(sceneAsset);
                        Scene  scene     = SceneManager.GetSceneByPath(scenePath);
                        if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(scene))
                        {
                            m_TreeView.Frame(scene.handle, true, true);
                        }
                        else
                        {
                            bool unloaded = Event.current.alt;
                            if (unloaded)
                            {
                                scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.AdditiveWithoutLoading);
                            }
                            else
                            {
                                scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
                            }

                            if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(scene))
                            {
                                insertedScenes.Add(scene);
                            }
                        }
                    }
                    if (targetItem != null)
                    {
                        scenesToBeMoved = insertedScenes;
                    }

                    // Select added scenes and frame last scene
                    if (insertedScenes.Count > 0)
                    {
                        Selection.instanceIDs = insertedScenes.Select(x => x.handle).ToArray();
                        m_TreeView.Frame(insertedScenes.Last().handle, true, false);
                    }
                }
                else // reorderExistingScenes
                {
                    scenesToBeMoved = scenes;
                }

                if (scenesToBeMoved != null)
                {
                    if (targetItem != null)
                    {
                        Scene dstScene = targetItem.scene;
                        if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(dstScene))
                        {
                            if (!targetItem.isSceneHeader || dropPos == DropPosition.Upon)
                            {
                                dropPos = DropPosition.Below;
                            }

                            if (dropPos == DropPosition.Above)
                            {
                                for (int i = 0; i < scenesToBeMoved.Count; i++)
                                {
                                    EditorSceneManager.MoveSceneBefore(scenesToBeMoved[i], dstScene);
                                }
                            }
                            else if (dropPos == DropPosition.Below)
                            {
                                for (int i = scenesToBeMoved.Count - 1; i >= 0; i--)
                                {
                                    EditorSceneManager.MoveSceneAfter(scenesToBeMoved[i], dstScene);
                                }
                            }
                        }
                    }
                    else
                    {
                        Scene dstScene = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
                        for (int i = scenesToBeMoved.Count - 1; i >= 0; i--)
                        {
                            EditorSceneManager.MoveSceneAfter(scenesToBeMoved[i], dstScene);
                        }
                    }
                }
            }

            return(DragAndDropVisualMode.Move);
        }
Ejemplo n.º 13
0
        private DragAndDropVisualMode DoDragScenes(GameObjectTreeViewItem parentItem, GameObjectTreeViewItem targetItem, bool perform, TreeViewDragging.DropPosition dropPos)
        {
            List <Scene> genericData = DragAndDrop.GetGenericData("SceneHeaderList") as List <Scene>;
            bool         flag1       = genericData != null;
            bool         flag2       = false;

            if (!flag1 && DragAndDrop.objectReferences.Length > 0)
            {
                int num = 0;
                foreach (UnityEngine.Object objectReference in DragAndDrop.objectReferences)
                {
                    if (objectReference is SceneAsset)
                    {
                        ++num;
                    }
                }
                flag2 = num == DragAndDrop.objectReferences.Length;
            }
            if (!flag1 && !flag2)
            {
                return(DragAndDropVisualMode.None);
            }
            if (perform)
            {
                List <Scene> sceneList = (List <Scene>)null;
                if (flag2)
                {
                    List <Scene> source = new List <Scene>();
                    foreach (UnityEngine.Object objectReference in DragAndDrop.objectReferences)
                    {
                        string assetPath   = AssetDatabase.GetAssetPath(objectReference);
                        Scene  sceneByPath = SceneManager.GetSceneByPath(assetPath);
                        if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(sceneByPath))
                        {
                            this.m_TreeView.Frame(sceneByPath.handle, true, true);
                        }
                        else
                        {
                            Scene scene = !Event.current.alt ? EditorSceneManager.OpenScene(assetPath, OpenSceneMode.Additive) : EditorSceneManager.OpenScene(assetPath, OpenSceneMode.AdditiveWithoutLoading);
                            if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(scene))
                            {
                                source.Add(scene);
                            }
                        }
                    }
                    if (targetItem != null)
                    {
                        sceneList = source;
                    }
                    if (SceneManager.sceneCount - source.Count == 1)
                    {
                        ((TreeViewDataSource)this.m_TreeView.data).SetExpanded(SceneManager.GetSceneAt(0).handle, true);
                    }
                    if (source.Count > 0)
                    {
                        Selection.instanceIDs = source.Select <Scene, int>((Func <Scene, int>)(x => x.handle)).ToArray <int>();
                        this.m_TreeView.Frame(source.Last <Scene>().handle, true, false);
                    }
                }
                else
                {
                    sceneList = genericData;
                }
                if (sceneList != null)
                {
                    if (targetItem != null)
                    {
                        Scene scene = targetItem.scene;
                        if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(scene))
                        {
                            if (!targetItem.isSceneHeader || dropPos == TreeViewDragging.DropPosition.Upon)
                            {
                                dropPos = TreeViewDragging.DropPosition.Below;
                            }
                            if (dropPos == TreeViewDragging.DropPosition.Above)
                            {
                                for (int index = 0; index < sceneList.Count; ++index)
                                {
                                    EditorSceneManager.MoveSceneBefore(sceneList[index], scene);
                                }
                            }
                            else if (dropPos == TreeViewDragging.DropPosition.Below)
                            {
                                for (int index = sceneList.Count - 1; index >= 0; --index)
                                {
                                    EditorSceneManager.MoveSceneAfter(sceneList[index], scene);
                                }
                            }
                        }
                    }
                    else
                    {
                        Scene sceneAt = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
                        for (int index = sceneList.Count - 1; index >= 0; --index)
                        {
                            EditorSceneManager.MoveSceneAfter(sceneList[index], sceneAt);
                        }
                    }
                }
            }
            return(DragAndDropVisualMode.Move);
        }
Ejemplo n.º 14
0
        private DragAndDropVisualMode DoDragScenes(GameObjectTreeViewItem parentItem, GameObjectTreeViewItem targetItem, bool perform, TreeViewDragging.DropPosition dropPos)
        {
            List <Scene> genericData = DragAndDrop.GetGenericData("SceneHeaderList") as List <Scene>;
            bool         flag        = genericData != null;
            bool         flag2       = false;

            if (!flag && (DragAndDrop.objectReferences.Length > 0))
            {
                int num = 0;
                foreach (Object obj2 in DragAndDrop.objectReferences)
                {
                    if (obj2 is SceneAsset)
                    {
                        num++;
                    }
                }
                flag2 = num == DragAndDrop.objectReferences.Length;
            }
            if (!flag && !flag2)
            {
                return(DragAndDropVisualMode.None);
            }
            if (perform)
            {
                List <Scene> list2 = null;
                if (flag2)
                {
                    List <Scene> source = new List <Scene>();
                    foreach (Object obj3 in DragAndDrop.objectReferences)
                    {
                        string assetPath   = AssetDatabase.GetAssetPath(obj3);
                        Scene  sceneByPath = SceneManager.GetSceneByPath(assetPath);
                        if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(sceneByPath))
                        {
                            base.m_TreeView.Frame(sceneByPath.handle, true, true);
                        }
                        else
                        {
                            if (Event.current.alt)
                            {
                                sceneByPath = EditorSceneManager.OpenScene(assetPath, OpenSceneMode.AdditiveWithoutLoading);
                            }
                            else
                            {
                                sceneByPath = EditorSceneManager.OpenScene(assetPath, OpenSceneMode.Additive);
                            }
                            if (SceneHierarchyWindow.IsSceneHeaderInHierarchyWindow(sceneByPath))
                            {
                                source.Add(sceneByPath);
                            }
                        }
                    }
                    if (targetItem != null)
                    {
                        list2 = source;
                    }
                    if ((SceneManager.sceneCount - source.Count) == 1)
                    {
                        Scene sceneAt = SceneManager.GetSceneAt(0);
                        ((TreeViewDataSource)base.m_TreeView.data).SetExpanded(sceneAt.handle, true);
                    }
                    if (source.Count > 0)
                    {
                        if (< > f__am$cache1 == null)
                        {