public static GameObject CreateGameObject(Scene scene, HideFlags hideFlags, string name, params Type[] types)
        {
            if (!scene.IsValid())
            {
                throw new ArgumentException("Cannot create a GameObject to a null Scene.");
            }

            //Internally, this sets the target scene that the scene points to.
            EditorSceneManager.SetTargetSceneForNewGameObjects(scene);
            var go = CreateGameObject(name, types);

            go.hideFlags = hideFlags;
            EditorSceneManager.ClearTargetSceneForNewGameObjects();
            return(go);
        }
        static bool IsPrefabStageHeader(GameObjectTreeViewItem item)
        {
            if (!item.isSceneHeader)
            {
                return(false);
            }

            Scene scene = EditorSceneManager.GetSceneByHandle(item.id);

            if (!scene.IsValid())
            {
                return(false);
            }

            return(EditorSceneManager.IsPreviewScene(scene));
        }
        internal static void PasteGOAsChild()
        {
            Transform[] selected = Selection.transforms;

            // paste as a child if a gameObject is selected
            if (selected.Length == 1)
            {
                Scene subScene        = new Scene();
                bool  pasteToSubScene = false;
                bool  isSubScene      = false;

                // If target is subScene make sure we just move objects under subScene
                if (SubSceneGUI.IsSubSceneHeader(selected[0].gameObject))
                {
                    subScene        = SubSceneGUI.GetSubScene(selected[0].gameObject);
                    isSubScene      = subScene.isSubScene;
                    pasteToSubScene = subScene.IsValid();
                }

                // handle paste after cut
                if (CutBoard.hasCutboardData)
                {
                    if (pasteToSubScene)
                    {
                        if (subScene.handle != 0)
                        {
                            CutBoard.PasteToScene(subScene, selected[0]);
                            pastedGameObjects?.Invoke(Selection.gameObjects);
                        }
                    }
                    else if (!isSubScene)
                    {
                        CutBoard.PasteAsChildren(selected[0]);
                        pastedGameObjects?.Invoke(Selection.gameObjects);
                    }
                }
                // paste after copy
                else if (pasteToSubScene || !isSubScene)
                {
                    Unsupported.PasteGameObjectsFromPasteboard(selected[0], pasteToSubScene ? subScene.handle : 0);
                    pastedGameObjects?.Invoke(Selection.gameObjects);
                }
            }
            RepaintHierarchyWindowsAfterPaste();
        }
        private void FilterSettingsChanged()
        {
            SearchFilter searchFilter = new SearchFilter();

            searchFilter.SearchFieldStringToFilter(this.m_SearchFilter);
            if (!string.IsNullOrEmpty(this.m_RequiredType))
            {
                searchFilter.classNames = new string[] { this.m_RequiredType };
            }
            HierarchyType hierarchyType = !this.m_IsShowingAssets ? HierarchyType.GameObjects : HierarchyType.Assets;

            if ((EditorSceneManager.preventCrossSceneReferences && (hierarchyType == HierarchyType.GameObjects)) && (this.m_ObjectBeingEdited != null))
            {
                Scene sceneFromObject = this.GetSceneFromObject(this.m_ObjectBeingEdited);
                if (sceneFromObject.IsValid())
                {
                    searchFilter.scenePaths = new string[] { sceneFromObject.path };
                }
            }
            this.m_ListArea.Init(this.listPosition, hierarchyType, searchFilter, true);
        }
