GUIPointToWorldRay() public static method

Convert 2D GUI position to a world space ray.

public static GUIPointToWorldRay ( Vector2 position ) : Ray
position Vector2
return UnityEngine.Ray
        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)
                {
                    // While dragging the instantiated prefab we do not want to record undo for this object
                    // this will cause a remerge of the instance since changes are undone while dragging.
                    // The DrivenRectTransformTracker by default records Undo when used when driving
                    // UI components. This breaks our hideflag setup below due to a remerge of the dragged instance.
                    // StartRecordingUndo() is called on DragExited. Fixes case 1223793.
                    DrivenRectTransformTracker.StopRecordingUndo();

                    if (!EditorApplication.isPlaying || EditorSceneManager.IsPreviewScene(destinationScene))
                    {
                        dragObject      = (GameObject)PrefabUtility.InstantiatePrefab(prefabAssetRoot, destinationScene);
                        dragObject.name = go.name;
                    }
                    else
                    {
                        // Instatiate as regular GameObject in Play Mode so runtime logic
                        // won't run into restrictions on restructuring Prefab instances.
                        dragObject = Instantiate(prefabAssetRoot);
                        SceneManager.MoveGameObjectToScene(dragObject, destinationScene);
                    }
                    dragObject.hideFlags = HideFlags.HideInHierarchy;
                }

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

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                Vector3 point, normal;

                if (HandleUtility.PlaceObject(evt.mousePosition, out point, out normal))
                {
                    float offset = 0;
                    if (Tools.pivotMode == PivotMode.Center)
                    {
                        float geomOffset = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, normal);
                        if (geomOffset != Mathf.Infinity)
                        {
                            offset = Vector3.Dot(dragObject.transform.position, normal) - geomOffset;
                        }
                    }
                    dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(point + (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:
                if (!DragPerform(sceneView, dragObject, go))
                {
                    return;
                }
                dragObject = null;
                evt.Use();
                break;

            case EventType.DragExited:
                // DragExited is always fired after DragPerform so we do no need to call StartRecordingUndo
                // in DragPerform
                DrivenRectTransformTracker.StartRecordingUndo();

                if (dragObject)
                {
                    UnityObject.DestroyImmediate(dragObject, false);
                    HandleUtility.ignoreRaySnapObjects = null;
                    dragObject = null;
                    evt.Use();
                }
                break;
            }
        }
Esempio n. 2
0
        public static void OnSceneDrag(SceneView sceneView)
        {
            Event current = Event.current;

            if (current.type != EventType.DragUpdated && current.type != EventType.DragPerform && current.type != EventType.DragExited)
            {
                return;
            }
            if (!sceneView.in2DMode)
            {
                GameObject gameObject = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                if (gameObject != null && DragAndDrop.objectReferences.Length == 1 && DragAndDrop.objectReferences[0] as Texture != null && gameObject.GetComponent <Renderer>() != null)
                {
                    SpriteUtility.CleanUp(true);
                    return;
                }
            }
            EventType type = current.type;

            if (type != EventType.DragUpdated)
            {
                if (type != EventType.DragPerform)
                {
                    if (type == EventType.DragExited)
                    {
                        if (SpriteUtility.s_SceneDragObjects != null && SpriteUtility.s_SceneDragObjects != null)
                        {
                            SpriteUtility.CleanUp(true);
                            current.Use();
                        }
                    }
                }
                else
                {
                    Sprite[] spriteFromDraggedPathsOrObjects = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                    if (spriteFromDraggedPathsOrObjects != null && SpriteUtility.s_SceneDragObjects != null)
                    {
                        if (SpriteUtility.s_DragType == SpriteUtility.DragType.SpriteAnimation)
                        {
                            SpriteUtility.AddAnimationToGO((GameObject)SpriteUtility.s_SceneDragObjects[0], spriteFromDraggedPathsOrObjects);
                        }
                        using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                GameObject gameObject2 = (GameObject)enumerator.Current;
                                Undo.RegisterCreatedObjectUndo(gameObject2, "Create Sprite");
                                gameObject2.hideFlags = HideFlags.None;
                            }
                        }
                        Selection.objects = SpriteUtility.s_SceneDragObjects.ToArray();
                        SpriteUtility.CleanUp(false);
                        current.Use();
                    }
                }
            }
            else
            {
                SpriteUtility.DragType dragType = (!current.alt) ? SpriteUtility.DragType.SpriteAnimation : SpriteUtility.DragType.CreateMultiple;
                if (SpriteUtility.s_DragType != dragType || SpriteUtility.s_SceneDragObjects == null)
                {
                    Sprite[] spriteFromDraggedPathsOrObjects2 = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                    if (spriteFromDraggedPathsOrObjects2 == null || spriteFromDraggedPathsOrObjects2.Length == 0)
                    {
                        return;
                    }
                    Sprite x = spriteFromDraggedPathsOrObjects2[0];
                    if (x == null)
                    {
                        return;
                    }
                    if (SpriteUtility.s_DragType != SpriteUtility.DragType.NotInitialized)
                    {
                        SpriteUtility.CleanUp(true);
                    }
                    SpriteUtility.s_DragType         = dragType;
                    SpriteUtility.s_SceneDragObjects = new List <UnityEngine.Object>();
                    if (SpriteUtility.s_DragType == SpriteUtility.DragType.CreateMultiple)
                    {
                        Sprite[] array = spriteFromDraggedPathsOrObjects2;
                        for (int i = 0; i < array.Length; i++)
                        {
                            Sprite frame = array[i];
                            SpriteUtility.s_SceneDragObjects.Add(SpriteUtility.CreateDragGO(frame, Vector3.zero));
                        }
                    }
                    else
                    {
                        SpriteUtility.s_SceneDragObjects.Add(SpriteUtility.CreateDragGO(spriteFromDraggedPathsOrObjects2[0], Vector3.zero));
                    }
                    List <Transform> list = new List <Transform>();
                    using (List <UnityEngine.Object> .Enumerator enumerator2 = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            GameObject gameObject3 = (GameObject)enumerator2.Current;
                            list.AddRange(gameObject3.GetComponentsInChildren <Transform>());
                            gameObject3.hideFlags = HideFlags.HideInHierarchy;
                        }
                    }
                    HandleUtility.ignoreRaySnapObjects = list.ToArray();
                }
                Vector3 position = Vector3.zero;
                position = HandleUtility.GUIPointToWorldRay(current.mousePosition).GetPoint(10f);
                if (sceneView.in2DMode)
                {
                    position.z = 0f;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                    if (obj != null)
                    {
                        position = ((RaycastHit)obj).point;
                    }
                }
                using (List <UnityEngine.Object> .Enumerator enumerator3 = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator3.MoveNext())
                    {
                        GameObject gameObject4 = (GameObject)enumerator3.Current;
                        gameObject4.transform.position = position;
                    }
                }
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                current.Use();
            }
        }
