Ejemplo n.º 1
0
        public static void SetCursor(int id, Vector3 from, Vector3 to)
        {
            if (UnityEditor.HandleUtility.nearestControl != id &&
                EditorGUIUtility.hotControl != id)
            {
                return;
            }

            SetArrowCursor(SceneHandleUtility.GetCursorForEdge(from, to));
        }
        public static Vector3 Edge2DHandleOffset(int id, Vector3 from, Vector3 to, Vector3 position, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, CapFunction capFunction, Axes axes = Axes.None, Vector3?snappingSteps = null)
        {
            var evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            {
                if (Tools.current == Tool.View ||
                    Tools.current == Tool.None ||
                    evt.alt)
                {
                    break;
                }
                UnityEditor.HandleUtility.AddControl(id, UnityEditor.HandleUtility.DistanceToLine(from, to) * 0.5f);
                break;
            }

            case EventType.Repaint:
            {
                var sceneView = SceneView.currentDrawingSceneView;
                if (sceneView &&
                    Tools.current != Tool.View &&
                    Tools.current != Tool.None &&
                    !evt.alt)
                {
                    if (UnityEditor.HandleUtility.nearestControl == id || EditorGUIUtility.hotControl == id)
                    {
                        var rect = sceneView.position;
                        rect.min = Vector2.zero;
                        EditorGUIUtility.AddCursorRect(rect, SceneHandleUtility.GetCursorForEdge(from, to));
                    }
                }
                if (EditorGUIUtility.keyboardControl == id)
                {
                    SceneHandles.DrawAAPolyLine(3.0f, from, to);
                }
                else
                {
                    SceneHandles.DrawAAPolyLine(2.5f, from, to);
                }
                break;
            }
            }


            var points = new Vector3[] { from, to };
            var result = Slider2D.Do(id, points, position, Vector3.zero, handleDir, slideDir1, slideDir2, handleSize, capFunction, axes, snappingSteps: snappingSteps);

            return(result[0] - from);
        }
        public static Vector3 Edge1DHandleOffset(int id, Axis axis, Vector3 from, Vector3 to, Vector3 position, Vector3 direction, float snappingStep, float handleSize, CapFunction capFunction)
        {
            var evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            {
                if (Tools.current == Tool.View ||
                    Tools.current == Tool.None ||
                    evt.alt)
                {
                    break;
                }
                UnityEditor.HandleUtility.AddControl(id, UnityEditor.HandleUtility.DistanceToLine(from, to));
                break;
            }

            case EventType.Repaint:
            {
                var sceneView = SceneView.currentDrawingSceneView;
                if (sceneView &&
                    Tools.current != Tool.View &&
                    Tools.current != Tool.None &&
                    !evt.alt)
                {
                    var rect = sceneView.position;
                    rect.min = Vector2.zero;
                    var hovering = UnityEditor.HandleUtility.nearestControl == id &&
                                   UnityEditor.HandleUtility.DistanceToLine(from, to) < 10;      // in case multiple edges share the same id, we want to ignore those that aren't even close
                    if (EditorGUIUtility.hotControl == id || hovering)
                    {
                        EditorGUIUtility.AddCursorRect(rect, SceneHandleUtility.GetCursorForEdge(from, to));
                    }
                }

                SceneHandles.DrawAAPolyLine(3.0f, from, to);
                break;
            }
            }


            var points = new Vector3[] { from, to };
            var result = Slider1DHandle(id, axis, points, position, direction, snappingStep, handleSize, capFunction);

            return(result[0] - from);
        }