Beispiel #5
0
        public static void DoItemGUI(Rect rect, GameObjectTreeViewItem goItem, bool isSelected, bool isHovered, bool isFocused, bool isDragging)
        {
            Rect iconRect = rect;

            iconRect.xMin += k_VisibilityIconPadding;
            iconRect.width = k_IconWidth;
            isHovered      = isHovered && !isDragging;
            bool isIconHovered = !isDragging && iconRect.Contains(Event.current.mousePosition);

            if (isHovered)
            {
                GUIView.current.MarkHotRegion(GUIClip.UnclipToWindow(iconRect));
            }

            GameObject gameObject = goItem.objectPPTR as GameObject;

            if (gameObject)
            {
                // The scene header overlaps it's next item by some pixels. Displace the background so it doesn't draw on top of the scene header.
                // Don't displace when selected or hovered (They already show on top of the header)
                if (m_PrevItemWasScene && !isSelected && !isHovered)
                {
                    rect.yMin += k_sceneHeaderOverflow;
                }

                DrawItemBackground(rect, false, isSelected, isHovered, isFocused);
                DrawGameObjectItem(iconRect, gameObject, isHovered, isIconHovered);
                m_PrevItemWasScene = false;
            }
            else
            {
                Scene scene = goItem.scene;
                if (scene.IsValid())
                {
                    DrawItemBackground(rect, true, isSelected, isHovered, isFocused);
                    DrawSceneItem(iconRect, scene, isHovered, isIconHovered);
                    m_PrevItemWasScene = true;
                }
            }
        }
 int GetDropTargetInstanceID(GameObjectTreeViewItem hierarchyTargetItem)
 {
     if (SubSceneGUI.IsUsingSubScenes())
     {
         var gameObjectDropTarget = hierarchyTargetItem.objectPPTR as GameObject;
         if (gameObjectDropTarget != null)
         {
             if (SubSceneGUI.IsSubSceneHeader(gameObjectDropTarget))
             {
                 Scene subScene = SubSceneGUI.GetSubScene(gameObjectDropTarget);
                 if (subScene.IsValid())
                 {
                     return(subScene.handle);
                 }
                 else
                 {
                     return(0);
                 }
             }
         }
     }
     return(hierarchyTargetItem.id);
 }
        public override DragAndDropVisualMode DoDrag(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, DropPosition dropPos)
        {
            var hierarchyTargetItem = targetItem as GameObjectTreeViewItem;

            // Allow client to handle drag
            if (m_CustomDragHandling != null)
            {
                DragAndDropVisualMode dragResult = m_CustomDragHandling(parentItem as GameObjectTreeViewItem, hierarchyTargetItem, dropPos, perform);
                if (dragResult != DragAndDropVisualMode.None)
                {
                    return(dragResult);
                }
            }

            // Scene dragging logic
            DragAndDropVisualMode dragSceneResult = DoDragScenes(parentItem as GameObjectTreeViewItem, hierarchyTargetItem, perform, dropPos);

            if (dragSceneResult != DragAndDropVisualMode.None)
            {
                return(dragSceneResult);
            }

            if (targetItem != null && !IsDropTargetUserModifiable(hierarchyTargetItem, dropPos))
            {
                return(DragAndDropVisualMode.Rejected);
            }

            var option       = InternalEditorUtility.HierarchyDropMode.kHierarchyDragNormal;
            var searchActive = !string.IsNullOrEmpty(dataSource.searchString);

            if (searchActive)
            {
                option |= InternalEditorUtility.HierarchyDropMode.kHierarchySearchActive;
            }
            if (parentItem == null || targetItem == null)
            {
                // Here we are dragging outside any treeview items:

                if (parentForDraggedObjectsOutsideItems != null)
                {
                    // Use specific parent for DragAndDropForwarding
                    return(DragAndDropService.Drop(DragAndDropService.kHierarchyDropDstId, 0, option, parentForDraggedObjectsOutsideItems, perform));
                }
                else
                {
                    // Simulate drag upon the last loaded scene in the hierarchy (adds as last root sibling of the last scene)
                    Scene lastScene = dataSource.GetLastScene();
                    if (!lastScene.IsValid())
                    {
                        return(DragAndDropVisualMode.Rejected);
                    }

                    option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropUpon;
                    return(DragAndDropService.Drop(DragAndDropService.kHierarchyDropDstId, lastScene.handle, option, null, perform));
                }
            }

            // Here we are hovering over items

            var draggingUpon = dropPos == TreeViewDragging.DropPosition.Upon;

            if (searchActive && !draggingUpon)
            {
                return(DragAndDropVisualMode.None);
            }

            if (draggingUpon)
            {
                option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropUpon;
            }
            else
            {
                if (dropPos == TreeViewDragging.DropPosition.Above)
                {
                    option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropAbove;
                }
                else
                {
                    option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropBetween;
                }
            }

            bool isDroppingBetweenParentAndFirstChild = parentItem != null && targetItem != parentItem && dropPos == DropPosition.Above && parentItem.children[0] == targetItem;

            if (isDroppingBetweenParentAndFirstChild)
            {
                option |= InternalEditorUtility.HierarchyDropMode.kHierarchyDropAfterParent;
            }

            int gameObjectOrSceneInstanceID = GetDropTargetInstanceID(hierarchyTargetItem, dropPos);

            if (gameObjectOrSceneInstanceID == 0)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            if (perform && SubSceneGUI.IsUsingSubScenes() && !IsValidSubSceneDropTarget(gameObjectOrSceneInstanceID, dropPos, DragAndDrop.objectReferences))
            {
                return(DragAndDropVisualMode.Rejected);
            }

            return(DragAndDropService.Drop(DragAndDropService.kHierarchyDropDstId, gameObjectOrSceneInstanceID, option, null, perform));
        }
 void OnSceneSelectionStateChanged(Scene selectedScene)
 {
     m_SceneHierarchy.customScenes = selectedScene.IsValid() ? new[] { selectedScene } : null;
     Repaint();
 }
 public static bool IsSceneHeaderInHierarchyWindow(Scene scene)
 {
     return(scene.IsValid());
 }