Esempio n. 3
0
        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)
                {
                    if (!EditorApplication.isPlaying || EditorSceneManager.IsPreviewScene(destinationScene))
                    {
                        dragObject      = (GameObject)PrefabUtility.InstantiatePrefab(prefabAssetRoot, destinationScene);
                        dragObject.name = go.name;
                    }
                    else
                    {
                        // Instatiate as regular GameObject in Play Mode so runtime logic
                        // won't run into restrictions on restructuring Prefab instances.
                        dragObject = Instantiate(prefabAssetRoot);
                        SceneManager.MoveGameObjectToScene(dragObject, destinationScene);
                    }
                    dragObject.hideFlags = HideFlags.HideInHierarchy;
                }

                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.currentStage;
                if (stage is PrefabStage)
                {
                    var prefabAssetThatIsAddedTo = AssetDatabase.LoadMainAssetAtPath(stage.assetPath);
                    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();
                }
                if (!Application.IsPlaying(dragObject))
                {
                    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 OnSceneGUI()
        {
            if (m_ActiveCollider == null)
            {
                return;
            }

            // Skip editing of polygon if view tool is active i.e. while panning the scene view
            if (Tools.viewToolActive)
            {
                return;
            }

            // Fetch the collider offset.
            var colliderOffset = m_ActiveCollider.offset;

            Event evt = Event.current;

            m_DeleteMode = evt.command || evt.control;
            Transform transform = m_ActiveCollider.transform;

            // Handles.Slider2D will render active point as yellow if there is keyboardControl set. We don't want that happening.
            GUIUtility.keyboardControl = 0;

            HandleUtility.s_CustomPickDistance = k_HandlePickDistance;

            // Find mouse positions in local and world space
            Plane plane    = new Plane(-transform.forward, Vector3.zero);
            Ray   mouseRay = HandleUtility.GUIPointToWorldRay(evt.mousePosition);
            float dist;

            plane.Raycast(mouseRay, out dist);

            Vector3 mouseWorldPos = mouseRay.GetPoint(dist);
            Vector2 mouseLocalPos = transform.InverseTransformPoint(mouseWorldPos);

            // Select the active vertex and edge
            if (evt.type == EventType.MouseMove || m_FirstOnSceneGUIAfterReset)
            {
                int   pathIndex;
                int   pointIndex0, pointIndex1;
                float distance;
                if (PolygonEditor.GetNearestPoint(mouseLocalPos - colliderOffset, out pathIndex, out pointIndex0, out distance))
                {
                    m_SelectedPath   = pathIndex;
                    m_SelectedVertex = pointIndex0;
                }
                else
                {
                    m_SelectedPath = -1;
                }

                if (PolygonEditor.GetNearestEdge(mouseLocalPos - colliderOffset, out pathIndex, out pointIndex0, out pointIndex1, out distance, m_LoopingCollider))
                {
                    m_SelectedEdgePath    = pathIndex;
                    m_SelectedEdgeVertex0 = pointIndex0;
                    m_SelectedEdgeVertex1 = pointIndex1;
                }
                else
                {
                    m_SelectedEdgePath = -1;
                }

                if (evt.type == EventType.MouseMove)
                {
                    evt.Use();
                }
            }
            else if (evt.type == EventType.MouseUp)
            {
                m_LeftIntersect  = false;
                m_RightIntersect = false;
            }

            // Do we handle point or line?
            // TODO: there probably isn't a case when selectedPath is valid and selectedEdge is invalid. This needs a refactor.


            if (GUIUtility.hotControl == 0)
            {
                if (m_SelectedPath != -1 && m_SelectedEdgePath != -1)
                {
                    // Calculate snapping distance
                    Vector2 point;
                    PolygonEditor.GetPoint(m_SelectedPath, m_SelectedVertex, out point);
                    point += colliderOffset;
                    Vector3 worldPos = transform.TransformPoint(point);
                    m_HandleEdge  = (HandleUtility.WorldToGUIPoint(worldPos) - Event.current.mousePosition).sqrMagnitude > k_HandlePointSnap * k_HandlePointSnap;
                    m_HandlePoint = !m_HandleEdge;
                }
                else if (m_SelectedPath != -1)
                {
                    m_HandlePoint = true;
                }
                else if (m_SelectedEdgePath != -1)
                {
                    m_HandleEdge = true;
                }

                if (m_DeleteMode && m_HandleEdge)
                {
                    m_HandleEdge  = false;
                    m_HandlePoint = true;
                }
            }

            bool applyToCollider = false;

            // Edge handle
            if (m_HandleEdge && !m_DeleteMode)
            {
                Vector2 p0, p1;
                PolygonEditor.GetPoint(m_SelectedEdgePath, m_SelectedEdgeVertex0, out p0);
                PolygonEditor.GetPoint(m_SelectedEdgePath, m_SelectedEdgeVertex1, out p1);
                p0 += colliderOffset;
                p1 += colliderOffset;
                Vector3 worldPosV0 = transform.TransformPoint(p0);
                Vector3 worldPosV1 = transform.TransformPoint(p1);
                worldPosV0.z = worldPosV1.z = 0;

                Handles.color = Color.green;
                Handles.DrawAAPolyLine(4.0f, new Vector3[] { worldPosV0, worldPosV1 });
                Handles.color = Color.white;

                Vector2 newPoint = GetNearestPointOnEdge(transform.TransformPoint(mouseLocalPos), worldPosV0, worldPosV1);

                EditorGUI.BeginChangeCheck();
                float guiSize = HandleUtility.GetHandleSize(newPoint) * 0.04f;
                Handles.color = Color.green;

                newPoint = Handles.Slider2D(
                    newPoint,
                    new Vector3(0, 0, 1),
                    new Vector3(1, 0, 0),
                    new Vector3(0, 1, 0),
                    guiSize,
                    Handles.DotHandleCap,
                    Vector3.zero);
                Handles.color = Color.white;
                if (EditorGUI.EndChangeCheck())
                {
                    PolygonEditor.InsertPoint(m_SelectedEdgePath, m_SelectedEdgeVertex1, ((p0 + p1) / 2) - colliderOffset);
                    m_SelectedPath   = m_SelectedEdgePath;
                    m_SelectedVertex = m_SelectedEdgeVertex1;
                    m_HandleEdge     = false;
                    m_HandlePoint    = true;
                    applyToCollider  = true;
                }
            }

            // Point handle
            if (m_HandlePoint)
            {
                Vector2 point;
                PolygonEditor.GetPoint(m_SelectedPath, m_SelectedVertex, out point);
                point += colliderOffset;
                Vector3 worldPos = transform.TransformPoint(point);
                worldPos.z = 0;
                Vector2 screenPos = HandleUtility.WorldToGUIPoint(worldPos);

                float guiSize = HandleUtility.GetHandleSize(worldPos) * 0.04f;

                if (m_DeleteMode && evt.type == EventType.MouseDown &&
                    Vector2.Distance(screenPos, Event.current.mousePosition) < k_HandlePickDistance ||
                    DeleteCommandEvent(evt))
                {
                    if (evt.type != EventType.ValidateCommand)
                    {
                        int pathPointCount = PolygonEditor.GetPointCount(m_SelectedPath);
                        if (pathPointCount > m_MinPathPoints)
                        {
                            PolygonEditor.RemovePoint(m_SelectedPath, m_SelectedVertex);
                            Reset();
                            applyToCollider = true;
                        }
                    }
                    evt.Use();
                }

                EditorGUI.BeginChangeCheck();
                Handles.color = m_DeleteMode ? Color.red : Color.green;
                Vector3 newWorldPos = Handles.Slider2D(
                    worldPos,
                    new Vector3(0, 0, 1),
                    new Vector3(1, 0, 0),
                    new Vector3(0, 1, 0),
                    guiSize,
                    Handles.DotHandleCap,
                    Vector3.zero);
                Handles.color = Color.white;
                if (EditorGUI.EndChangeCheck() && !m_DeleteMode)
                {
                    point  = transform.InverseTransformPoint(newWorldPos);
                    point -= colliderOffset;
                    PolygonEditor.TestPointMove(m_SelectedPath, m_SelectedVertex, point, out m_LeftIntersect, out m_RightIntersect, m_LoopingCollider);
                    PolygonEditor.SetPoint(m_SelectedPath, m_SelectedVertex, point);
                    applyToCollider = true;
                }

                if (!applyToCollider)
                {
                    DrawEdgesForSelectedPoint(newWorldPos, transform, m_LeftIntersect, m_RightIntersect, m_LoopingCollider);
                }
            }

            // Apply changes
            if (applyToCollider)
            {
                Undo.RecordObject(m_ActiveCollider, "Edit Collider");
                PolygonEditor.ApplyEditing(m_ActiveCollider);
            }

            if (DeleteCommandEvent(evt))
            {
                Event.current.Use();  // If we don't use the delete event in all cases, it sceneview might delete the entire object
            }
            m_FirstOnSceneGUIAfterReset = false;
        }
Esempio n. 5
0
        private static void HandleScrollWheel(SceneView view, bool zoomTowardsCenter)
        {
            if (Tools.s_LockedViewTool == ViewTool.FPS)
            {
                float scrollWheelDelta = Event.current.delta.y * s_FPSScrollWheelMultiplier;
                view.cameraSettings.speedNormalized -= scrollWheelDelta;
                float  cameraSettingsSpeed     = view.cameraSettings.speed;
                string cameraSpeedDisplayValue = cameraSettingsSpeed.ToString(
                    cameraSettingsSpeed < 0.01f  ? "F3" :
                    cameraSettingsSpeed < 0.1f  ? "F2" :
                    cameraSettingsSpeed < 10f ? "F1" :
                    "F0");

                if (cameraSettingsSpeed < 0.1f)
                {
                    cameraSpeedDisplayValue = cameraSpeedDisplayValue.TrimStart(new Char[] { '0' });
                }

                GUIContent cameraSpeedContent = EditorGUIUtility.TempContent(string.Format("{0}{1}",
                                                                                           cameraSpeedDisplayValue,
                                                                                           s_CurrentSceneView.cameraSettings.accelerationEnabled ? "x" : ""));

                view.ShowNotification(cameraSpeedContent, .5f);
            }
            else
            {
                float zoomDelta = Event.current.delta.y;
                float targetSize;

                if (!view.orthographic)
                {
                    float       relativeDelta = Mathf.Abs(view.size) * zoomDelta * .015f;
                    const float deltaCutoff   = .3f;
                    if (relativeDelta > 0 && relativeDelta < deltaCutoff)
                    {
                        relativeDelta = deltaCutoff;
                    }
                    else if (relativeDelta < 0 && relativeDelta > -deltaCutoff)
                    {
                        relativeDelta = -deltaCutoff;
                    }

                    targetSize = view.size + relativeDelta;
                }
                else
                {
                    targetSize = Mathf.Abs(view.size) * (zoomDelta * .015f + 1.0f);
                }

                var initialDistance = view.cameraDistance;

                if (!(float.IsNaN(targetSize) || float.IsInfinity(targetSize)))
                {
                    targetSize = Mathf.Min(SceneView.k_MaxSceneViewSize, targetSize);
                    view.size  = targetSize;
                }

                if (!zoomTowardsCenter && Mathf.Abs(view.cameraDistance) < 1.0e7f)
                {
                    var percentage  = 1f - (view.cameraDistance / initialDistance);
                    var mouseRay    = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    var mousePivot  = mouseRay.origin + mouseRay.direction * view.cameraDistance;
                    var pivotVector = mousePivot - view.pivot;

                    view.pivot += pivotVector * percentage;
                }
            }

            Event.current.Use();
        }
Esempio n. 6
0
        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 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;
            }
        }
        void ShowClosestPointOnOpenSpline(SerializedProperty points)
        {
            var   spline = target as SplineComponent;
            var   plane  = new Plane(spline.transform.up, spline.transform.position);
            var   ray    = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            float center;

            if (plane.Raycast(ray, out center))
            {
                var hit      = ray.origin + ray.direction * center;
                var discSize = HandleUtility.GetHandleSize(hit);
                Handles.DrawWireDisc(hit, spline.transform.up, discSize);
                var p = SearchForClosestPoint(Event.current.mousePosition);


                if ((hit - spline.GetNonUniformPoint(0)).sqrMagnitude < 25)
                {
                    p = 0;
                }
                if ((hit - spline.GetNonUniformPoint(1)).sqrMagnitude < 25)
                {
                    p = 1;
                }


                var sp = spline.GetNonUniformPoint(p);


                var extend = Mathf.Approximately(p, 0) || Mathf.Approximately(p, 1);


                Handles.color = extend ? Color.red : Color.white;
                Handles.DrawLine(hit, sp);
                Handles.color = Color.white;


                var i = 1 + Mathf.FloorToInt(p * (spline.points.Count - 3));


                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.shift)
                {
                    if (extend)
                    {
                        if (i == spline.points.Count - 2)
                        {
                            i++;
                        }
                        points.InsertArrayElementAtIndex(i);
                        points.GetArrayElementAtIndex(i).vector3Value = spline.transform.InverseTransformPoint(hit);
                        hotIndex = i;
                    }
                    else
                    {
                        i++;
                        points.InsertArrayElementAtIndex(i);
                        points.GetArrayElementAtIndex(i).vector3Value = spline.transform.InverseTransformPoint(sp);
                        hotIndex = i;
                    }
                    serializedObject.ApplyModifiedProperties();
                }
            }
        }
        public void OnSceneGUI()
        {
            if ((UnityEngine.Object) this.m_ActiveCollider == (UnityEngine.Object)null || Tools.viewToolActive)
            {
                return;
            }
            Vector2 offset  = this.m_ActiveCollider.offset;
            Event   current = Event.current;

            this.m_DeleteMode = current.command || current.control;
            Transform transform = this.m_ActiveCollider.transform;

            GUIUtility.keyboardControl         = 0;
            HandleUtility.s_CustomPickDistance = 50f;
            Plane plane    = new Plane(-transform.forward, Vector3.zero);
            Ray   worldRay = HandleUtility.GUIPointToWorldRay(current.mousePosition);
            float enter;

            plane.Raycast(worldRay, out enter);
            Vector3 point1    = worldRay.GetPoint(enter);
            Vector2 vector2_1 = (Vector2)transform.InverseTransformPoint(point1);

            if (current.type == EventType.MouseMove || this.m_FirstOnSceneGUIAfterReset)
            {
                int   pathIndex;
                int   num;
                float distance;
                if (PolygonEditor.GetNearestPoint(vector2_1 - offset, out pathIndex, out num, out distance))
                {
                    this.m_SelectedPath     = pathIndex;
                    this.m_SelectedVertex   = num;
                    this.m_SelectedDistance = distance;
                }
                else
                {
                    this.m_SelectedPath = -1;
                }
                int pointIndex1;
                if (PolygonEditor.GetNearestEdge(vector2_1 - offset, out pathIndex, out num, out pointIndex1, out distance, this.m_LoopingCollider))
                {
                    this.m_SelectedEdgePath     = pathIndex;
                    this.m_SelectedEdgeVertex0  = num;
                    this.m_SelectedEdgeVertex1  = pointIndex1;
                    this.m_SelectedEdgeDistance = distance;
                }
                else
                {
                    this.m_SelectedEdgePath = -1;
                }
                if (current.type == EventType.MouseMove)
                {
                    current.Use();
                }
            }
            else if (current.type == EventType.MouseUp)
            {
                this.m_LeftIntersect  = false;
                this.m_RightIntersect = false;
            }
            bool flag1 = false;
            bool flag2 = false;

            if (this.m_SelectedPath != -1 && this.m_SelectedEdgePath != -1)
            {
                Vector2 point2;
                PolygonEditor.GetPoint(this.m_SelectedPath, this.m_SelectedVertex, out point2);
                point2 += offset;
                flag2   = (double)this.m_SelectedEdgeDistance < (double)this.m_SelectedDistance - (double)(HandleUtility.GetHandleSize(transform.TransformPoint((Vector3)point2)) * 0.2f);
                flag1   = !flag2;
            }
            else if (this.m_SelectedPath != -1)
            {
                flag1 = true;
            }
            else if (this.m_SelectedEdgePath != -1)
            {
                flag2 = true;
            }
            if (this.m_DeleteMode && flag2)
            {
                flag2 = false;
                flag1 = true;
            }
            bool flag3 = false;

            if (flag2 && !this.m_DeleteMode)
            {
                Vector2 point2;
                PolygonEditor.GetPoint(this.m_SelectedEdgePath, this.m_SelectedEdgeVertex0, out point2);
                Vector2 point3;
                PolygonEditor.GetPoint(this.m_SelectedEdgePath, this.m_SelectedEdgeVertex1, out point3);
                point2 += offset;
                Vector2 vector2_2 = point3 + offset;
                Vector3 vector3_1 = transform.TransformPoint((Vector3)point2);
                Vector3 vector3_2 = transform.TransformPoint((Vector3)vector2_2);
                vector3_1.z   = vector3_2.z = 0.0f;
                Handles.color = Color.green;
                Handles.DrawAAPolyLine(4f, new Vector3[2]
                {
                    vector3_1,
                    vector3_2
                });
                Handles.color = Color.white;
                Vector2 nearestPointOnEdge = this.GetNearestPointOnEdge((Vector2)transform.TransformPoint((Vector3)vector2_1), (Vector2)vector3_1, (Vector2)vector3_2);
                EditorGUI.BeginChangeCheck();
                float handleSize = HandleUtility.GetHandleSize((Vector3)nearestPointOnEdge) * 0.04f;
                Handles.color = Color.green;
                Vector2 vector2_3 = (Vector2)Handles.Slider2D((Vector3)nearestPointOnEdge, new Vector3(0.0f, 0.0f, 1f), new Vector3(1f, 0.0f, 0.0f), new Vector3(0.0f, 1f, 0.0f), handleSize, new Handles.DrawCapFunction(Handles.DotCap), (Vector2)Vector3.zero);
                Handles.color = Color.white;
                if (EditorGUI.EndChangeCheck())
                {
                    PolygonEditor.InsertPoint(this.m_SelectedEdgePath, this.m_SelectedEdgeVertex1, (point2 + vector2_2) / 2f - offset);
                    this.m_SelectedPath     = this.m_SelectedEdgePath;
                    this.m_SelectedVertex   = this.m_SelectedEdgeVertex1;
                    this.m_SelectedDistance = 0.0f;
                    flag1 = true;
                    flag3 = true;
                }
            }
            if (flag1)
            {
                Vector2 point2;
                PolygonEditor.GetPoint(this.m_SelectedPath, this.m_SelectedVertex, out point2);
                point2 += offset;
                Vector3 vector3_1 = transform.TransformPoint((Vector3)point2);
                vector3_1.z = 0.0f;
                Vector2 guiPoint   = HandleUtility.WorldToGUIPoint(vector3_1);
                float   handleSize = HandleUtility.GetHandleSize(vector3_1) * 0.04f;
                if (this.m_DeleteMode && current.type == EventType.MouseDown && (double)Vector2.Distance(guiPoint, Event.current.mousePosition) < 50.0 || this.DeleteCommandEvent(current))
                {
                    if (current.type != EventType.ValidateCommand && PolygonEditor.GetPointCount(this.m_SelectedPath) > this.m_MinPathPoints)
                    {
                        PolygonEditor.RemovePoint(this.m_SelectedPath, this.m_SelectedVertex);
                        this.Reset();
                        flag3 = true;
                    }
                    current.Use();
                }
                EditorGUI.BeginChangeCheck();
                Handles.color = !this.m_DeleteMode ? Color.green : Color.red;
                Vector3 vector3_2 = Handles.Slider2D(vector3_1, new Vector3(0.0f, 0.0f, 1f), new Vector3(1f, 0.0f, 0.0f), new Vector3(0.0f, 1f, 0.0f), handleSize, new Handles.DrawCapFunction(Handles.DotCap), (Vector2)Vector3.zero);
                Handles.color = Color.white;
                if (EditorGUI.EndChangeCheck() && !this.m_DeleteMode)
                {
                    point2  = (Vector2)transform.InverseTransformPoint(vector3_2);
                    point2 -= offset;
                    PolygonEditor.TestPointMove(this.m_SelectedPath, this.m_SelectedVertex, point2, out this.m_LeftIntersect, out this.m_RightIntersect, this.m_LoopingCollider);
                    PolygonEditor.SetPoint(this.m_SelectedPath, this.m_SelectedVertex, point2);
                    flag3 = true;
                }
                if (!flag3)
                {
                    this.DrawEdgesForSelectedPoint(vector3_2, transform, this.m_LeftIntersect, this.m_RightIntersect, this.m_LoopingCollider);
                }
            }
            if (flag3)
            {
                Undo.RecordObject((UnityEngine.Object) this.m_ActiveCollider, "Edit Collider");
                PolygonEditor.ApplyEditing(this.m_ActiveCollider);
            }
            if (this.DeleteCommandEvent(current))
            {
                Event.current.Use();
            }
            this.m_FirstOnSceneGUIAfterReset = false;
        }
