GetUniqueNameForSibling() private méthode

private GetUniqueNameForSibling ( Transform parent, string name ) : string
parent UnityEngine.Transform
name string
Résultat string
        static void CreateAndPlacePrimitive(PrimitiveType type, GameObject parent)
        {
            // make sure to get the unique name before the GameObject is created
            // or GetUniqueNameForSibling will always end up with (1) in empty scene
            string uniqueName = GameObjectUtility.GetUniqueNameForSibling(parent != null ? parent.transform : null, type.ToString());
            var    primitive  = ObjectFactory.CreatePrimitive(type);

            primitive.name = uniqueName;
            Place(primitive, parent);
        }
        internal static void CreateRectangularTilemap()
        {
            var root       = FindOrCreateRootGrid();
            var uniqueName = GameObjectUtility.GetUniqueNameForSibling(root.transform, "Tilemap");
            var tilemapGO  = ObjectFactory.CreateGameObject(uniqueName, typeof(Tilemap), typeof(TilemapRenderer));

            Undo.SetTransformParent(tilemapGO.transform, root.transform, "");
            tilemapGO.transform.position = Vector3.zero;
            Undo.SetCurrentGroupName("Create Tilemap");
        }
Exemple #3
0
        public static GameObject CreateDragGO(Sprite frame, Vector3 position)
        {
            string name = (!string.IsNullOrEmpty(frame.name)) ? frame.name : "Sprite";

            name = GameObjectUtility.GetUniqueNameForSibling(null, name);
            GameObject     gameObject     = new GameObject(name);
            SpriteRenderer spriteRenderer = gameObject.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite         = frame;
            gameObject.transform.position = position;
            return(gameObject);
        }
        internal static void CreateRectangularTilemap()
        {
            GameObject gameObject           = TilemapEditor.FindOrCreateRootGrid();
            string     uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling(gameObject.transform, "Tilemap");
            GameObject gameObject2          = ObjectFactory.CreateGameObject(uniqueNameForSibling, new Type[]
            {
                typeof(Tilemap),
                typeof(TilemapRenderer)
            });

            Undo.SetTransformParent(gameObject2.transform, gameObject.transform, "");
            gameObject2.transform.position = Vector3.zero;
            Undo.SetCurrentGroupName("Create Tilemap");
        }
Exemple #5
0
        public static GameObject CreateDragGO(Sprite frame, Vector3 position)
        {
            string name = string.IsNullOrEmpty(frame.name) ? "Sprite" : frame.name;

            name = GameObjectUtility.GetUniqueNameForSibling(null, name);
            GameObject go = new GameObject(name);

            SpriteRenderer spriteRenderer = go.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite = frame;
            go.transform.position = position;
            go.hideFlags          = HideFlags.HideAndDontSave;
            return(go);
        }
Exemple #6
0
        private static void CreateHexagonalTilemap(GridLayout.CellSwizzle swizzle, string undoMessage)
        {
            var root       = FindOrCreateRootGrid();
            var uniqueName = GameObjectUtility.GetUniqueNameForSibling(root.transform, "Tilemap");
            var tilemapGO  = ObjectFactory.CreateGameObject(uniqueName, typeof(Tilemap), typeof(TilemapRenderer));

            tilemapGO.transform.SetParent(root.transform);
            tilemapGO.transform.position = Vector3.zero;
            var grid = root.GetComponent <Grid>();

            grid.cellLayout  = Grid.CellLayout.Hexagon;
            grid.cellSwizzle = swizzle;
            var tilemap = tilemapGO.GetComponent <Tilemap>();

            tilemap.tileAnchor = Vector3.zero;
            Undo.RegisterCreatedObjectUndo(tilemapGO, undoMessage);
        }
        public static void CreateVisualEffectGameObject(MenuCommand menuCommand)
        {
            GameObject go = new GameObject(GameObjectUtility.GetUniqueNameForSibling(null, "Visual Effect"));

            GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
            var vfxComp = go.AddComponent <VisualEffect>();

            if (Selection.activeObject != null && Selection.activeObject is VisualEffectAsset)
            {
                vfxComp.visualEffectAsset = Selection.activeObject as VisualEffectAsset;
                vfxComp.startSeed         = (uint)Random.Range(int.MinValue, int.MaxValue);
            }

            Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);

            Selection.activeObject = go;
        }
        private static void CreateTerrain(MenuCommand menuCommand)
        {
            TerrainData terrainData = new TerrainData();

            terrainData.heightmapResolution = 1025;
            terrainData.size = new Vector3(1000f, 600f, 1000f);
            terrainData.heightmapResolution = 512;
            terrainData.baseMapResolution   = 1024;
            terrainData.SetDetailResolution(1024, terrainData.detailResolutionPerPatch);
            AssetDatabase.CreateAsset(terrainData, AssetDatabase.GenerateUniqueAssetPath("Assets/New Terrain.asset"));
            GameObject gameObject           = menuCommand.context as GameObject;
            string     uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling((!(gameObject != null)) ? null : gameObject.transform, "Terrain");
            GameObject gameObject2          = Terrain.CreateTerrainGameObject(terrainData);

            gameObject2.name = uniqueNameForSibling;
            GameObjectUtility.SetParentAndAlign(gameObject2, gameObject);
            Selection.activeObject = gameObject2;
            Undo.RegisterCreatedObjectUndo(gameObject2, "Create terrain");
        }
Exemple #9
0
        private static void CreateTerrain(MenuCommand menuCommand)
        {
            TerrainData asset = new TerrainData {
                heightmapResolution = 0x401,
                size = new Vector3(1000f, 600f, 1000f),
                heightmapResolution = 0x200,
                baseMapResolution   = 0x400
            };

            asset.SetDetailResolution(0x400, asset.detailResolutionPerPatch);
            AssetDatabase.CreateAsset(asset, AssetDatabase.GenerateUniqueAssetPath("Assets/New Terrain.asset"));
            GameObject context = menuCommand.context as GameObject;
            string     uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling(context?.transform, "Terrain");
            GameObject child = Terrain.CreateTerrainGameObject(asset);

            child.name = uniqueNameForSibling;
            GameObjectUtility.SetParentAndAlign(child, context);
            Selection.activeObject = child;
            Undo.RegisterCreatedObjectUndo(child, "Create terrain");
        }