Esempio n. 10
0
        public void OnSceneGUI()
        {
            if (this.m_ActiveCollider == null)
            {
                return;
            }
            Vector2 offset  = this.m_ActiveCollider.offset;
            Event   current = Event.current;

            this.m_DeleteMode = (current.command || current.control);
            Transform transform = this.m_ActiveCollider.transform;

            GUIUtility.keyboardControl         = 0;
            HandleUtility.s_CustomPickDistance = 50f;
            Plane plane = new Plane(-transform.forward, Vector3.zero);
            Ray   ray   = HandleUtility.GUIPointToWorldRay(current.mousePosition);
            float distance;

            plane.Raycast(ray, out distance);
            Vector3 point  = ray.GetPoint(distance);
            Vector2 vector = transform.InverseTransformPoint(point);

            if (current.type == EventType.MouseMove || this.m_FirstOnSceneGUIAfterReset)
            {
                int   num;
                int   num2;
                float num3;
                if (PolygonEditor.GetNearestPoint(vector - offset, out num, out num2, out num3))
                {
                    this.m_SelectedPath     = num;
                    this.m_SelectedVertex   = num2;
                    this.m_SelectedDistance = num3;
                }
                else
                {
                    this.m_SelectedPath = -1;
                }
                int selectedEdgeVertex;
                if (PolygonEditor.GetNearestEdge(vector - offset, out num, out num2, out selectedEdgeVertex, out num3, this.m_LoopingCollider))
                {
                    this.m_SelectedEdgePath     = num;
                    this.m_SelectedEdgeVertex0  = num2;
                    this.m_SelectedEdgeVertex1  = selectedEdgeVertex;
                    this.m_SelectedEdgeDistance = num3;
                }
                else
                {
                    this.m_SelectedEdgePath = -1;
                }
                current.Use();
            }
            else
            {
                if (current.type == EventType.MouseUp)
                {
                    this.m_LeftIntersect  = false;
                    this.m_RightIntersect = false;
                }
            }
            bool flag  = false;
            bool flag2 = false;

            if (this.m_SelectedPath != -1 && this.m_SelectedEdgePath != -1)
            {
                Vector2 vector2;
                PolygonEditor.GetPoint(this.m_SelectedPath, this.m_SelectedVertex, out vector2);
                vector2 += offset;
                Vector3 position = transform.TransformPoint(vector2);
                float   num4     = HandleUtility.GetHandleSize(position) * 0.2f;
                flag2 = (this.m_SelectedEdgeDistance < this.m_SelectedDistance - num4);
                flag  = !flag2;
            }
            else
            {
                if (this.m_SelectedPath != -1)
                {
                    flag = true;
                }
                else
                {
                    if (this.m_SelectedEdgePath != -1)
                    {
                        flag2 = true;
                    }
                }
            }
            if (this.m_DeleteMode && flag2)
            {
                flag2 = false;
                flag  = true;
            }
            bool flag3 = false;

            if (flag2 && !this.m_DeleteMode)
            {
                Vector2 vector3;
                PolygonEditor.GetPoint(this.m_SelectedEdgePath, this.m_SelectedEdgeVertex0, out vector3);
                Vector2 vector4;
                PolygonEditor.GetPoint(this.m_SelectedEdgePath, this.m_SelectedEdgeVertex1, out vector4);
                vector3 += offset;
                vector4 += offset;
                Vector3 vector5 = transform.TransformPoint(vector3);
                Vector3 vector6 = transform.TransformPoint(vector4);
                vector5.z     = (vector6.z = 0f);
                Handles.color = Color.green;
                Handles.DrawAAPolyLine(4f, new Vector3[]
                {
                    vector5,
                    vector6
                });
                Handles.color = Color.white;
                Vector2 v = this.GetNearestPointOnEdge(transform.TransformPoint(vector), vector5, vector6);
                EditorGUI.BeginChangeCheck();
                float handleSize = HandleUtility.GetHandleSize(v) * 0.04f;
                Handles.color = Color.green;
                v             = Handles.Slider2D(v, new Vector3(0f, 0f, 1f), new Vector3(1f, 0f, 0f), new Vector3(0f, 1f, 0f), handleSize, new Handles.DrawCapFunction(Handles.DotCap), Vector3.zero);
                Handles.color = Color.white;
                if (EditorGUI.EndChangeCheck())
                {
                    PolygonEditor.InsertPoint(this.m_SelectedEdgePath, this.m_SelectedEdgeVertex1, (vector3 + vector4) / 2f - offset);
                    this.m_SelectedPath     = this.m_SelectedEdgePath;
                    this.m_SelectedVertex   = this.m_SelectedEdgeVertex1;
                    this.m_SelectedDistance = 0f;
                    flag  = true;
                    flag3 = true;
                }
            }
            if (flag)
            {
                Vector2 vector7;
                PolygonEditor.GetPoint(this.m_SelectedPath, this.m_SelectedVertex, out vector7);
                vector7 += offset;
                Vector3 vector8 = transform.TransformPoint(vector7);
                vector8.z = 0f;
                Vector2 a           = HandleUtility.WorldToGUIPoint(vector8);
                float   handleSize2 = HandleUtility.GetHandleSize(vector8) * 0.04f;
                if ((this.m_DeleteMode && current.type == EventType.MouseDown && Vector2.Distance(a, Event.current.mousePosition) < 50f) || this.DeleteCommandEvent(current))
                {
                    if (current.type != EventType.ValidateCommand)
                    {
                        int pointCount = PolygonEditor.GetPointCount(this.m_SelectedPath);
                        if (pointCount > this.m_MinPathPoints)
                        {
                            PolygonEditor.RemovePoint(this.m_SelectedPath, this.m_SelectedVertex);
                            this.Reset();
                            flag3 = true;
                        }
                    }
                    current.Use();
                }
                EditorGUI.BeginChangeCheck();
                Handles.color = ((!this.m_DeleteMode) ? Color.green : Color.red);
                Vector3 vector9 = Handles.Slider2D(vector8, new Vector3(0f, 0f, 1f), new Vector3(1f, 0f, 0f), new Vector3(0f, 1f, 0f), handleSize2, new Handles.DrawCapFunction(Handles.DotCap), Vector3.zero);
                Handles.color = Color.white;
                if (EditorGUI.EndChangeCheck() && !this.m_DeleteMode)
                {
                    vector7  = transform.InverseTransformPoint(vector9);
                    vector7 -= offset;
                    PolygonEditor.TestPointMove(this.m_SelectedPath, this.m_SelectedVertex, vector7, out this.m_LeftIntersect, out this.m_RightIntersect, this.m_LoopingCollider);
                    PolygonEditor.SetPoint(this.m_SelectedPath, this.m_SelectedVertex, vector7);
                    flag3 = true;
                }
                if (!flag3)
                {
                    this.DrawEdgesForSelectedPoint(vector9, transform, this.m_LeftIntersect, this.m_RightIntersect, this.m_LoopingCollider);
                }
            }
            if (flag3)
            {
                Undo.RecordObject(this.m_ActiveCollider, "Edit Collider");
                PolygonEditor.ApplyEditing(this.m_ActiveCollider);
            }
            if (this.DeleteCommandEvent(current))
            {
                Event.current.Use();
            }
            this.m_FirstOnSceneGUIAfterReset = false;
        }