Exemple #10
0
        public static GameObject CreateDragGO(Sprite frame, Vector3 position, SceneView sceneView)
        {
            string name = string.IsNullOrEmpty(frame.name) ? "Sprite" : frame.name;

            name = GameObjectUtility.GetUniqueNameForSibling(null, name);
            GameObject go = new GameObject(name);

            SpriteRenderer spriteRenderer = go.AddComponent <SpriteRenderer>();

            spriteRenderer.sprite = frame;
            go.transform.position = position;
            go.hideFlags          = HideFlags.HideAndDontSave;

            // Ensure that the dragged gameobjects gets the correct scene culling mask so it can be rendered in the SceneView (when the SceneView camera is culling on a custom scene)
            if (sceneView.customScene.IsValid())
            {
                SceneManager.MoveGameObjectToScene(go, sceneView.customScene);
            }

            return(go);
        }
        internal static bool DragPerform(SceneView sceneView, GameObject draggedObject, GameObject go)
        {
            var stage = StageNavigationManager.instance.currentStage;

            if (stage is PrefabStage)
            {
                var prefabAssetThatIsAddedTo = AssetDatabase.LoadMainAssetAtPath(stage.assetPath);
                if (PrefabUtility.CheckIfAddingPrefabWouldResultInCyclicNesting(prefabAssetThatIsAddedTo, go))
                {
                    PrefabUtility.ShowCyclicNestingWarningDialog();
                    return(false);
                }
            }

            var defaultParentObject = SceneView.GetDefaultParentObjectIfSet();
            var parent = defaultParentObject != null ? defaultParentObject : sceneView.customParentForDraggedObjects;

            string uniqueName = GameObjectUtility.GetUniqueNameForSibling(parent, draggedObject.name);

            if (parent != null)
            {
                draggedObject.transform.parent = parent;
            }
            draggedObject.hideFlags = 0;
            Undo.RegisterCreatedObjectUndo(draggedObject, "Place " + draggedObject.name);
            EditorUtility.SetDirty(draggedObject);
            DragAndDrop.AcceptDrag();
            Selection.activeObject             = draggedObject;
            HandleUtility.ignoreRaySnapObjects = null;
            if (SceneView.mouseOverWindow != null)
            {
                SceneView.mouseOverWindow.Focus();
            }
            if (!Application.IsPlaying(draggedObject))
            {
                draggedObject.name = uniqueName;
            }

            return(true);
        }
        private static void CreateIsometricTilemap(GridLayout.CellLayout isometricLayout, string undoMessage)
        {
            var root       = FindOrCreateRootGrid();
            var uniqueName = GameObjectUtility.GetUniqueNameForSibling(root.transform, "Tilemap");
            var tilemapGO  = ObjectFactory.CreateGameObject(uniqueName, typeof(Tilemap), typeof(TilemapRenderer));

            tilemapGO.transform.SetParent(root.transform);
            tilemapGO.transform.position = Vector3.zero;

            var grid = root.GetComponent <Grid>();

            // Case 1071703: Do not reset cell size if adding a new Tilemap to an existing Grid of the same layout
            if (isometricLayout != grid.cellLayout)
            {
                grid.cellLayout = isometricLayout;
                grid.cellSize   = new Vector3(1.0f, 0.5f, 0.0f);
            }

            var tilemapRenderer = tilemapGO.GetComponent <TilemapRenderer>();

            tilemapRenderer.sortOrder = TilemapRenderer.SortOrder.TopRight;
            Undo.RegisterCreatedObjectUndo(tilemapGO, undoMessage);
        }
        internal static void DragPerform(SceneView sceneView, GameObject draggedObject, GameObject go)
        {
            var defaultParentObject = SceneView.GetDefaultParentObjectIfSet();
            var parent = defaultParentObject != null ? defaultParentObject : sceneView.customParentForDraggedObjects;

            string uniqueName = GameObjectUtility.GetUniqueNameForSibling(parent, draggedObject.name);

            if (parent != null)
            {
                draggedObject.transform.parent = parent;
            }
            draggedObject.hideFlags = 0;
            Undo.RegisterCreatedObjectUndo(draggedObject, "Place " + draggedObject.name);
            EditorUtility.SetDirty(draggedObject);
            DragAndDrop.AcceptDrag();
            if (s_ShouldClearSelection)
            {
                Selection.objects      = new[] { draggedObject };
                s_ShouldClearSelection = false;
            }
            else
            {
                // Since this inspector code executes for each dragged GameObject we should retain
                // selection to all of them by joining them to the previous selection list
                Selection.objects = Selection.gameObjects.Union(new[] { draggedObject }).ToArray();
            }
            HandleUtility.ignoreRaySnapObjects = null;
            if (SceneView.mouseOverWindow != null)
            {
                SceneView.mouseOverWindow.Focus();
            }
            if (!Application.IsPlaying(draggedObject))
            {
                draggedObject.name = uniqueName;
            }
            s_CyclicNestingDetected = false;
        }