Esempio n. 11
0
 public void OnSceneGUI()
 {
     if ((this.m_ActiveCollider != null) && !Tools.viewToolActive)
     {
         float   num;
         Vector2 offset  = this.m_ActiveCollider.offset;
         Event   current = Event.current;
         this.m_DeleteMode = current.command || current.control;
         Transform transform = this.m_ActiveCollider.transform;
         GUIUtility.keyboardControl         = 0;
         HandleUtility.s_CustomPickDistance = 50f;
         Plane plane = new Plane(-transform.forward, Vector3.zero);
         Ray   ray   = HandleUtility.GUIPointToWorldRay(current.mousePosition);
         plane.Raycast(ray, out num);
         Vector3 point   = ray.GetPoint(num);
         Vector2 vector3 = transform.InverseTransformPoint(point);
         if ((current.type == EventType.MouseMove) || this.m_FirstOnSceneGUIAfterReset)
         {
             int   num2;
             int   num3;
             int   num4;
             float num5;
             if (PolygonEditor.GetNearestPoint(vector3 - offset, out num2, out num3, out num5))
             {
                 this.m_SelectedPath     = num2;
                 this.m_SelectedVertex   = num3;
                 this.m_SelectedDistance = num5;
             }
             else
             {
                 this.m_SelectedPath = -1;
             }
             if (PolygonEditor.GetNearestEdge(vector3 - offset, out num2, out num3, out num4, out num5, this.m_LoopingCollider))
             {
                 this.m_SelectedEdgePath     = num2;
                 this.m_SelectedEdgeVertex0  = num3;
                 this.m_SelectedEdgeVertex1  = num4;
                 this.m_SelectedEdgeDistance = num5;
             }
             else
             {
                 this.m_SelectedEdgePath = -1;
             }
             if (current.type == EventType.MouseMove)
             {
                 current.Use();
             }
         }
         else if (current.type == EventType.MouseUp)
         {
             this.m_LeftIntersect  = false;
             this.m_RightIntersect = false;
         }
         bool flag  = false;
         bool flag2 = false;
         if ((this.m_SelectedPath != -1) && (this.m_SelectedEdgePath != -1))
         {
             Vector2 vector4;
             PolygonEditor.GetPoint(this.m_SelectedPath, this.m_SelectedVertex, out vector4);
             vector4 += offset;
             float num6 = HandleUtility.GetHandleSize(transform.TransformPoint((Vector3)vector4)) * 0.2f;
             flag2 = this.m_SelectedEdgeDistance < (this.m_SelectedDistance - num6);
             flag  = !flag2;
         }
         else if (this.m_SelectedPath != -1)
         {
             flag = true;
         }
         else if (this.m_SelectedEdgePath != -1)
         {
             flag2 = true;
         }
         if (this.m_DeleteMode && flag2)
         {
             flag2 = false;
             flag  = true;
         }
         bool flag3 = false;
         if (flag2 && !this.m_DeleteMode)
         {
             Vector2 vector6;
             Vector2 vector7;
             PolygonEditor.GetPoint(this.m_SelectedEdgePath, this.m_SelectedEdgeVertex0, out vector6);
             PolygonEditor.GetPoint(this.m_SelectedEdgePath, this.m_SelectedEdgeVertex1, out vector7);
             vector6 += offset;
             vector7 += offset;
             Vector3 start = transform.TransformPoint((Vector3)vector6);
             Vector3 end   = transform.TransformPoint((Vector3)vector7);
             start.z       = end.z = 0f;
             Handles.color = Color.green;
             Vector3[] points = new Vector3[] { start, end };
             Handles.DrawAAPolyLine((float)4f, points);
             Handles.color = Color.white;
             Vector2 vector10 = this.GetNearestPointOnEdge(transform.TransformPoint((Vector3)vector3), start, end);
             EditorGUI.BeginChangeCheck();
             float handleSize = HandleUtility.GetHandleSize((Vector3)vector10) * 0.04f;
             Handles.color = Color.green;
             if (< > f__mg$cache0 == null)
             {
Esempio n. 12
0
        public static void OnSceneDrag(SceneView sceneView)
        {
            Event current1 = Event.current;

            if (current1.type != EventType.DragUpdated && current1.type != EventType.DragPerform && current1.type != EventType.DragExited)
            {
                return;
            }
            if (!sceneView.in2DMode)
            {
                GameObject gameObject = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null && DragAndDrop.objectReferences.Length == 1 && ((UnityEngine.Object)(DragAndDrop.objectReferences[0] as Texture) != (UnityEngine.Object)null && (UnityEngine.Object)gameObject.GetComponent <Renderer>() != (UnityEngine.Object)null))
                {
                    return;
                }
            }
            switch (current1.type)
            {
            case EventType.DragUpdated:
                SpriteUtility.DragType dragType = !current1.alt ? SpriteUtility.DragType.SpriteAnimation : SpriteUtility.DragType.CreateMultiple;
                if (SpriteUtility.s_DragType != dragType || SpriteUtility.s_SceneDragObjects == null)
                {
                    Sprite[] draggedPathsOrObjects = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                    if (draggedPathsOrObjects == null || draggedPathsOrObjects.Length == 0 || (UnityEngine.Object)draggedPathsOrObjects[0] == (UnityEngine.Object)null)
                    {
                        break;
                    }
                    if (SpriteUtility.s_DragType != SpriteUtility.DragType.NotInitialized)
                    {
                        SpriteUtility.CleanUp();
                    }
                    SpriteUtility.s_DragType         = dragType;
                    SpriteUtility.s_SceneDragObjects = new List <UnityEngine.Object>();
                    if (SpriteUtility.s_DragType == SpriteUtility.DragType.CreateMultiple)
                    {
                        foreach (Sprite frame in draggedPathsOrObjects)
                        {
                            SpriteUtility.s_SceneDragObjects.Add((UnityEngine.Object)SpriteUtility.CreateDragGO(frame, Vector3.zero));
                        }
                    }
                    else
                    {
                        SpriteUtility.s_SceneDragObjects.Add((UnityEngine.Object)SpriteUtility.CreateDragGO(draggedPathsOrObjects[0], Vector3.zero));
                    }
                    List <Transform> transformList = new List <Transform>();
                    using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            GameObject current2 = (GameObject)enumerator.Current;
                            transformList.AddRange((IEnumerable <Transform>)current2.GetComponentsInChildren <Transform>());
                            current2.hideFlags = HideFlags.HideInHierarchy;
                        }
                    }
                    HandleUtility.ignoreRaySnapObjects = transformList.ToArray();
                }
                Vector3 zero  = Vector3.zero;
                Vector3 point = HandleUtility.GUIPointToWorldRay(current1.mousePosition).GetPoint(10f);
                if (sceneView.in2DMode)
                {
                    point.z = 0.0f;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current1.mousePosition));
                    if (obj != null)
                    {
                        point = ((RaycastHit)obj).point;
                    }
                }
                using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ((GameObject)enumerator.Current).transform.position = point;
                    }
                }
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                current1.Use();
                break;

            case EventType.DragPerform:
                Sprite[] draggedPathsOrObjects1 = SpriteUtility.GetSpriteFromDraggedPathsOrObjects();
                if (draggedPathsOrObjects1 == null || SpriteUtility.s_SceneDragObjects == null)
                {
                    break;
                }
                if (SpriteUtility.s_DragType == SpriteUtility.DragType.SpriteAnimation)
                {
                    SpriteUtility.AddAnimationToGO((GameObject)SpriteUtility.s_SceneDragObjects[0], draggedPathsOrObjects1);
                }
                using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        GameObject current2 = (GameObject)enumerator.Current;
                        Undo.RegisterCreatedObjectUndo((UnityEngine.Object)current2, "Create Sprite");
                        current2.hideFlags = HideFlags.None;
                    }
                }
                Selection.objects = SpriteUtility.s_SceneDragObjects.ToArray();
                SpriteUtility.CleanUp();
                current1.Use();
                break;

            case EventType.DragExited:
                if (SpriteUtility.s_SceneDragObjects == null || SpriteUtility.s_SceneDragObjects == null)
                {
                    break;
                }
                using (List <UnityEngine.Object> .Enumerator enumerator = SpriteUtility.s_SceneDragObjects.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        UnityEngine.Object.DestroyImmediate(enumerator.Current, false);
                    }
                }
                SpriteUtility.CleanUp();
                current1.Use();
                break;
            }
        }
Esempio n. 13
0
        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)
                {
                    if (!EditorApplication.isPlaying || EditorSceneManager.IsPreviewScene(destinationScene))
                    {
                        dragObject      = (GameObject)PrefabUtility.InstantiatePrefab(prefabAssetRoot, destinationScene);
                        dragObject.name = go.name;
                    }
                    else
                    {
                        // Instatiate as regular GameObject in Play Mode so runtime logic
                        // won't run into restrictions on restructuring Prefab instances.
                        dragObject = Instantiate(prefabAssetRoot);
                        SceneManager.MoveGameObjectToScene(dragObject, destinationScene);
                    }
                    dragObject.hideFlags = HideFlags.HideInHierarchy;
                }

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

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                Vector3 point, normal;

                if (HandleUtility.PlaceObject(evt.mousePosition, out point, out normal))
                {
                    float offset = 0;
                    if (Tools.pivotMode == PivotMode.Center)
                    {
                        float geomOffset = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, normal);
                        if (geomOffset != Mathf.Infinity)
                        {
                            offset = Vector3.Dot(dragObject.transform.position, normal) - geomOffset;
                        }
                    }
                    dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(point + (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:
                if (!DragPerform(sceneView, dragObject, go))
                {
                    return;
                }
                dragObject = null;
                evt.Use();
                break;

            case EventType.DragExited:
                if (dragObject)
                {
                    UnityObject.DestroyImmediate(dragObject, false);
                    HandleUtility.ignoreRaySnapObjects = null;
                    dragObject = null;
                    evt.Use();
                }
                break;
            }
        }