Exemple #14
0
        private static void CreateSpriteMaskGameObject()
        {
            GameObject gameObject = ObjectFactory.CreateGameObject("", new Type[]
            {
                typeof(SpriteMask)
            });

            if (Selection.activeObject is Sprite)
            {
                gameObject.GetComponent <SpriteMask>().sprite = (Sprite)Selection.activeObject;
            }
            else if (Selection.activeObject is Texture2D)
            {
                string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
                if (!string.IsNullOrEmpty(assetPath))
                {
                    Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath);
                    if (sprite != null)
                    {
                        gameObject.GetComponent <SpriteMask>().sprite = sprite;
                    }
                }
            }
            else if (Selection.activeObject is GameObject)
            {
                GameObject gameObject2 = (GameObject)Selection.activeObject;
                PrefabType prefabType  = PrefabUtility.GetPrefabType(gameObject2);
                if (prefabType != PrefabType.Prefab && prefabType != PrefabType.ModelPrefab)
                {
                    GameObjectUtility.SetParentAndAlign(gameObject, gameObject2);
                }
            }
            gameObject.name = GameObjectUtility.GetUniqueNameForSibling(gameObject.transform.parent, SpriteMaskEditor.Contents.newSpriteMaskName.text);
            Undo.SetCurrentGroupName(SpriteMaskEditor.Contents.createSpriteMaskUndoString.text);
            Selection.activeGameObject = gameObject;
        }
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject target = base.target as GameObject;

            switch (PrefabUtility.GetPrefabType(target))
            {
            case PrefabType.Prefab:
            case PrefabType.ModelPrefab:
            {
                Event     current = Event.current;
                EventType type    = current.type;
                if (type != EventType.DragUpdated)
                {
                    if (type == EventType.DragPerform)
                    {
                        string uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling(null, dragObject.name);
                        dragObject.hideFlags = HideFlags.None;
                        Undo.RegisterCreatedObjectUndo(dragObject, "Place " + dragObject.name);
                        EditorUtility.SetDirty(dragObject);
                        DragAndDrop.AcceptDrag();
                        Selection.activeObject             = dragObject;
                        HandleUtility.ignoreRaySnapObjects = null;
                        EditorWindow.mouseOverWindow.Focus();
                        dragObject.name = uniqueNameForSibling;
                        dragObject      = null;
                        current.Use();
                        break;
                    }
                    if (type == EventType.DragExited)
                    {
                        if (dragObject != null)
                        {
                            UnityEngine.Object.DestroyImmediate(dragObject, false);
                            HandleUtility.ignoreRaySnapObjects = null;
                            dragObject = null;
                            current.Use();
                        }
                        break;
                    }
                }
                else
                {
                    if (dragObject == null)
                    {
                        dragObject           = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.FindPrefabRoot(target));
                        dragObject.hideFlags = HideFlags.HideInHierarchy;
                        dragObject.name      = target.name;
                    }
                    if (HandleUtility.ignoreRaySnapObjects == null)
                    {
                        HandleUtility.ignoreRaySnapObjects = dragObject.GetComponentsInChildren <Transform>();
                    }
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    object obj3 = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                    if (obj3 != null)
                    {
                        RaycastHit hit = (RaycastHit)obj3;
                        float      num = 0f;
                        if (Tools.pivotMode == PivotMode.Center)
                        {
                            float num2 = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, hit.normal);
                            if (num2 != float.PositiveInfinity)
                            {
                                num = Vector3.Dot(dragObject.transform.position, hit.normal) - num2;
                            }
                        }
                        dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(hit.point + ((Vector3)(hit.normal * num)));
                    }
                    else
                    {
                        dragObject.transform.position = HandleUtility.GUIPointToWorldRay(current.mousePosition).GetPoint(10f);
                    }
                    if (sceneView.in2DMode)
                    {
                        Vector3 position = dragObject.transform.position;
                        position.z = PrefabUtility.FindPrefabRoot(target).transform.position.z;
                        dragObject.transform.position = position;
                    }
                    current.Use();
                }
                break;
            }
            }
        }
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject go         = target as GameObject;
            PrefabType prefabType = PrefabUtility.GetPrefabType(go);

            if (prefabType != PrefabType.Prefab && prefabType != PrefabType.ModelPrefab)
            {
                return;
            }

            Event evt = Event.current;

            switch (evt.type)
            {
            case EventType.DragUpdated:
                if (dragObject == null)
                {
                    dragObject           = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.FindPrefabRoot(go));
                    dragObject.hideFlags = HideFlags.HideInHierarchy;
                    dragObject.name      = go.name;
                }

                if (HandleUtility.ignoreRaySnapObjects == null)
                {
                    HandleUtility.ignoreRaySnapObjects = dragObject.GetComponentsInChildren <Transform>();
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                object hit = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(evt.mousePosition));
                if (hit != null)
                {
                    RaycastHit rh     = (RaycastHit)hit;
                    float      offset = 0;
                    if (Tools.pivotMode == PivotMode.Center)
                    {
                        float geomOffset = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, rh.normal);
                        if (geomOffset != Mathf.Infinity)
                        {
                            offset = Vector3.Dot(dragObject.transform.position, rh.normal) - geomOffset;
                        }
                    }
                    dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(rh.point + (rh.normal * offset));
                }
                else
                {
                    dragObject.transform.position = HandleUtility.GUIPointToWorldRay(evt.mousePosition).GetPoint(10);
                }

                // Use prefabs original z position when in 2D mode
                if (sceneView.in2DMode)
                {
                    Vector3 dragPosition = dragObject.transform.position;
                    dragPosition.z = PrefabUtility.FindPrefabRoot(go).transform.position.z;
                    dragObject.transform.position = dragPosition;
                }

                evt.Use();
                break;

            case EventType.DragPerform:
                string uniqueName = GameObjectUtility.GetUniqueNameForSibling(null, dragObject.name);
                dragObject.hideFlags = 0;
                Undo.RegisterCreatedObjectUndo(dragObject, "Place " + dragObject.name);
                EditorUtility.SetDirty(dragObject);
                DragAndDrop.AcceptDrag();
                Selection.activeObject             = dragObject;
                HandleUtility.ignoreRaySnapObjects = null;
                if (SceneView.mouseOverWindow != null)
                {
                    SceneView.mouseOverWindow.Focus();
                }
                dragObject.name = uniqueName;
                dragObject      = null;
                evt.Use();
                break;

            case EventType.DragExited:
                if (dragObject)
                {
                    UnityObject.DestroyImmediate(dragObject, false);
                    HandleUtility.ignoreRaySnapObjects = null;
                    dragObject = null;
                    evt.Use();
                }
                break;
            }
        }
 internal static GameObject CreateGameObject(GameObject parent, string name, params Type[] types)
 {
     return(ObjectFactory.CreateGameObject(GameObjectUtility.GetUniqueNameForSibling(parent != null ? parent.transform : null, name), types));
 }
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject go = target as GameObject;

            if (!PrefabUtility.IsPartOfPrefabAsset(go))
            {
                return;
            }

            var prefabAssetRoot = go.transform.root.gameObject;

            Event evt = Event.current;

            switch (evt.type)
            {
            case EventType.DragUpdated:

                Scene destinationScene = sceneView.customScene.IsValid() ? sceneView.customScene : SceneManager.GetActiveScene();
                if (dragObject == null)
                {
                    dragObject           = (GameObject)PrefabUtility.InstantiatePrefab(prefabAssetRoot, destinationScene);
                    dragObject.hideFlags = HideFlags.HideInHierarchy;
                    dragObject.name      = go.name;
                }

                if (HandleUtility.ignoreRaySnapObjects == null)
                {
                    HandleUtility.ignoreRaySnapObjects = dragObject.GetComponentsInChildren <Transform>();
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                object hit = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(evt.mousePosition));

                if (hit != null)
                {
                    RaycastHit rh     = (RaycastHit)hit;
                    float      offset = 0;
                    if (Tools.pivotMode == PivotMode.Center)
                    {
                        float geomOffset = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, rh.normal);
                        if (geomOffset != Mathf.Infinity)
                        {
                            offset = Vector3.Dot(dragObject.transform.position, rh.normal) - geomOffset;
                        }
                    }
                    dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(rh.point + (rh.normal * offset));
                }
                else
                {
                    dragObject.transform.position = HandleUtility.GUIPointToWorldRay(evt.mousePosition).GetPoint(10);
                }

                // Use prefabs original z position when in 2D mode
                if (sceneView.in2DMode)
                {
                    Vector3 dragPosition = dragObject.transform.position;
                    dragPosition.z = prefabAssetRoot.transform.position.z;
                    dragObject.transform.position = dragPosition;
                }

                evt.Use();
                break;

            case EventType.DragPerform:

                var stage = StageNavigationManager.instance.currentItem;
                if (stage.isPrefabStage)
                {
                    var prefabAssetThatIsAddedTo = AssetDatabase.LoadMainAssetAtPath(stage.prefabAssetPath);
                    if (PrefabUtility.CheckIfAddingPrefabWouldResultInCyclicNesting(prefabAssetThatIsAddedTo, go))
                    {
                        PrefabUtility.ShowCyclicNestingWarningDialog();
                        return;
                    }
                }

                Transform parent = sceneView.customParentForDraggedObjects;

                string uniqueName = GameObjectUtility.GetUniqueNameForSibling(parent, dragObject.name);
                if (parent != null)
                {
                    dragObject.transform.parent = parent;
                }
                dragObject.hideFlags = 0;
                Undo.RegisterCreatedObjectUndo(dragObject, "Place " + dragObject.name);
                EditorUtility.SetDirty(dragObject);
                DragAndDrop.AcceptDrag();
                Selection.activeObject             = dragObject;
                HandleUtility.ignoreRaySnapObjects = null;
                if (SceneView.mouseOverWindow != null)
                {
                    SceneView.mouseOverWindow.Focus();
                }
                dragObject.name = uniqueName;
                dragObject      = null;
                evt.Use();
                break;

            case EventType.DragExited:
                if (dragObject)
                {
                    UnityObject.DestroyImmediate(dragObject, false);
                    HandleUtility.ignoreRaySnapObjects = null;
                    dragObject = null;
                    evt.Use();
                }
                break;
            }
        }
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject gameObject = this.target as GameObject;
            PrefabType prefabType = PrefabUtility.GetPrefabType(gameObject);

            if (prefabType != PrefabType.Prefab && prefabType != PrefabType.ModelPrefab)
            {
                return;
            }
            Event     current = Event.current;
            EventType type    = current.type;

            if (type != EventType.DragUpdated)
            {
                if (type != EventType.DragPerform)
                {
                    if (type == EventType.DragExited)
                    {
                        if (GameObjectInspector.dragObject)
                        {
                            UnityEngine.Object.DestroyImmediate(GameObjectInspector.dragObject, false);
                            HandleUtility.ignoreRaySnapObjects = null;
                            GameObjectInspector.dragObject     = null;
                            current.Use();
                        }
                    }
                }
                else
                {
                    string uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling(null, GameObjectInspector.dragObject.name);
                    GameObjectInspector.dragObject.hideFlags = HideFlags.None;
                    Undo.RegisterCreatedObjectUndo(GameObjectInspector.dragObject, "Place " + GameObjectInspector.dragObject.name);
                    EditorUtility.SetDirty(GameObjectInspector.dragObject);
                    DragAndDrop.AcceptDrag();
                    Selection.activeObject             = GameObjectInspector.dragObject;
                    HandleUtility.ignoreRaySnapObjects = null;
                    EditorWindow.mouseOverWindow.Focus();
                    GameObjectInspector.dragObject.name = uniqueNameForSibling;
                    GameObjectInspector.dragObject      = null;
                    current.Use();
                }
            }
            else
            {
                if (GameObjectInspector.dragObject == null)
                {
                    GameObjectInspector.dragObject           = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.FindPrefabRoot(gameObject));
                    HandleUtility.ignoreRaySnapObjects       = GameObjectInspector.dragObject.GetComponentsInChildren <Transform>();
                    GameObjectInspector.dragObject.hideFlags = HideFlags.HideInHierarchy;
                    GameObjectInspector.dragObject.name      = gameObject.name;
                }
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                if (obj != null)
                {
                    RaycastHit raycastHit = (RaycastHit)obj;
                    float      d          = 0f;
                    if (Tools.pivotMode == PivotMode.Center)
                    {
                        float num = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, raycastHit.normal);
                        if (num != float.PositiveInfinity)
                        {
                            d = Vector3.Dot(GameObjectInspector.dragObject.transform.position, raycastHit.normal) - num;
                        }
                    }
                    GameObjectInspector.dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(raycastHit.point + raycastHit.normal * d);
                }
                else
                {
                    GameObjectInspector.dragObject.transform.position = HandleUtility.GUIPointToWorldRay(current.mousePosition).GetPoint(10f);
                }
                if (sceneView.in2DMode)
                {
                    Vector3 position = GameObjectInspector.dragObject.transform.position;
                    position.z = PrefabUtility.FindPrefabRoot(gameObject).transform.position.z;
                    GameObjectInspector.dragObject.transform.position = position;
                }
                current.Use();
            }
        }
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject target = this.target as GameObject;

            switch (PrefabUtility.GetPrefabType((UnityEngine.Object)target))
            {
            case PrefabType.Prefab:
            case PrefabType.ModelPrefab:
                Event current = Event.current;
                switch (current.type)
                {
                case EventType.DragUpdated:
                    if ((UnityEngine.Object)GameObjectInspector.dragObject == (UnityEngine.Object)null)
                    {
                        GameObjectInspector.dragObject           = (GameObject)PrefabUtility.InstantiatePrefab((UnityEngine.Object)PrefabUtility.FindPrefabRoot(target));
                        HandleUtility.ignoreRaySnapObjects       = GameObjectInspector.dragObject.GetComponentsInChildren <Transform>();
                        GameObjectInspector.dragObject.hideFlags = HideFlags.HideInHierarchy;
                        GameObjectInspector.dragObject.name      = target.name;
                    }
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                    if (obj != null)
                    {
                        RaycastHit raycastHit = (RaycastHit)obj;
                        float      num1       = 0.0f;
                        if (Tools.pivotMode == PivotMode.Center)
                        {
                            float num2 = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, raycastHit.normal);
                            if ((double)num2 != double.PositiveInfinity)
                            {
                                num1 = Vector3.Dot(GameObjectInspector.dragObject.transform.position, raycastHit.normal) - num2;
                            }
                        }
                        GameObjectInspector.dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(raycastHit.point + raycastHit.normal * num1);
                    }
                    else
                    {
                        GameObjectInspector.dragObject.transform.position = HandleUtility.GUIPointToWorldRay(current.mousePosition).GetPoint(10f);
                    }
                    if (sceneView.in2DMode)
                    {
                        Vector3 position = GameObjectInspector.dragObject.transform.position;
                        position.z = PrefabUtility.FindPrefabRoot(target).transform.position.z;
                        GameObjectInspector.dragObject.transform.position = position;
                    }
                    current.Use();
                    return;

                case EventType.DragPerform:
                    string uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling((Transform)null, GameObjectInspector.dragObject.name);
                    GameObjectInspector.dragObject.hideFlags = HideFlags.None;
                    Undo.RegisterCreatedObjectUndo((UnityEngine.Object)GameObjectInspector.dragObject, "Place " + GameObjectInspector.dragObject.name);
                    EditorUtility.SetDirty((UnityEngine.Object)GameObjectInspector.dragObject);
                    DragAndDrop.AcceptDrag();
                    Selection.activeObject             = (UnityEngine.Object)GameObjectInspector.dragObject;
                    HandleUtility.ignoreRaySnapObjects = (Transform[])null;
                    EditorWindow.mouseOverWindow.Focus();
                    GameObjectInspector.dragObject.name = uniqueNameForSibling;
                    GameObjectInspector.dragObject      = (GameObject)null;
                    current.Use();
                    return;

                case EventType.DragExited:
                    if (!(bool)((UnityEngine.Object)GameObjectInspector.dragObject))
                    {
                        return;
                    }
                    UnityEngine.Object.DestroyImmediate((UnityEngine.Object)GameObjectInspector.dragObject, false);
                    HandleUtility.ignoreRaySnapObjects = (Transform[])null;
                    GameObjectInspector.dragObject     = (GameObject)null;
                    current.Use();
                    return;

                default:
                    return;
                }
            }
        }