Esempio n. 14
0
        public void OnSceneDrag(SceneView sceneView)
        {
            GameObject target = this.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();
                        return;
                    }
                    if ((type == EventType.DragExited) && (dragObject != null))
                    {
                        UnityEngine.Object.DestroyImmediate(dragObject, false);
                        HandleUtility.ignoreRaySnapObjects = null;
                        dragObject = null;
                        current.Use();
                    }
                }
                else
                {
                    if (dragObject == null)
                    {
                        dragObject = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.FindPrefabRoot(target));
                        HandleUtility.ignoreRaySnapObjects = dragObject.GetComponentsInChildren <Transform>();
                        dragObject.hideFlags = HideFlags.HideInHierarchy;
                        dragObject.name      = target.name;
                    }
                    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 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;
                }
            }
        }
Esempio n. 16
0
        public static void PickAllNonAlloc(List <ProbeHit> hits, ProbeFilter filter, SceneView sceneView, Vector2 guiPosition, int limit = DefaultLimit)
        {
            var screenPosition = HandleUtility.GUIPointToScreenPixelCoordinate(guiPosition);
            var ray3D          = HandleUtility.GUIPointToWorldRay(guiPosition);
            var worldPosition  = sceneView.camera.ScreenToWorldPoint(screenPosition);
            var layerMask      = PeekPlugin.Configuration.probeLayerMask;

            var raycastHits = ArrayPool <RaycastHit> .New(limit);

            var overlapHits = ArrayPool <Collider2D> .New(limit);

            var handleHits = HashSetPool <GameObject> .New();

            var ancestorHits = HashSetPool <ProbeHit> .New();

#if PROBUILDER_4_OR_NEWER
            var proBuilderHits = ListPool <ProbeHit> .New();
#endif

            var gameObjectHits = DictionaryPool <GameObject, ProbeHit> .New();

            try
            {
                // Raycast (3D)
                if (filter.raycast)
                {
                    var raycastHitCount = Physics.RaycastNonAlloc(ray3D, raycastHits, Mathf.Infinity, layerMask);

                    for (var i = 0; i < raycastHitCount; i++)
                    {
                        var raycastHit = raycastHits[i];

#if UNITY_2019_2_OR_NEWER
                        if (SceneVisibilityManager.instance.IsHidden(raycastHit.transform.gameObject))
                        {
                            continue;
                        }
#endif

                        var gameObject = raycastHit.transform.gameObject;

                        if (!gameObjectHits.TryGetValue(gameObject, out var hit))
                        {
                            hit = new ProbeHit(gameObject);
                        }

                        hit.point    = raycastHit.point;
                        hit.distance = raycastHit.distance;

                        gameObjectHits[gameObject] = hit;
                    }
                }

                // Overlap (2D)
                if (filter.overlap)
                {
                    var overlapHitCount = Physics2D.OverlapPointNonAlloc(worldPosition, overlapHits, layerMask);

                    for (var i = 0; i < overlapHitCount; i++)
                    {
                        var overlapHit = overlapHits[i];

#if UNITY_2019_2_OR_NEWER
                        if (SceneVisibilityManager.instance.IsHidden(overlapHit.transform.gameObject))
                        {
                            continue;
                        }
#endif

                        var gameObject = overlapHit.transform.gameObject;

                        if (!gameObjectHits.TryGetValue(gameObject, out var hit))
                        {
                            hit = new ProbeHit(gameObject);
                        }

                        hit.distance = hit.distance ?? Vector3.Distance(overlapHit.transform.position, worldPosition);

                        gameObjectHits[gameObject] = hit;
                    }
                }

                // Handles (Editor Default)
                if (filter.handles && canPickHandles)
                {
                    PickAllHandlesNonAlloc(handleHits, guiPosition, limit);

                    foreach (var handleHit in handleHits)
                    {
                        var gameObject = handleHit;

                        if (!gameObjectHits.TryGetValue(gameObject, out var hit))
                        {
                            hit = new ProbeHit(gameObject);
                        }

                        hit.distance = hit.distance ?? Vector3.Distance(handleHit.transform.position, worldPosition);

                        gameObjectHits[gameObject] = hit;
                    }
                }

                // Ancestors
                foreach (var gameObjectHit in gameObjectHits)
                {
                    var gameObject = gameObjectHit.Key;
                    var hit        = gameObjectHit.Value;

                    var parent = gameObject.transform.parent;

                    int depth = 0;

                    while (parent != null)
                    {
                        var parentGameObject = parent.gameObject;

                        var parentHit = new ProbeHit(parentGameObject);
                        parentHit.groupGameObject = gameObject;
                        parentHit.distance        = hit.distance ?? Vector3.Distance(parentHit.transform.position, worldPosition);
                        parentHit.groupOrder      = 1000 + depth;

                        ancestorHits.Add(parentHit);

                        parent = parent.parent;
                        depth++;
                    }
                }

#if PROBUILDER_4_OR_NEWER
                // ProBuilder
                if (filter.proBuilder && ProBuilderEditor.instance != null)
                {
                    var proBuilderMeshes = ListPool <ProBuilderMesh> .New();

                    try
                    {
                        foreach (var gameObjectHit in gameObjectHits.Values)
                        {
                            var proBuilderMesh = gameObjectHit.gameObject.GetComponent <ProBuilderMesh>();

                            if (proBuilderMesh != null)
                            {
                                proBuilderMeshes.Add(proBuilderMesh);
                            }
                        }

                        PickProBuilderElementsNonAlloc(proBuilderHits, proBuilderMeshes, sceneView, guiPosition);
                    }
                    finally
                    {
                        proBuilderMeshes.Free();
                    }
                }
#endif

                // Prepare final hits
                hits.Clear();

                // Add hits
                foreach (var gameObjectHit in gameObjectHits.Values)
                {
                    hits.Add(gameObjectHit);
                }

                foreach (var ancestorHit in ancestorHits)
                {
                    hits.Add(ancestorHit);
                }

#if PROBUILDER_4_OR_NEWER
                foreach (var proBuilderHit in proBuilderHits)
                {
                    hits.Add(proBuilderHit);
                }
#endif

                // Sort by distance
                hits.Sort(compareHits);
            }
            finally
            {
                raycastHits.Free();
                overlapHits.Free();
                handleHits.Free();
                ancestorHits.Free();

#if PROBUILDER_4_OR_NEWER
                proBuilderHits.Free();
#endif

                gameObjectHits.Free();
            }
        }
        internal void OnSceneDragInternal(SceneView sceneView, int index, EventType type, Vector2 mousePosition, bool alt)
        {
            GameObject go = target as GameObject;

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

            var prefabAssetRoot = go.transform.root.gameObject;

            switch (type)
            {
            case EventType.DragUpdated:
                Scene destinationScene = sceneView.customScene.IsValid() ? sceneView.customScene : SceneManager.GetActiveScene();
                if (m_DragObject == null)
                {
                    // While dragging the instantiated prefab we do not want to record undo for this object
                    // this will cause a remerge of the instance since changes are undone while dragging.
                    // The DrivenRectTransformTracker by default records Undo when used when driving
                    // UI components. This breaks our hideflag setup below due to a remerge of the dragged instance.
                    // StartRecordingUndo() is called on DragExited. Fixes case 1223793.
                    DrivenRectTransformTracker.StopRecordingUndo();

                    if (!EditorApplication.isPlaying || EditorSceneManager.IsPreviewScene(destinationScene))
                    {
                        m_DragObject      = (GameObject)PrefabUtility.InstantiatePrefab(prefabAssetRoot, destinationScene);
                        m_DragObject.name = go.name;
                    }
                    else
                    {
                        // Instatiate as regular GameObject in Play Mode so runtime logic
                        // won't run into restrictions on restructuring Prefab instances.
                        m_DragObject = Instantiate(prefabAssetRoot);
                        SceneManager.MoveGameObjectToScene(m_DragObject, destinationScene);
                    }
                    m_DragObject.hideFlags = HideFlags.HideInHierarchy;

                    if (HandleUtility.ignoreRaySnapObjects == null)
                    {
                        HandleUtility.ignoreRaySnapObjects = m_DragObject.GetComponentsInChildren <Transform>();
                    }
                    else
                    {
                        HandleUtility.ignoreRaySnapObjects = HandleUtility.ignoreRaySnapObjects.Union(m_DragObject.GetComponentsInChildren <Transform>()).ToArray();
                    }

                    PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
                    if (prefabStage != null)
                    {
                        GameObject prefab = AssetDatabase.LoadMainAssetAtPath(prefabStage.assetPath) as GameObject;

                        if (prefab != null)
                        {
                            if (PrefabUtility.CheckIfAddingPrefabWouldResultInCyclicNesting(prefab, target))
                            {
                                s_CyclicNestingDetected = true;
                            }
                        }
                    }
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                Vector3 point, normal;
                float   offset = 0;

                if (index == 0)
                {
                    s_PlaceObject = HandleUtility.PlaceObject(mousePosition, out s_PlaceObjectPoint, out s_PlaceObjectNormal);
                }

                point  = s_PlaceObjectPoint;
                normal = s_PlaceObjectNormal;

                if (s_PlaceObject)
                {
                    if (Tools.pivotMode == PivotMode.Center)
                    {
                        float geomOffset = HandleUtility.CalcRayPlaceOffset(m_DragObject.GetComponentsInChildren <Transform>(), normal);
                        if (geomOffset != Mathf.Infinity)
                        {
                            offset = Vector3.Dot(m_DragObject.transform.position, normal) - geomOffset;
                        }
                    }
                    m_DragObject.transform.position = Matrix4x4.identity.MultiplyPoint(point + (normal * offset));
                }
                else
                {
                    m_DragObject.transform.position = HandleUtility.GUIPointToWorldRay(mousePosition).GetPoint(10);
                }

                if (alt)
                {
                    if (offset != 0)
                    {
                        m_DragObject.transform.position = point;
                    }
                    m_DragObject.transform.position += prefabAssetRoot.transform.localPosition;
                }

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

                // Schedule selection clearing for when we start performing the actual drag action
                s_ShouldClearSelection = true;
                break;

            case EventType.DragPerform:
                DragPerform(sceneView, m_DragObject, go);
                m_DragObject = null;
                break;

            case EventType.DragExited:
                // DragExited is always fired after DragPerform so we do no need to call StartRecordingUndo
                // in DragPerform
                DrivenRectTransformTracker.StartRecordingUndo();

                if (m_DragObject)
                {
                    DestroyImmediate(m_DragObject, false);
                    HandleUtility.ignoreRaySnapObjects = null;
                    m_DragObject = null;
                }
                s_ShouldClearSelection  = false;
                s_CyclicNestingDetected = false;
                break;
            }
        }