Exemplo n.º 1
0
        static bool DoFaceSizeHandle(FaceData face, int controlID)
        {
            if (k_OrientationControlIDs.Contains(HandleUtility.nearestControl) && !EditorShapeUtility.PointerIsInFace(face))
            {
                return(false);
            }

            Event evt        = Event.current;
            float handleSize = HandleUtility.GetHandleSize(face.CenterPosition) * s_DefaultMidpointHandleSize;
            bool  isSelected = (HandleUtility.nearestControl == controlID && s_CurrentId == -1) || s_CurrentId == controlID;

            switch (evt.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                if (HandleUtility.nearestControl == controlID && evt.button == 0)
                {
                    s_CurrentId            = controlID;
                    GUIUtility.hotControl  = controlID;
                    s_StartMousePosition   = evt.mousePosition;
                    s_SizeManipulationInit = false;
                    evt.Use();
                    SceneView.RepaintAll();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID && evt.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    s_CurrentId            = -1;
                    s_SizeManipulationInit = false;
                }
                break;

            case EventType.Layout:
                HandleUtility.AddControl(controlID, HandleUtility.DistanceToLine(face.CenterPosition, face.CenterPosition) / 2f);
                break;

            case EventType.Repaint:
                Color color = isSelected ? EditorHandleDrawing.edgeSelectedColor : k_BoundsHandleColor;
                color.a *= face.IsVisible ? 1f : 0.25f;
                using (new Handles.DrawingScope(color))
                    Handles.DotHandleCap(controlID, face.CenterPosition, Quaternion.identity, handleSize, EventType.Repaint);
                break;

            case EventType.MouseDrag:
                if (s_CurrentId == controlID)
                {
                    s_SizeDelta = HandleUtility.CalcLineTranslation(s_StartMousePosition, evt.mousePosition, s_StartPositionLocal, face.Normal);
                    return(true);
                }
                break;
            }
            return(false);
        }
Exemplo n.º 2
0
        void handle_Editor(Vector3 _direction, Color _color, bool _active)
        {
            Vector3 handlePosition = handlePosition_Centor + fHandleSize * _direction * fHandleOffsetSize;

            if (_tile_Scene != null)// && _tile.coordinates.IsLastTile(_direction))
            {
                if (_active)
                {
                    Handles.color = _color;
                    Handles.DrawLine(handlePosition_Centor, handlePosition_Centor + fHandleSize * _direction);
                    EditorGUI.BeginChangeCheck();
                    if (bSingleCtlr)
                    {
                        Handles.FreeMoveHandle(handlePosition,
                                               Quaternion.identity, fHandleSize * 0.15f, Vector3.zero, Handles.RectangleHandleCap);
                    }
                    else
                    {
                        Handles.FreeMoveHandle(handlePosition,
                                               Quaternion.identity, fHandleSize * 0.25f, Vector3.zero, Handles.SphereHandleCap);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        float fDragDistance = HandleUtility.CalcLineTranslation(
                            HandleUtility.WorldToGUIPoint(handlePosition),
                            Event.current.mousePosition, handlePosition, _direction);

                        float fHurdleDistance = Vector3.Scale(_direction,
                                                              _tile_Scene.coordinates.grid.GridInterval).magnitude;

                        _tile_Scene.Bulk.Do_With_SensorOff(() =>
                        {
                            if (fDragDistance >= fHurdleDistance)
                            {
                                handle_Extrude(_direction, selectionType, bSingleCtlr, bWithAttachment);
                            }
                            else if (fDragDistance <= -fHurdleDistance)
                            {
                                handle_Press(-_direction, bSingleCtlr);
                            }
                        });
                        _tile_Scene.Bulk.Update_ChildList();
                    }
                }
                else
                {
                    Handles.color = _color / 1.5f;
                    Handles.FreeMoveHandle(handlePosition,
                                           Quaternion.LookRotation(_direction), fHandleSize * 0.1f, Vector3.one, Handles.DotHandleCap);
                }
            }
        }
Exemplo n.º 3
0
        public static float DoAxis(int id, float scale, Vector3 position, Vector3 direction, Quaternion rotation, float size, float snap)
        {
            Event current = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (((HandleUtility.nearestControl == id) && (current.button == 0)) || ((GUIUtility.keyboardControl == id) && (current.button == 2)))
                {
                    int num3 = id;
                    GUIUtility.keyboardControl = num3;
                    GUIUtility.hotControl      = num3;
                    s_CurrentMousePosition     = s_StartMousePosition = current.mousePosition;
                    s_StartScale = scale;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                return(scale);

            case EventType.MouseUp:
                if ((GUIUtility.hotControl == id) && ((current.button == 0) || (current.button == 2)))
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                return(scale);

            case EventType.MouseMove:
            case EventType.KeyDown:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
                return(scale);

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += current.delta;
                    float val = 1f + (HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, position, direction) / size);
                    val         = Handles.SnapValue(val, snap);
                    scale       = s_StartScale * val;
                    GUI.changed = true;
                    current.Use();
                }
                return(scale);

            case EventType.Repaint:
            {
                Color white = Color.white;
                if (id == GUIUtility.keyboardControl)
                {
                    white         = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                float num2 = size;
                if (GUIUtility.hotControl == id)
                {
                    num2 = (size * scale) / s_StartScale;
                }
                Handles.CubeCap(id, position + ((Vector3)((direction * num2) * s_ScaleDrawLength)), rotation, size * 0.1f);
                Handles.DrawLine(position, position + ((Vector3)(direction * ((num2 * s_ScaleDrawLength) - (size * 0.05f)))));
                if (id == GUIUtility.keyboardControl)
                {
                    Handles.color = white;
                }
                return(scale);
            }

            case EventType.Layout:
                HandleUtility.AddControl(id, HandleUtility.DistanceToLine(position, position + ((Vector3)(direction * size))));
                HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + ((Vector3)(direction * size)), size * 0.2f));
                return(scale);
            }
            return(scale);
        }
Exemplo n.º 4
0
        public static Quaternion Do(Camera camera, int id, string name, Quaternion rotation, Vector3 position, Vector3 axis, float size, bool cutoffPlane, bool snapping, float snap, CSGHandles.InitFunction initFunction, CSGHandles.InitFunction shutdownFunction)
        {
            if (Mathf.Abs(Vector3.Dot(camera.transform.forward, axis)) > .999f)
            {
                cutoffPlane = false;
            }

            var evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            {
                float d;
                if (cutoffPlane)
                {
                    var from = Vector3.Cross(axis, camera.transform.forward).normalized;
                    d = HandleUtility.DistanceToArc(position, axis, from, 180, size) / 2;
                }
                else
                {
                    d = HandleUtility.DistanceToDisc(position, axis, size) / 2;
                }

                HandleUtility.AddControl(id, d);
                break;
            }

            case EventType.MouseDown:
            {
                if (CSGHandles.disabled)
                {
                    break;
                }
                if (((HandleUtility.nearestControl == id && evt.button == 0) ||
                     (GUIUtility.keyboardControl == id && evt.button == 2)) && GUIUtility.hotControl == 0)
                {
                    if (initFunction != null)
                    {
                        initFunction();
                    }
                    GUIUtility.hotControl = GUIUtility.keyboardControl = id;                                // Grab mouse focus
                    //Tools.LockHandlePosition();
                    if (cutoffPlane)
                    {
                        Vector3 from = Vector3.Cross(axis, camera.transform.forward).normalized;
                        s_StartPosition = HandleUtility.ClosestPointToArc(position, axis, from, 180, size);
                    }
                    else
                    {
                        s_StartPosition = HandleUtility.ClosestPointToDisc(position, axis, size);
                    }
                    s_RotationDist         = 0;
                    s_StartRotation        = rotation;
                    s_StartAxis            = axis;
                    s_CurrentMousePosition = s_StartMousePosition = Event.current.mousePosition;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;
            }

            case EventType.MouseDrag:
            {
                if (GUIUtility.hotControl == id)
                {
                    var direction = Vector3.Cross(axis, position - s_StartPosition).normalized;
                    s_CurrentMousePosition += evt.delta;
                    s_RotationDist          = HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, direction) / size * 30;
                    s_RotationDist          = SnapValue(s_RotationDist, snap, snapping);
                    rotation = Quaternion.AngleAxis(s_RotationDist * -1, s_StartAxis) * s_StartRotation;

                    GUI.changed = true;
                    evt.Use();
                }
                break;
            }

            case EventType.MouseUp:
            {
                if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                {
                    //Tools.UnlockHandlePosition();
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    if (shutdownFunction != null)
                    {
                        shutdownFunction();
                    }
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;
            }

            case EventType.KeyDown:
            {
                if (evt.keyCode == KeyCode.Escape && GUIUtility.hotControl == id)
                {
                    // We do not use the event nor clear hotcontrol to ensure auto revert value kicks in from native side
                    //Tools.UnlockHandlePosition();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;
            }

            case EventType.Repaint:
            {
                var originalColor = Handles.color;
                if (id == GUIUtility.keyboardControl)
                {
                    Handles.color = Handles.selectedColor;
                }

                // If we're dragging it, we'll go a bit further and draw a selection pie
                if (GUIUtility.hotControl == id)
                {
                    Vector3 from = Vector3.Cross(axis, Vector3.Cross(axis, (s_StartPosition - position).normalized).normalized);

                    float radius   = size * 1.1f;
                    float endAngle = s_RotationDist;

                    PaintUtility.DrawRotateCircle(camera, position, axis, from, radius, 0, 0, endAngle, Handles.color, name, true);
                    PaintUtility.DrawRotateCirclePie(position, axis, from, radius, 0, 0, endAngle, Handles.color);

                    /*
                     * Color t = Handles.color;
                     * Vector3 from = (s_StartPosition - position).normalized;
                     * Handles.color = Handles.secondaryColor;
                     * Handles.DrawLine(position, position + from * size * 1.1f);
                     * float d = Mathf.Repeat(-s_RotationDist - 180, 360) - 180;
                     * Vector3 to = Quaternion.AngleAxis(d, axis) * from;
                     * Handles.DrawLine(position, position + to * size * 1.1f);
                     *
                     * Handles.color = Handles.secondaryColor * new Color(1, 1, 1, .2f);
                     * Handles.DrawSolidArc(position, axis, from, d, size);
                     * Handles.color = t;
                     */
                }
                else
                if (CSGHandles.disabled)
                {
                    Handles.color = Color.Lerp(originalColor, Handles.secondaryColor, 0.75f);
                }

                if (cutoffPlane)
                {
                    Vector3 from = Vector3.Cross(axis, camera.transform.forward).normalized;
                    Handles.DrawWireArc(position, axis, from, 180, size);
                }
                else
                {
                    Handles.DrawWireDisc(position, axis, size);
                }

                Handles.color = originalColor;
                break;
            }
            }

            return(rotation);
        }
Exemplo n.º 5
0
        public static bool ScaleSlider(float scale, Vector3 position, Vector3 direction, Quaternion rotation, float length, float size, float snap, out float delta)
        {
            int   id       = GUIUtility.GetControlID("ScaleSliderHash".GetHashCode(), FocusType.Keyboard);
            float newScale = scale;
            Event current  = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if ((HandleUtility.nearestControl == id && current.button == 0) || (GUIUtility.keyboardControl == id && current.button == 2))
                {
                    GUIUtility.keyboardControl = id;
                    GUIUtility.hotControl      = id;
                    s_CurrentMousePosition     = (s_StartMousePosition = current.mousePosition);
                    s_StartScale = scale;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += current.delta;
                    float num = 1f + HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, position, direction) * 0.1f;
                    num         = Handles.SnapValue(num, snap);
                    newScale    = s_StartScale * num;
                    GUI.changed = true;
                    current.Use();
                }
                break;

            case EventType.Repaint:
            {
                Color color = Color.white;
                if (id == GUIUtility.keyboardControl)
                {
                    color         = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                //float num2 = size;
                //if (GUIUtility.hotControl == id)
                //{
                //    num2 = size * scale / s_StartScale;
                //}
#if UNITY_5_6_OR_NEWER
                Handles.CubeHandleCap(id, position + direction * length, rotation, HandleUtility.GetHandleSize(position) * size, EventType.Repaint);
#else
                Handles.CubeCap(id, position + direction * length, rotation, HandleUtility.GetHandleSize(position) * size);
#endif

                Handles.DrawLine(position, position + direction * length);
                if (id == GUIUtility.keyboardControl)
                {
                    Handles.color = color;
                }
                break;
            }

            case EventType.Layout:
                HandleUtility.AddControl(id, HandleUtility.DistanceToLine(position, position + direction * length));
                HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + direction * length, size));
                break;
            }
            delta = newScale - scale;

            return(scale != newScale);
        }
Exemplo n.º 6
0
        internal static Vector3 Do(int id, Vector3 position, Vector3 direction, float size, Handles.DrawCapFunction drawFunc, float snap)
        {
            Event current = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if ((((HandleUtility.nearestControl == id) && (current.button == 0)) || ((GUIUtility.keyboardControl == id) && (current.button == 2))) && (GUIUtility.hotControl == 0))
                {
                    int num2 = id;
                    GUIUtility.keyboardControl = num2;
                    GUIUtility.hotControl      = num2;
                    s_CurrentMousePosition     = s_StartMousePosition = current.mousePosition;
                    s_StartPosition            = position;
                    Undo.CreateSnapshot();
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                return(position);

            case EventType.MouseUp:
                if ((GUIUtility.hotControl == id) && ((current.button == 0) || (current.button == 2)))
                {
                    GUIUtility.hotControl = 0;
                    Undo.RegisterSnapshot();
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                return(position);

            case EventType.MouseMove:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
                return(position);

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += current.delta;
                    float   num    = Handles.SnapValue(HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, direction), snap);
                    Vector3 vector = Handles.matrix.MultiplyVector(direction);
                    Vector3 v      = Handles.matrix.MultiplyPoint(s_StartPosition) + ((Vector3)(vector * num));
                    position    = Handles.matrix.inverse.MultiplyPoint(v);
                    GUI.changed = true;
                    current.Use();
                }
                return(position);

            case EventType.KeyDown:
                if ((GUIUtility.hotControl == id) && (current.keyCode == KeyCode.Escape))
                {
                    position = s_StartPosition;
                    GUIUtility.hotControl = 0;
                    GUI.changed           = true;
                    current.Use();
                }
                return(position);

            case EventType.Repaint:
            {
                Color white = Color.white;
                if ((id == GUIUtility.keyboardControl) && GUI.enabled)
                {
                    white         = Handles.color;
                    Handles.color = new Color(0.9647059f, 0.9490196f, 0.1960784f, 0.89f);
                }
                drawFunc(id, position, Quaternion.LookRotation(direction), size);
                if (id == GUIUtility.keyboardControl)
                {
                    Handles.color = white;
                }
                return(position);
            }

            case EventType.Layout:
                if (drawFunc != new Handles.DrawCapFunction(Handles.ArrowCap))
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, size * 0.2f));
                    return(position);
                }
                HandleUtility.AddControl(id, HandleUtility.DistanceToLine(position, position + ((Vector3)(direction * size))));
                HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + ((Vector3)(direction * size)), size * 0.2f));
                return(position);
            }
            return(position);
        }
Exemplo n.º 7
0
        internal static float DoAxis(int id, float scale, Vector3 position, Vector3 direction, Quaternion rotation, float size, float snap, float handleOffset, float lineScale)
        {
            if (GUIUtility.hotControl == id)
            {
                Handles.handleLength = size * scale / s_StartScale;
            }
            var positionOffset = direction * size * handleOffset;
            var s = GUIUtility.hotControl == id || Handles.proportionalScale
                ? Handles.handleLength
                : size;
            var startPosition = position + positionOffset;
            var cubePosition  = position + direction * (s * s_ScaleDrawLength * lineScale) + positionOffset;

            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseMove:
            case EventType.Layout:
                HandleUtility.AddControl(id, HandleUtility.DistanceToLine(startPosition, cubePosition));
                HandleUtility.AddControl(id, HandleUtility.DistanceToCube(cubePosition, rotation, size * .1f));
                break;

            case EventType.MouseDown:
                // am I closest to the thingy?
                if (HandleUtility.nearestControl == id && evt.button == 0 && !evt.alt)
                {
                    GUIUtility.hotControl  = id;       // Grab mouse focus
                    s_CurrentMousePosition = s_StartMousePosition = evt.mousePosition;
                    s_StartScale           = scale;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += evt.delta;
                    var dist = 1 + HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, position, direction) / size;
                    dist        = Handles.SnapValue(dist, snap);
                    scale       = s_StartScale * dist;
                    GUI.changed = true;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.Repaint:
                Handles.SetupHandleColor(id, evt, out var prevColor, out var thickness);
                float capSize = size * .1f;
                if (Handles.IsHovering(id, evt))
                {
                    capSize *= Handles.s_HoverExtraScale;
                }

                var camera     = Camera.current;
                var viewDir    = camera != null ? camera.transform.forward : -direction;
                var facingAway = Vector3.Dot(viewDir, direction) < 0.0f;
                // draw line vs cube in the appropriate order based on viewing
                // direction, for correct transparency sorting
                var lineEndPos = position + direction * (s * s_ScaleDrawLength * lineScale - capSize * 0.5f) + positionOffset;
                if (facingAway)
                {
                    Handles.DrawLine(startPosition, lineEndPos, thickness);
                    Handles.CubeHandleCap(id, cubePosition, rotation, capSize, EventType.Repaint);
                }
                else
                {
                    Handles.CubeHandleCap(id, cubePosition, rotation, capSize, EventType.Repaint);
                    Handles.DrawLine(startPosition, lineEndPos, thickness);
                }
                Handles.color = prevColor;
                break;
            }

            return(scale);
        }
Exemplo n.º 8
0
        internal static float DoAxis(int id, float scale, Vector3 position, Vector3 direction, Quaternion rotation, float size, float snap, float handleOffset, float lineScale)
        {
            Vector3 b       = direction * size * handleOffset;
            float   num     = (GUIUtility.hotControl != id) ? size : (size * scale / SliderScale.s_StartScale);
            Vector3 p       = position + b;
            Vector3 vector  = position + direction * (num * SliderScale.s_ScaleDrawLength * lineScale) + b;
            Event   current = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (HandleUtility.nearestControl == id && current.button == 0)
                {
                    GUIUtility.hotControl = id;
                    SliderScale.s_CurrentMousePosition = (SliderScale.s_StartMousePosition = current.mousePosition);
                    SliderScale.s_StartScale           = scale;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.MouseMove:
                if (id == HandleUtility.nearestControl)
                {
                    HandleUtility.Repaint();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    SliderScale.s_CurrentMousePosition += current.delta;
                    float num2 = 1f + HandleUtility.CalcLineTranslation(SliderScale.s_StartMousePosition, SliderScale.s_CurrentMousePosition, position, direction) / size;
                    num2        = Handles.SnapValue(num2, snap);
                    scale       = SliderScale.s_StartScale * num2;
                    GUI.changed = true;
                    current.Use();
                }
                break;

            case EventType.Repaint:
            {
                Color color = Color.white;
                if (id == GUIUtility.hotControl)
                {
                    color         = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    color         = Handles.color;
                    Handles.color = Handles.preselectionColor;
                }
                Handles.DrawLine(p, vector);
                Handles.CubeHandleCap(id, vector, rotation, size * 0.1f, EventType.Repaint);
                if (id == GUIUtility.hotControl || (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0))
                {
                    Handles.color = color;
                }
                break;
            }

            case EventType.Layout:
                HandleUtility.AddControl(id, HandleUtility.DistanceToLine(p, vector));
                HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(vector, size * 0.3f));
                break;
            }
            return(scale);
        }
Exemplo n.º 9
0
        internal static float DoAxis(int id, float scale, Vector3 position, Vector3 direction, Quaternion rotation, float size, float snap, float handleOffset, float lineScale)
        {
            var positionOffset = direction * size * handleOffset;
            var s = GUIUtility.hotControl == id
                ? size * scale / s_StartScale
                : size;
            var startPosition = position + positionOffset;
            var cubePosition  = position + direction * (s * s_ScaleDrawLength * lineScale) + positionOffset;

            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
                HandleUtility.AddControl(id, HandleUtility.DistanceToLine(startPosition, cubePosition));
                HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(cubePosition, size * .3f));
                break;

            case EventType.MouseDown:
                // am I closest to the thingy?
                if (HandleUtility.nearestControl == id && evt.button == 0)
                {
                    GUIUtility.hotControl  = id;       // Grab mouse focus
                    s_CurrentMousePosition = s_StartMousePosition = evt.mousePosition;
                    s_StartScale           = scale;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += evt.delta;
                    var dist = 1 + HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, position, direction) / size;
                    dist        = Handles.SnapValue(dist, snap);
                    scale       = s_StartScale * dist;
                    GUI.changed = true;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.MouseMove:
                if (id == HandleUtility.nearestControl)
                {
                    HandleUtility.Repaint();
                }
                break;

            case EventType.Repaint:
                Color temp = Color.white;
                if (id == GUIUtility.hotControl)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.preselectionColor;
                }

                Handles.DrawLine(startPosition, cubePosition);
                Handles.CubeHandleCap(id, cubePosition, rotation, size * .1f, EventType.Repaint);

                if (id == GUIUtility.hotControl || id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    Handles.color = temp;
                }
                break;
            }

            return(scale);
        }
Exemplo n.º 10
0
        public static float Do(int id, float value, Quaternion rotation, Vector3 position, Vector3 axis, float size, bool cutoffPlane, float snap, bool enableRayDrag, bool showHotArc, Color fillColor)
        {
            if (Mathf.Abs(Vector3.Dot(Camera.current.transform.forward, axis)) > 0.999f)
            {
                cutoffPlane = false;
            }

            Event current = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (HandleUtility.nearestControl == id && current.button == 0)
                {
                    GUIUtility.hotControl = id;
                    ToolsEx.LockHandlePosition();
                    if (cutoffPlane)
                    {
                        Vector3 normalized = Vector3.Cross(axis, Camera.current.transform.forward).normalized;
                        s_StartPosition = HandleUtility.ClosestPointToArc(position, axis, normalized, 180f, size);
                    }
                    else
                    {
                        s_StartPosition = HandleUtility.ClosestPointToDisc(position, axis, size);
                    }
                    s_RotationDist         = value;
                    s_StartRotation        = rotation;
                    s_StartAxis            = axis;
                    s_CurrentMousePosition = s_StartMousePosition = Event.current.mousePosition;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    break;
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2))
                {
                    ToolsEx.UnlockHandlePosition();
                    GUIUtility.hotControl = 0;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    break;
                }
                break;

            case EventType.MouseMove:
                if (id == HandleUtility.nearestControl)
                {
                    HandleUtility.Repaint();
                    break;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    if (EditorGUI.actionKey && current.shift && enableRayDrag)
                    {
                        //if (HandleUtility.ignoreRaySnapObjects == null)
                        //	Handles.SetupIgnoreRaySnapObjects();
                        object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                        if (obj != null && (double)Vector3.Dot(axis.normalized, rotation * Vector3.forward) < 0.999)
                        {
                            Vector3 lhs = ((RaycastHit)obj).point - position;
                            rotation = Quaternion.LookRotation(lhs - Vector3.Dot(lhs, axis.normalized) * axis.normalized, rotation * Vector3.up);
                        }
                    }
                    else
                    {
                        Vector3 normalized = Vector3.Cross(axis, position - s_StartPosition).normalized;
                        s_CurrentMousePosition += current.delta;
                        s_RotationDist          = (float)((double)HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, normalized) / (double)size * 30.0);
                        s_RotationDist          = Handles.SnapValue(s_RotationDist, snap);
                        rotation = Quaternion.AngleAxis(s_RotationDist * -1f, s_StartAxis) * s_StartRotation;
                    }
                    GUI.changed = true;
                    current.Use();
                    break;
                }
                break;

            case EventType.KeyDown:
                if (current.keyCode == KeyCode.Escape && GUIUtility.hotControl == id)
                {
                    ToolsEx.UnlockHandlePosition();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    break;
                }
                break;

            case EventType.Repaint:
                Color color1 = Color.white;
                if (id == GUIUtility.hotControl)
                {
                    color1        = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    color1        = Handles.color;
                    Handles.color = Handles.secondaryColor;
                }
                if (GUIUtility.hotControl == id)
                {
                    Color   color2     = Handles.color;
                    Vector3 normalized = (s_StartPosition - position).normalized;
                    Handles.color = fillColor;
                    Handles.DrawLine(position, position + normalized * size);
                    float   angle   = -Mathf.Sign(s_RotationDist) * Mathf.Repeat(Mathf.Abs(s_RotationDist), 360f);
                    Vector3 vector3 = Quaternion.AngleAxis(angle, axis) * normalized;
                    Handles.DrawLine(position, position + vector3 * size);
                    Handles.color = fillColor * new Color(1f, 1f, 1f, 0.2f);
                    int num = 0;
                    for (int index = (int)Mathf.Abs(s_RotationDist * (1f / 360f)); num < index; ++num)
                    {
                        Handles.DrawSolidDisc(position, axis, size);
                    }
                    Handles.DrawSolidArc(position, axis, normalized, angle, size);
                    if (EditorGUI.actionKey && snap > 0)
                    {
                        DrawRotationUnitSnapMarkers(position, axis, size, 0.1f, snap, normalized);
                        DrawRotationUnitSnapMarkers(position, axis, size, 0.2f, 45f, normalized);
                    }
                    Handles.color = color2;
                }
                if (showHotArc && GUIUtility.hotControl == id || GUIUtility.hotControl != id && !cutoffPlane)
                {
                    Handles.DrawWireDisc(position, axis, size);
                }
                else if (GUIUtility.hotControl != id && cutoffPlane)
                {
                    Vector3 normalized = Vector3.Cross(axis, Camera.current.transform.forward).normalized;
                    Handles.DrawWireArc(position, axis, normalized, 180f, size);
                }
                if (id == GUIUtility.hotControl || id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    Handles.color = color1;
                    break;
                }
                break;

            case EventType.Layout:
                float distance;
                if (cutoffPlane)
                {
                    Vector3 normalized = Vector3.Cross(axis, Camera.current.transform.forward).normalized;
                    distance = HandleUtility.DistanceToArc(position, axis, normalized, 180f, size) * 0.3f;
                }
                else
                {
                    distance = HandleUtility.DistanceToDisc(position, axis, size) * 0.3f;
                }
                HandleUtility.AddControl(id, distance);
                break;
            }
            return(s_RotationDist);
        }
Exemplo n.º 11
0
        public static float DoAxis(int id, float scale, Vector3 position, Vector3 direction, Quaternion rotation, float size, float snap)
        {
            Event current = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (HandleUtility.nearestControl == id && current.button == 0 || GUIUtility.keyboardControl == id && current.button == 2)
                {
                    int num = id;
                    GUIUtility.keyboardControl         = num;
                    GUIUtility.hotControl              = num;
                    SliderScale.s_CurrentMousePosition = SliderScale.s_StartMousePosition = current.mousePosition;
                    SliderScale.s_StartScale           = scale;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    break;
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    break;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    SliderScale.s_CurrentMousePosition += current.delta;
                    float num = Handles.SnapValue((float)(1.0 + (double)HandleUtility.CalcLineTranslation(SliderScale.s_StartMousePosition, SliderScale.s_CurrentMousePosition, position, direction) / (double)size), snap);
                    scale       = SliderScale.s_StartScale * num;
                    GUI.changed = true;
                    current.Use();
                    break;
                }
                break;

            case EventType.Repaint:
                Color color = Color.white;
                if (id == GUIUtility.keyboardControl)
                {
                    color         = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                float num1 = size;
                if (GUIUtility.hotControl == id)
                {
                    num1 = size * scale / SliderScale.s_StartScale;
                }
                Handles.CubeCap(id, position + direction * num1 * SliderScale.s_ScaleDrawLength, rotation, size * 0.1f);
                Handles.DrawLine(position, position + direction * (float)((double)num1 * (double)SliderScale.s_ScaleDrawLength - (double)size * 0.0500000007450581));
                if (id == GUIUtility.keyboardControl)
                {
                    Handles.color = color;
                    break;
                }
                break;

            case EventType.Layout:
                HandleUtility.AddControl(id, HandleUtility.DistanceToLine(position, position + direction * size));
                HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + direction * size, size * 0.2f));
                break;
            }
            return(scale);
        }
Exemplo n.º 12
0
        public static Quaternion Do(int id, Quaternion rotation, Vector3 position, Vector3 axis, float size, bool cutoffPlane, float snap)
        {
            float num;

            if (Mathf.Abs(Vector3.Dot(Camera.current.transform.forward, axis)) > 0.999f)
            {
                cutoffPlane = false;
            }
            Event current = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (((HandleUtility.nearestControl == id) && (current.button == 0)) || ((GUIUtility.keyboardControl == id) && (current.button == 2)))
                {
                    int num3 = id;
                    GUIUtility.keyboardControl = num3;
                    GUIUtility.hotControl      = num3;
                    Tools.LockHandlePosition();
                    if (!cutoffPlane)
                    {
                        s_StartPosition = HandleUtility.ClosestPointToDisc(position, axis, size);
                    }
                    else
                    {
                        Vector3 normalized = Vector3.Cross(axis, Camera.current.transform.forward).normalized;
                        s_StartPosition = HandleUtility.ClosestPointToArc(position, axis, normalized, 180f, size);
                    }
                    s_RotationDist         = 0f;
                    s_StartRotation        = rotation;
                    s_StartAxis            = axis;
                    s_CurrentMousePosition = s_StartMousePosition = Event.current.mousePosition;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                return(rotation);

            case EventType.MouseUp:
                if ((GUIUtility.hotControl == id) && ((current.button == 0) || (current.button == 2)))
                {
                    Tools.UnlockHandlePosition();
                    GUIUtility.hotControl = 0;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                return(rotation);

            case EventType.MouseMove:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
                return(rotation);

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    if (!(EditorGUI.actionKey && current.shift))
                    {
                        Vector3 constraintDir = Vector3.Cross(axis, position - s_StartPosition).normalized;
                        s_CurrentMousePosition += current.delta;
                        s_RotationDist          = (HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, constraintDir) / size) * 30f;
                        s_RotationDist          = Handles.SnapValue(s_RotationDist, snap);
                        rotation = Quaternion.AngleAxis(s_RotationDist * -1f, s_StartAxis) * s_StartRotation;
                    }
                    else
                    {
                        if (HandleUtility.ignoreRaySnapObjects == null)
                        {
                            Handles.SetupIgnoreRaySnapObjects();
                        }
                        object obj2 = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                        if ((obj2 != null) && (Vector3.Dot(axis.normalized, (Vector3)(rotation * Vector3.forward)) < 0.999))
                        {
                            RaycastHit hit     = (RaycastHit)obj2;
                            Vector3    lhs     = hit.point - position;
                            Vector3    forward = lhs - ((Vector3)(Vector3.Dot(lhs, axis.normalized) * axis.normalized));
                            rotation = Quaternion.LookRotation(forward, (Vector3)(rotation * Vector3.up));
                        }
                    }
                    GUI.changed = true;
                    current.Use();
                }
                return(rotation);

            case EventType.KeyDown:
                if ((current.keyCode == KeyCode.Escape) && (GUIUtility.hotControl == id))
                {
                    Tools.UnlockHandlePosition();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                return(rotation);

            case EventType.Repaint:
            {
                Color white = Color.white;
                if (id == GUIUtility.keyboardControl)
                {
                    white         = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                if (GUIUtility.hotControl == id)
                {
                    Color   color    = Handles.color;
                    Vector3 vector12 = s_StartPosition - position;
                    Vector3 from     = vector12.normalized;
                    Handles.color = Handles.secondaryColor;
                    Handles.DrawLine(position, position + ((Vector3)((from * size) * 1.1f)));
                    float   angle   = Mathf.Repeat(-s_RotationDist - 180f, 360f) - 180f;
                    Vector3 vector7 = (Vector3)(Quaternion.AngleAxis(angle, axis) * from);
                    Handles.DrawLine(position, position + ((Vector3)((vector7 * size) * 1.1f)));
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 0.2f);
                    Handles.DrawSolidArc(position, axis, from, angle, size);
                    Handles.color = color;
                }
                if (cutoffPlane)
                {
                    Vector3 vector8 = Vector3.Cross(axis, Camera.current.transform.forward).normalized;
                    Handles.DrawWireArc(position, axis, vector8, 180f, size);
                }
                else
                {
                    Handles.DrawWireDisc(position, axis, size);
                }
                if (id == GUIUtility.keyboardControl)
                {
                    Handles.color = white;
                }
                return(rotation);
            }

            case EventType.Layout:
            {
                if (!cutoffPlane)
                {
                    num = HandleUtility.DistanceToDisc(position, axis, size) / 2f;
                    break;
                }
                Vector3 vector = Vector3.Cross(axis, Camera.current.transform.forward).normalized;
                num = HandleUtility.DistanceToArc(position, axis, vector, 180f, size) / 2f;
                break;
            }

            default:
                return(rotation);
            }
            HandleUtility.AddControl(id, num);
            return(rotation);
        }
Exemplo n.º 13
0
        internal static float DoAxis(int id, float scale, Vector3 position, Vector3 direction, Quaternion rotation, float size, float snap, float handleOffset, float lineScale)
        {
            var positionOffset = direction * size * handleOffset;
            var s = GUIUtility.hotControl == id
                ? size * scale / s_StartScale
                : size;
            var startPosition = position + positionOffset;
            var cubePosition  = position + direction * (s * s_ScaleDrawLength * lineScale) + positionOffset;

            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseMove:
            case EventType.Layout:
                HandleUtility.AddControl(id, HandleUtility.DistanceToLine(startPosition, cubePosition));
                HandleUtility.AddControl(id, HandleUtility.DistanceToCube(cubePosition, rotation, size * .1f));
                break;

            case EventType.MouseDown:
                // am I closest to the thingy?
                if (HandleUtility.nearestControl == id && evt.button == 0 && !evt.alt)
                {
                    GUIUtility.hotControl  = id;       // Grab mouse focus
                    s_CurrentMousePosition = s_StartMousePosition = evt.mousePosition;
                    s_StartScale           = scale;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += evt.delta;
                    var dist = 1 + HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, position, direction) / size;
                    dist        = Handles.SnapValue(dist, snap);
                    scale       = s_StartScale * dist;
                    GUI.changed = true;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.Repaint:
                Handles.SetupHandleColor(id, evt, out var prevColor, out var thickness);
                float capSize = size * .1f;
                if (Handles.IsHovering(id, evt))
                {
                    capSize *= Handles.s_HoverExtraScale;
                }
                Handles.DrawLine(startPosition, cubePosition, thickness);
                Handles.CubeHandleCap(id, cubePosition, rotation, capSize, EventType.Repaint);
                Handles.color = prevColor;
                break;
            }

            return(scale);
        }
Exemplo n.º 14
0
        internal static Vector3 Do(int id, Vector3 position, Vector3 handleDirection, Vector3 slideDirection, float size, Handles.DrawCapFunction drawFunc, float snap)
        {
            Event current = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if ((HandleUtility.nearestControl == id && current.button == 0 || GUIUtility.keyboardControl == id && current.button == 2) && GUIUtility.hotControl == 0)
                {
                    int num = id;
                    GUIUtility.keyboardControl      = num;
                    GUIUtility.hotControl           = num;
                    Slider1D.s_CurrentMousePosition = Slider1D.s_StartMousePosition = current.mousePosition;
                    Slider1D.s_StartPosition        = position;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    break;
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    break;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    Slider1D.s_CurrentMousePosition += current.delta;
                    float   num     = Handles.SnapValue(HandleUtility.CalcLineTranslation(Slider1D.s_StartMousePosition, Slider1D.s_CurrentMousePosition, Slider1D.s_StartPosition, slideDirection), snap);
                    Vector3 vector3 = Handles.matrix.MultiplyVector(slideDirection);
                    Vector3 v       = Handles.s_Matrix.MultiplyPoint(Slider1D.s_StartPosition) + vector3 * num;
                    position    = Handles.s_InverseMatrix.MultiplyPoint(v);
                    GUI.changed = true;
                    current.Use();
                    break;
                }
                break;

            case EventType.Repaint:
                Color color = Color.white;
                if (id == GUIUtility.keyboardControl && GUI.enabled)
                {
                    color         = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                drawFunc(id, position, Quaternion.LookRotation(handleDirection), size);
                if (id == GUIUtility.keyboardControl)
                {
                    Handles.color = color;
                    break;
                }
                break;

            case EventType.Layout:
                if ((MulticastDelegate)drawFunc == (MulticastDelegate) new Handles.DrawCapFunction(Handles.ArrowCap))
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToLine(position, position + slideDirection * size));
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + slideDirection * size, size * 0.2f));
                    break;
                }
                HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, size * 0.2f));
                break;
            }
            return(position);
        }
Exemplo n.º 15
0
        internal static Vector3 Do(int id, Vector3 position, Vector3 handleDirection, Vector3 slideDirection, float size, Handles.DrawCapFunction drawFunc, float snap)
        {
            Event current = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (HandleUtility.nearestControl == id && current.button == 0 && GUIUtility.hotControl == 0)
                {
                    GUIUtility.hotControl           = id;
                    Slider1D.s_CurrentMousePosition = (Slider1D.s_StartMousePosition = current.mousePosition);
                    Slider1D.s_StartPosition        = position;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.MouseMove:
                if (id == HandleUtility.nearestControl)
                {
                    HandleUtility.Repaint();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    Slider1D.s_CurrentMousePosition += current.delta;
                    float num = HandleUtility.CalcLineTranslation(Slider1D.s_StartMousePosition, Slider1D.s_CurrentMousePosition, Slider1D.s_StartPosition, slideDirection);
                    num = Handles.SnapValue(num, snap);
                    Vector3 a     = Handles.matrix.MultiplyVector(slideDirection);
                    Vector3 point = Handles.matrix.MultiplyPoint(Slider1D.s_StartPosition) + a * num;
                    position    = Handles.inverseMatrix.MultiplyPoint(point);
                    GUI.changed = true;
                    current.Use();
                }
                break;

            case EventType.Repaint:
            {
                Color color = Color.white;
                if (id == GUIUtility.hotControl)
                {
                    color         = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    color         = Handles.color;
                    Handles.color = Handles.preselectionColor;
                }
                drawFunc(id, position, Quaternion.LookRotation(handleDirection), size);
                if (id == GUIUtility.hotControl || (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0))
                {
                    Handles.color = color;
                }
                break;
            }

            case EventType.Layout:
                if (Slider1D.< > f__mg$cache0 == null)
                {
                    Slider1D.< > f__mg$cache0 = new Handles.DrawCapFunction(Handles.ArrowCap);
                }
                if (drawFunc == Slider1D.< > f__mg$cache0)
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToLine(position, position + slideDirection * size));
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + slideDirection * size, size * 0.2f));
                }
                else
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, size * 0.2f));
                }
                break;
            }
            return(position);
        }
Exemplo n.º 16
0
    public static sbyte DrawAxisHandle(Vector3 handlePosition, sbyte voxPosition, NPVoxToUnity npVoxToUnity, Vector3 axis)
    {
        int controlID = GUIUtility.GetControlID(FocusType.Passive);

        Handles.DotCap(controlID, handlePosition, Quaternion.identity, npVoxToUnity.VoxeSize.x * 0.25f);

        Vector3 screenPosition = Handles.matrix.MultiplyPoint(handlePosition);

        switch (Event.current.GetTypeForControl(controlID))
        {
        case EventType.Layout:
            HandleUtility.AddControl(
                controlID,
                HandleUtility.DistanceToCircle(screenPosition, npVoxToUnity.VoxeSize.x * 0.25f * (1 + npVoxToUnity.UnityVoxModelSize.x))
                );
            break;

        case EventType.MouseDown:
            if (HandleUtility.nearestControl == controlID)
            {
                mouseStartPos = Event.current.mousePosition;
                startCoord    = voxPosition;
                // Respond to a press on this handle. Drag starts automatically.
                GUIUtility.hotControl = controlID;
                Event.current.Use();
            }
            break;

        case EventType.MouseUp:
            if (GUIUtility.hotControl == controlID)
            {
                // Respond to a release on this handle. Drag stops automatically.
                GUIUtility.hotControl = 0;
                Event.current.Use();
            }
            break;

        case EventType.MouseDrag:
            if (GUIUtility.hotControl == controlID)
            {
                // Do whatever with mouse deltas here
                GUI.changed = true;

                float transl = HandleUtility.CalcLineTranslation(mouseStartPos, Event.current.mousePosition, handlePosition, axis);
                sbyte result;
                if (axis == Vector3.forward)
                {
                    result = (sbyte)(startCoord + npVoxToUnity.ToVoxDirection(Vector3.forward * transl).Z);
                }
                else if (axis == Vector3.right)
                {
                    result = (sbyte)(startCoord + npVoxToUnity.ToVoxDirection(Vector3.right * transl).X);
                }
                else
                {
                    result = (sbyte)(startCoord + npVoxToUnity.ToVoxDirection(Vector3.up * transl).Y);
                }
                if (result != voxPosition)
                {
                    SceneView.RepaintAll();
                    return(result);
                }
            }
            break;
        }
        return(voxPosition);
    }
Exemplo n.º 17
0
        internal static float DoFloat(int id, Vector3 position, Vector3 handleDirection, Vector3 slideDirection, float floatIn, float size, Handles.CapFunction capFunction, float snap, out EventType handleEvent)
        {
            Event current = Event.current;
            float result  = floatIn;

            handleEvent = current.GetTypeForControl(id);

            switch (handleEvent)
            {
            case EventType.MouseDown:
                if (HandleUtility.nearestControl == id && current.button == 0 && GUIUtility.hotControl == 0)
                {
                    GUIUtility.hotControl  = id;
                    s_CurrentMousePosition = s_StartMousePosition = current.mousePosition;
                    s_StartPosition        = position;
                    s_StartSliderValue     = floatIn;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    break;
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    break;
                }
                break;

            case EventType.MouseMove:
                if (id == HandleUtility.nearestControl)
                {
                    HandleUtility.Repaint();
                    break;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += current.delta;
                    result      = s_StartSliderValue + SnapValue(HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, slideDirection), snap);
                    GUI.changed = true;
                    current.Use();
                    break;
                }
                break;

            case EventType.Repaint:
                Color color = Color.white;
                if (id == GUIUtility.hotControl)
                {
                    color         = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    color         = Handles.color;
                    Handles.color = Handles.preselectionColor;
                }
                capFunction(id, position, Quaternion.LookRotation(handleDirection), size, EventType.Repaint);
                if (id == GUIUtility.hotControl || id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    Handles.color = color;
                    break;
                }
                break;

            case EventType.Layout:
                if (capFunction != null)
                {
                    capFunction(id, position, Quaternion.LookRotation(handleDirection), size, EventType.Layout);
                    break;
                }
                HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, size * 0.2f));
                break;
            }
            return(result);
        }
Exemplo n.º 18
0
        internal static Vector3 Do(int id, Vector3 position, Vector3 handleDirection, Vector3 slideDirection, float size, Handles.DrawCapFunction drawFunc, float snap)
        {
            Event current = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if ((((HandleUtility.nearestControl == id) && (current.button == 0)) || ((GUIUtility.keyboardControl == id) && (current.button == 2))) && (GUIUtility.hotControl == 0))
                {
                    int num = id;
                    GUIUtility.keyboardControl = num;
                    GUIUtility.hotControl      = num;
                    s_CurrentMousePosition     = s_StartMousePosition = current.mousePosition;
                    s_StartPosition            = position;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                return(position);

            case EventType.MouseUp:
                if ((GUIUtility.hotControl == id) && ((current.button == 0) || (current.button == 2)))
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                return(position);

            case EventType.MouseMove:
            case EventType.KeyDown:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
                return(position);

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += current.delta;
                    float   num2   = Handles.SnapValue(HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, slideDirection), snap);
                    Vector3 vector = Handles.matrix.MultiplyVector(slideDirection);
                    Vector3 v      = Handles.s_Matrix.MultiplyPoint(s_StartPosition) + ((Vector3)(vector * num2));
                    position    = Handles.s_InverseMatrix.MultiplyPoint(v);
                    GUI.changed = true;
                    current.Use();
                }
                return(position);

            case EventType.Repaint:
            {
                Color white = Color.white;
                if ((id == GUIUtility.keyboardControl) && GUI.enabled)
                {
                    white         = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                drawFunc(id, position, Quaternion.LookRotation(handleDirection), size);
                if (id == GUIUtility.keyboardControl)
                {
                    Handles.color = white;
                }
                return(position);
            }

            case EventType.Layout:
                if (< > f__mg$cache0 == null)
                {
                    < > f__mg$cache0 = new Handles.DrawCapFunction(Handles.ArrowCap);
                }
Exemplo n.º 19
0
        public static Quaternion Do(int id, Quaternion rotation, Vector3 position, Vector3 axis, float size, bool cutoffPlane, float snap)
        {
            if (Mathf.Abs(Vector3.Dot(Camera.current.transform.forward, axis)) > 0.999f)
            {
                cutoffPlane = false;
            }
            Event current = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if ((HandleUtility.nearestControl == id && current.button == 0) || (GUIUtility.keyboardControl == id && current.button == 2))
                {
                    GUIUtility.keyboardControl = id;
                    GUIUtility.hotControl      = id;
                    Tools.LockHandlePosition();
                    if (cutoffPlane)
                    {
                        Vector3 normalized = Vector3.Cross(axis, Camera.current.transform.forward).normalized;
                        Disc.s_StartPosition = HandleUtility.ClosestPointToArc(position, axis, normalized, 180f, size);
                    }
                    else
                    {
                        Disc.s_StartPosition = HandleUtility.ClosestPointToDisc(position, axis, size);
                    }
                    Disc.s_RotationDist         = 0f;
                    Disc.s_StartRotation        = rotation;
                    Disc.s_StartAxis            = axis;
                    Disc.s_CurrentMousePosition = (Disc.s_StartMousePosition = Event.current.mousePosition);
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2))
                {
                    Tools.UnlockHandlePosition();
                    GUIUtility.hotControl = 0;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    bool flag = EditorGUI.actionKey && current.shift;
                    if (flag)
                    {
                        if (HandleUtility.ignoreRaySnapObjects == null)
                        {
                            Handles.SetupIgnoreRaySnapObjects();
                        }
                        object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
                        if (obj != null && (double)Vector3.Dot(axis.normalized, rotation * Vector3.forward) < 0.999)
                        {
                            Vector3 vector  = ((RaycastHit)obj).point - position;
                            Vector3 forward = vector - Vector3.Dot(vector, axis.normalized) * axis.normalized;
                            rotation = Quaternion.LookRotation(forward, rotation * Vector3.up);
                        }
                    }
                    else
                    {
                        Vector3 normalized2 = Vector3.Cross(axis, position - Disc.s_StartPosition).normalized;
                        Disc.s_CurrentMousePosition += current.delta;
                        Disc.s_RotationDist          = HandleUtility.CalcLineTranslation(Disc.s_StartMousePosition, Disc.s_CurrentMousePosition, Disc.s_StartPosition, normalized2) / size * 30f;
                        Disc.s_RotationDist          = Handles.SnapValue(Disc.s_RotationDist, snap);
                        rotation = Quaternion.AngleAxis(Disc.s_RotationDist * -1f, Disc.s_StartAxis) * Disc.s_StartRotation;
                    }
                    GUI.changed = true;
                    current.Use();
                }
                break;

            case EventType.KeyDown:
                if (current.keyCode == KeyCode.Escape && GUIUtility.hotControl == id)
                {
                    Tools.UnlockHandlePosition();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.Repaint:
            {
                Color color = Color.white;
                if (id == GUIUtility.keyboardControl)
                {
                    color         = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                if (GUIUtility.hotControl == id)
                {
                    Color   color2      = Handles.color;
                    Vector3 normalized3 = (Disc.s_StartPosition - position).normalized;
                    Handles.color = Handles.secondaryColor;
                    Handles.DrawLine(position, position + normalized3 * size * 1.1f);
                    float   angle = Mathf.Repeat(-Disc.s_RotationDist - 180f, 360f) - 180f;
                    Vector3 a     = Quaternion.AngleAxis(angle, axis) * normalized3;
                    Handles.DrawLine(position, position + a * size * 1.1f);
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 0.2f);
                    Handles.DrawSolidArc(position, axis, normalized3, angle, size);
                    Handles.color = color2;
                }
                if (cutoffPlane)
                {
                    Vector3 normalized4 = Vector3.Cross(axis, Camera.current.transform.forward).normalized;
                    Handles.DrawWireArc(position, axis, normalized4, 180f, size);
                }
                else
                {
                    Handles.DrawWireDisc(position, axis, size);
                }
                if (id == GUIUtility.keyboardControl)
                {
                    Handles.color = color;
                }
                break;
            }

            case EventType.Layout:
            {
                float distance;
                if (cutoffPlane)
                {
                    Vector3 normalized5 = Vector3.Cross(axis, Camera.current.transform.forward).normalized;
                    distance = HandleUtility.DistanceToArc(position, axis, normalized5, 180f, size) / 2f;
                }
                else
                {
                    distance = HandleUtility.DistanceToDisc(position, axis, size) / 2f;
                }
                HandleUtility.AddControl(id, distance);
                break;
            }
            }
            return(rotation);
        }
Exemplo n.º 20
0
        internal static Vector3 Do(int id, Vector3 position, Vector3 direction, float size, CSGHandles.CapFunction capFunction, SnapMode snapMode, Vector3[] snapVertices, CSGHandles.InitFunction initFunction = null, CSGHandles.InitFunction shutdownFunction = null)
        {
            var evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            {
                if (capFunction != null)
                {
                    capFunction(id, position, Quaternion.LookRotation(direction), size, EventType.Layout);
                }
                else
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, size * .2f));
                }
                break;
            }

            case EventType.MouseDown:
            {
                if (CSGHandles.disabled)
                {
                    break;
                }
                if (((HandleUtility.nearestControl == id && evt.button == 0) ||
                     (GUIUtility.keyboardControl == id && evt.button == 2)) && GUIUtility.hotControl == 0)
                {
                    s_SnapVertices = null;
                    if (initFunction != null)
                    {
                        initFunction();
                    }
                    GUIUtility.hotControl  = GUIUtility.keyboardControl = id;
                    s_CurrentMousePosition = s_StartMousePosition = evt.mousePosition;
                    s_StartPosition        = position;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }

                break;
            }

            case EventType.MouseDrag:
            {
                if (GUIUtility.hotControl == id)
                {
                    if (s_SnapVertices == null)
                    {
                        if (snapVertices != null)
                        {
                            s_SnapVertices = snapVertices.ToArray();
                        }
                        else
                        {
                            s_SnapVertices = new Vector3[] { s_StartPosition }
                        };
                    }
                    s_CurrentMousePosition += evt.delta;
                    var dist           = HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, direction);
                    var worldDirection = Handles.matrix.MultiplyVector(direction);
                    var worldPosition  = Handles.matrix.MultiplyPoint(s_StartPosition) + (worldDirection * dist);
                    position = Handles.inverseMatrix.MultiplyPoint(worldPosition);

                    switch (snapMode)
                    {
                    case SnapMode.GridSnapping:
                    {
                        var delta = RealtimeCSG.CSGGrid.SnapDeltaToGrid(position - s_StartPosition, s_SnapVertices, snapToGridPlane: false, snapToSelf: true);
                        position = delta + s_StartPosition;
                        break;
                    }

                    case SnapMode.RelativeSnapping:
                    {
                        var delta = RealtimeCSG.CSGGrid.SnapDeltaRelative(position - s_StartPosition, snapToGridPlane: false);
                        position = delta + s_StartPosition;
                        break;
                    }

                    default:
                    case SnapMode.None:
                    {
                        position = RealtimeCSG.CSGGrid.HandleLockedAxi(position - s_StartPosition) + s_StartPosition;
                        break;
                    }
                    }

                    GUI.changed = true;
                    evt.Use();
                }
                break;
            }

            case EventType.MouseUp:
            {
                if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    if (shutdownFunction != null)
                    {
                        shutdownFunction();
                    }
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;
            }

            case EventType.Repaint:
            {
                var originalColor = Handles.color;
                Handles.color = CSGHandles.StateColor(originalColor, CSGHandles.disabled, CSGHandles.FocusControl == id);
                if (capFunction != null)
                {
                    capFunction(id, position, Quaternion.LookRotation(direction), size, EventType.Repaint);
                }

                Handles.color = originalColor;
                break;
            }
            }
            return(position);
        }
Exemplo n.º 21
0
        internal static Vector3 Do(int id, Vector3 position, Vector3 offset, Vector3 handleDirection, Vector3 slideDirection, float size, Handles.CapFunction capFunction, float snap)
        {
            Event evt       = Event.current;
            var   eventType = evt.GetTypeForControl(id);

            switch (eventType)
            {
            case EventType.Layout:
            case EventType.MouseMove:
                if (capFunction != null)
                {
                    capFunction(id, position + offset, Quaternion.LookRotation(handleDirection), size, eventType);
                }
                else
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + offset, size * .2f));
                }
                break;

            case EventType.MouseDown:
                // am I closest to the thingy?
                if (HandleUtility.nearestControl == id && evt.button == 0 && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    GUIUtility.hotControl = id;        // Grab mouse focus
                    s_StartMousePosition  = evt.mousePosition;
                    s_ConstraintOrigin    = Handles.matrix.MultiplyPoint3x4(position);
                    s_StartPosition       = position;
                    s_ConstraintDirection = Handles.matrix.MultiplyVector(slideDirection);
                    s_HandleOffset        = HandleUtility.CalcPositionOnConstraint(Camera.current, evt.mousePosition, s_ConstraintOrigin, s_ConstraintDirection, out Vector3 point)
                            ? s_ConstraintOrigin - point
                            : Vector3.zero;
                    evt.Use();
                    s_StartHandleSize = HandleUtility.GetHandleSize(point);
                }

                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    // First try to calculate the translation by casting a mouse ray against a world position plane
                    // oriented towards the camera. This gives more accurate results than doing the line translation
                    // in 2D space, but is more prone towards skewing extreme values when the ray is near parallel
                    // to the plane. To address this, CalcPositionOnConstraint will fail if the mouse ray is close
                    // to parallel (see HandleUtility.k_MinRayConstraintDot) and fall back to 2D based movement.
                    if (HandleUtility.CalcPositionOnConstraint(Camera.current, evt.mousePosition, s_ConstraintOrigin, s_ConstraintDirection, out Vector3 worldPosition))
                    {
                        var handleOffset = s_HandleOffset * (HandleUtility.GetHandleSize(worldPosition) / s_StartHandleSize);
                        worldPosition += handleOffset;

                        if (EditorSnapSettings.incrementalSnapActive)
                        {
                            Vector3 dir  = worldPosition - s_ConstraintOrigin;
                            float   dist = Handles.SnapValue(dir.magnitude, snap) * Mathf.Sign(Vector3.Dot(s_ConstraintDirection, dir));
                            worldPosition = s_ConstraintOrigin + s_ConstraintDirection.normalized * dist;
                        }
                        else if (EditorSnapSettings.gridSnapActive)
                        {
                            worldPosition = Snapping.Snap(worldPosition, GridSettings.size, (SnapAxis) new SnapAxisFilter(s_ConstraintDirection));
                        }

                        position             = Handles.inverseMatrix.MultiplyPoint(worldPosition);
                        s_StartPosition      = position;
                        s_StartMousePosition = evt.mousePosition;
                    }
                    else
                    {
                        // Unlike HandleUtility.CalcPositionOnConstraint, CalcLineTranslation _does_ multiply constraint
                        // origin and direction by Handles.matrix, so make sure to pass in unmodified vectors here
                        float dist = HandleUtility.CalcLineTranslation(s_StartMousePosition, evt.mousePosition, s_StartPosition, slideDirection);
                        dist          = Handles.SnapValue(dist, snap);
                        worldPosition = Handles.matrix.MultiplyPoint(s_StartPosition) + s_ConstraintDirection * dist;
                        if (EditorSnapSettings.gridSnapActive)
                        {
                            worldPosition = Snapping.Snap(worldPosition, GridSettings.size, (SnapAxis) new SnapAxisFilter(s_ConstraintDirection));
                        }
                        position = Handles.inverseMatrix.MultiplyPoint(worldPosition);
                    }

                    GUI.changed = true;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                }
                break;

            case EventType.Repaint:
                Color temp = Color.white;

                if (id == GUIUtility.hotControl)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.preselectionColor;
                }

                capFunction(id, position + offset, Quaternion.LookRotation(handleDirection), size, EventType.Repaint);

                if (id == GUIUtility.hotControl || id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    Handles.color = temp;
                }
                break;
            }
            return(position);
        }
Exemplo n.º 22
0
        public static float DoCenter(int id, float value, Vector3 position, Quaternion rotation, float size, Handles.CapFunction capFunction, float snap)
        {
            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseMove:
            case EventType.Layout:
                capFunction(id, position, rotation, size * .15f, EventType.Layout);
                break;

            case EventType.MouseDown:
                // am I closest to the thingy?
                if (HandleUtility.nearestControl == id && evt.button == 0 && !evt.alt)
                {
                    GUIUtility.hotControl = id;         // Grab mouse focus
                    Tools.LockHandlePosition();
                    s_StartScale           = value;
                    s_CurrentMousePosition = s_StartMousePosition = evt.mousePosition;

                    var camera = SceneView.lastActiveSceneView.camera;
                    s_Direction = camera == null? Vector3.one : (camera.transform.right + camera.transform.up).normalized;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += evt.delta;
                    var dist = HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, position, s_Direction) / size;
                    value             = (Handles.SnapValue(dist, snap) + 1.0f) * s_StartScale;
                    s_ScaleDrawLength = value;
                    GUI.changed       = true;
                    evt.Use();
                }
                break;

            case EventType.KeyDown:
                if (GUIUtility.hotControl == id)
                {
                    // Cancel dragging on ESC
                    if (evt.keyCode == KeyCode.Escape)
                    {
                        Tools.UnlockHandlePosition();
                        s_ScaleDrawLength = 1.0f;
                    }
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    GUIUtility.hotControl = 0;
                    Tools.UnlockHandlePosition();
                    s_ScaleDrawLength = 1.0f;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.Repaint:
                Handles.SetupHandleColor(id, evt, out var prevColor, out var thickness);
                float capSize = size * .15f;
                if (Handles.IsHovering(id, evt))
                {
                    capSize *= Handles.s_HoverExtraScale;
                }
                capFunction(id, position, rotation, capSize, EventType.Repaint);
                Handles.color = prevColor;
                break;
            }

            return(value);
        }
Exemplo n.º 23
0
        void handle_Editor(string handleName, Vector3 _direction, Color _color, bool _active)
        {
            Vector3 handlePosition = handlePosition_Centor + fHandleSize * _direction * fHandleOffsetSize;

            if (_tile_Scene != null)// && _tile.coordinates.IsLastTile(_direction))
            {
                int controlID = 0;
#if UNITY_2017_2_OR_NEWER
                controlID = GUIUtility.GetControlID(handleName.GetHashCode(), FocusType.Passive);
#endif
                if (_active)
                {
                    Handles.color = _color;
                    Handles.DrawLine(handlePosition_Centor, handlePosition_Centor + fHandleSize * _direction);

                    using (var result = new EditorGUI.ChangeCheckScope())
                    {
                        if (bSingleCtlr)
                        {
                            WrapedFreeMoveHandle(controlID, handlePosition, Quaternion.identity,
                                                 fHandleSize * 0.15f, Vector3.zero, Handles.RectangleHandleCap);
                        }
                        else
                        {
                            WrapedFreeMoveHandle(controlID, handlePosition, Quaternion.identity,
                                                 fHandleSize * 0.25f, Vector3.zero, Handles.SphereHandleCap);
                        }

                        if (result.changed
#if UNITY_2017_2_OR_NEWER
                            && GUIUtility.hotControl == controlID
#endif
                            )
                        {
                            float fDragDistance = HandleUtility.CalcLineTranslation(
                                HandleUtility.WorldToGUIPoint(handlePosition),
                                Event.current.mousePosition, handlePosition, _direction);

                            float fHurdleDistance = Vector3.Scale(_direction,
                                                                  _tile_Scene.coordinates.GridInterval).magnitude;

                            _tile_Scene.Bulk.Do_With_SensorOff(() =>
                            {
                                if (fDragDistance >= fHurdleDistance)
                                {
                                    handle_Extrude(_direction, selectionType, bSingleCtlr, bWithAttachment);
                                }
                                else if (fDragDistance <= -fHurdleDistance)
                                {
                                    handle_Press(-_direction, bSingleCtlr);
                                }
                            });
                            _tile_Scene.Bulk.Update_ChildList();
                        }
                    }
                }
                else
                {
                    Handles.color = _color / 1.5f;
                    WrapedFreeMoveHandle(controlID,
                                         handlePosition, Quaternion.LookRotation(_direction),
                                         fHandleSize * 0.1f, Vector3.one, Handles.DotHandleCap);
                }
            }
        }
        private static Vector3 DoDragHandleAxis(DragAxisInfo axisInfo, Vector3 position, ref DragHandleResult result)
        {
            // Must request a control ID for each interactible control in the GUI that can respond to events
            int id = GUIUtility.GetControlID(axisInfo._handleHash, FocusType.Passive);

            float handleSize = HandleUtility.GetHandleSize(position);

            Camera camera = Camera.current;

            Event currentEvent = Event.current;

            Vector2 mousePos = HEU_EditorUI.GetMousePosition(ref currentEvent, camera);

            Vector3   handlePosition     = Handles.matrix.MultiplyPoint(position);
            Matrix4x4 cachedHandleMatrix = Handles.matrix;

            int mouseButtonID = Event.current.button;

            // Process events (using GetTypeForControl to filter events relevant to this control)
            switch (currentEvent.GetTypeForControl(id))
            {
            case EventType.MouseDown:
            {
                if (HandleUtility.nearestControl == id && (mouseButtonID == 0 || mouseButtonID == 1))
                {
                    GUIUtility.hotControl = id;

                    axisInfo._dragMouseCurrent = axisInfo._dragMouseStart = mousePos;
                    axisInfo._dragWorldStart   = position;
                    axisInfo._handleHasMoved   = false;

                    currentEvent.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);

                    if (mouseButtonID == 0)
                    {
                        result = DragHandleResult.LMB_PRESS;
                    }
                    else if (mouseButtonID == 1)
                    {
                        result = DragHandleResult.RMB_PRESS;
                    }
                }

                break;
            }

            case EventType.MouseUp:
            {
                if (GUIUtility.hotControl == id && (mouseButtonID == 0 || mouseButtonID == 1))
                {
                    GUIUtility.hotControl = 0;
                    currentEvent.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);

                    if (mouseButtonID == 0)
                    {
                        result = DragHandleResult.LMB_RELEASE;
                    }
                    else if (mouseButtonID == 1)
                    {
                        result = DragHandleResult.RMB_RELEASE;
                    }

                    // Double-click
                    if (mousePos == axisInfo._dragMouseStart)
                    {
                        bool doubleClick = (axisInfo._handleClickID == id) && (Time.realtimeSinceStartup - axisInfo._handleClickTime < _handleDoubleClikcInterval);

                        axisInfo._handleClickID   = id;
                        axisInfo._handleClickTime = Time.realtimeSinceStartup;

                        if (mouseButtonID == 0)
                        {
                            result = doubleClick ? DragHandleResult.LMB_DOUBLECLICK : DragHandleResult.LMB_CLICK;
                        }
                        else if (mouseButtonID == 1)
                        {
                            result = doubleClick ? DragHandleResult.RMB_DOUBLECLICK : DragHandleResult.RMB_CLICK;
                        }
                    }
                }

                break;
            }

            case EventType.MouseDrag:
            {
                if (GUIUtility.hotControl == id)
                {
                    if (axisInfo._dragAxis == DragAxis.ALL_AXIS)
                    {
                        // Free movement - (all axis)
                        // Flip y because Unity is inverted
                        axisInfo._dragMouseCurrent += new Vector2(currentEvent.delta.x, -currentEvent.delta.y);

                        Vector3 position2 = camera.WorldToScreenPoint(Handles.matrix.MultiplyPoint(axisInfo._dragWorldStart))
                                            + (Vector3)(axisInfo._dragMouseCurrent - axisInfo._dragMouseStart);

                        position = Handles.matrix.inverse.MultiplyPoint(camera.ScreenToWorldPoint(position2));
                    }
                    else
                    {
                        // Linear movement (constraint to current axis)

                        axisInfo._dragMouseCurrent += new Vector2(currentEvent.delta.x, currentEvent.delta.y);

                        float mag = HandleUtility.CalcLineTranslation(axisInfo._dragMouseStart, axisInfo._dragMouseCurrent, axisInfo._dragWorldStart, axisInfo._direction);
                        position = axisInfo._dragWorldStart + axisInfo._direction * mag;
                    }

                    if (mouseButtonID == 0)
                    {
                        result = DragHandleResult.LMB_DRAG;
                    }
                    else if (mouseButtonID == 1)
                    {
                        result = DragHandleResult.RMB_DRAG;
                    }

                    axisInfo._handleHasMoved = true;

                    GUI.changed = true;
                    currentEvent.Use();
                }

                break;
            }

            case EventType.MouseMove:
            case EventType.Repaint:
            {
                Color handleColor = Handles.color;
                if ((GUIUtility.hotControl == id && axisInfo._handleHasMoved) || (HandleUtility.nearestControl == id))
                {
                    Handles.color = Color.yellow;
                }
                else
                {
                    Handles.color = axisInfo._axisColor;
                }

                Handles.matrix = Matrix4x4.identity;
                if (axisInfo._dragAxis == DragAxis.ALL_AXIS)
                {
                    HEU_EditorUI.DrawCubeCap(id, handlePosition, Quaternion.identity, handleSize * 0.25f);
                }
                else
                {
                    HEU_EditorUI.DrawArrowCap(id, handlePosition, Quaternion.LookRotation(axisInfo._direction), handleSize);
                }
                Handles.matrix = cachedHandleMatrix;

                Handles.color = handleColor;

                // This forces a Repaint. We want this when we change the axis color due to being cursor being nearest.
                if (currentEvent.type == EventType.MouseMove && HandleUtility.nearestControl == id)
                {
                    SceneView.RepaintAll();
                }

                break;
            }

            case EventType.Layout:
            {
                // AddControl tells Unity where each Handle is relative to the current mouse position

                Handles.matrix = Matrix4x4.identity;
                if (axisInfo._dragAxis == DragAxis.ALL_AXIS)
                {
                    float distance = handleSize * 0.3f;
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(handlePosition, distance));
                }
                else
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToLine(handlePosition, handlePosition + axisInfo._direction * handleSize) * 0.4f);
                }
                Handles.matrix = cachedHandleMatrix;
                break;
            }
            }

            return(position);
        }
Exemplo n.º 25
0
        internal static Vector3 Do(int id, Vector3 position, Vector3 offset, Vector3 handleDirection, Vector3 slideDirection, float size, Handles.CapFunction capFunction, float snap)
        {
            Event evt       = Event.current;
            var   eventType = evt.GetTypeForControl(id);

            switch (eventType)
            {
            case EventType.Layout:
            case EventType.MouseMove:
                if (capFunction != null)
                {
                    capFunction(id, position + offset, Quaternion.LookRotation(handleDirection), size, eventType);
                }
                else
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + offset, size * .2f));
                }
                break;

            case EventType.MouseDown:
                // am I closest to the thingy?
                if (HandleUtility.nearestControl == id && evt.button == 0 && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    GUIUtility.hotControl  = id;       // Grab mouse focus
                    s_CurrentMousePosition = s_StartMousePosition = evt.mousePosition;
                    s_StartPosition        = position;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }

                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += evt.delta;
                    float dist = HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, slideDirection);

                    dist = Handles.SnapValue(dist, snap);

                    Vector3 worldDirection = Handles.matrix.MultiplyVector(slideDirection);
                    Vector3 worldPosition  = Handles.matrix.MultiplyPoint(s_StartPosition) + worldDirection * dist;

                    if (EditorSnapSettings.gridSnapActive)
                    {
                        worldPosition = Snapping.Snap(worldPosition, GridSettings.size, (SnapAxis) new SnapAxisFilter(worldDirection));
                    }

                    position = Handles.inverseMatrix.MultiplyPoint(worldPosition);

                    GUI.changed = true;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.Repaint:
                Color temp = Color.white;

                if (id == GUIUtility.hotControl)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.preselectionColor;
                }

                capFunction(id, position + offset, Quaternion.LookRotation(handleDirection), size, EventType.Repaint);

                if (id == GUIUtility.hotControl || id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    Handles.color = temp;
                }
                break;
            }
            return(position);
        }
Exemplo n.º 26
0
        public static Quaternion Do(int id, Quaternion rotation, Vector3 position, Vector3 axis, float size, bool cutoffPlane, float snap, bool enableRayDrag, bool showHotArc, Color fillColor)
        {
            var cam = Handles.inverseMatrix.MultiplyVector(Camera.current != null ? Camera.current.transform.forward : Vector3.forward);

            if (Mathf.Abs(Vector3.Dot(cam, axis)) > .999f)
            {
                cutoffPlane = false;
            }

            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            case EventType.MouseMove:
            {
                float d;
                if (cutoffPlane)
                {
                    Vector3 from = Vector3.Cross(axis, cam).normalized;
                    d = HandleUtility.DistanceToArc(position, axis, from, 180, size) * k_GrabZoneScale;
                }
                else
                {
                    d = HandleUtility.DistanceToDisc(position, axis, size) * k_GrabZoneScale;
                }

                HandleUtility.AddControl(id, d);
                break;
            }

            case EventType.MouseDown:
                // am I closest to the thingy?
                if (HandleUtility.nearestControl == id && evt.button == 0 && !evt.alt)
                {
                    GUIUtility.hotControl = id;        // Grab mouse focus
                    Tools.LockHandlePosition();
                    if (cutoffPlane)
                    {
                        Vector3 from = Vector3.Cross(axis, cam).normalized;
                        s_StartPosition = HandleUtility.ClosestPointToArc(position, axis, from, 180, size);
                    }
                    else
                    {
                        s_StartPosition = HandleUtility.ClosestPointToDisc(position, axis, size);
                    }
                    s_RotationDist         = 0;
                    s_StartRotation        = rotation;
                    s_StartAxis            = axis;
                    s_CurrentMousePosition = s_StartMousePosition = Event.current.mousePosition;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    // handle look to point rotation
                    bool rayDrag = EditorGUI.actionKey && evt.shift && enableRayDrag;
                    if (rayDrag)
                    {
                        if (HandleUtility.ignoreRaySnapObjects == null)
                        {
                            Handles.SetupIgnoreRaySnapObjects();
                        }
                        object hit = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(evt.mousePosition));
                        if (hit != null && Vector3.Dot(axis.normalized, rotation * Vector3.forward) < 0.999)
                        {
                            RaycastHit rh                 = (RaycastHit)hit;
                            Vector3    lookPoint          = rh.point - position;
                            Vector3    lookPointProjected = lookPoint - Vector3.Dot(lookPoint, axis.normalized) * axis.normalized;
                            rotation = Quaternion.LookRotation(lookPointProjected, rotation * Vector3.up);
                        }
                    }
                    else
                    {
                        Vector3 direction = Vector3.Cross(axis, position - s_StartPosition).normalized;
                        s_CurrentMousePosition += evt.delta;
                        s_RotationDist          = HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, direction) / size * 30;
                        s_RotationDist          = Handles.SnapValue(s_RotationDist, snap);
                        rotation = Quaternion.AngleAxis(s_RotationDist * -1, s_StartAxis) * s_StartRotation;
                    }

                    GUI.changed = true;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                {
                    Tools.UnlockHandlePosition();
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.KeyDown:
                if (evt.keyCode == KeyCode.Escape && GUIUtility.hotControl == id)
                {
                    // We do not use the event nor clear hotcontrol to ensure auto revert value kicks in from native side
                    Tools.UnlockHandlePosition();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.Repaint:
                Color temp = Color.white;

                if (id == GUIUtility.hotControl)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.preselectionColor;
                }

                // If we're dragging it, we'll go a bit further and draw a selection pie
                if (GUIUtility.hotControl == id)
                {
                    Color   t    = Handles.color;
                    Vector3 from = (s_StartPosition - position).normalized;
                    Handles.color = fillColor;
                    Handles.DrawLine(position, position + from * size);
                    var     d  = -Mathf.Sign(s_RotationDist) * Mathf.Repeat(Mathf.Abs(s_RotationDist), 360);
                    Vector3 to = Quaternion.AngleAxis(d, axis) * from;
                    Handles.DrawLine(position, position + to * size);

                    Handles.color = fillColor * new Color(1, 1, 1, .2f);
                    for (int i = 0, revolutions = (int)Mathf.Abs(s_RotationDist * 0.002777777778f); i < revolutions; ++i)
                    {
                        Handles.DrawSolidDisc(position, axis, size);
                    }
                    Handles.DrawSolidArc(position, axis, from, d, size);

                    // Draw snap markers
                    if (EditorSnapSettings.incrementalSnapActive && snap > 0)
                    {
                        DrawRotationUnitSnapMarkers(position, axis, size, k_RotationUnitSnapMarkerSize, snap, @from);
                        DrawRotationUnitSnapMarkers(position, axis, size, k_RotationUnitSnapMajorMarkerSize, k_RotationUnitSnapMajorMarkerStep, @from);
                    }
                    Handles.color = t;
                }

                if (showHotArc && GUIUtility.hotControl == id || GUIUtility.hotControl != id && !cutoffPlane)
                {
                    Handles.DrawWireDisc(position, axis, size);
                }
                else if (GUIUtility.hotControl != id && cutoffPlane)
                {
                    Vector3 from = Vector3.Cross(axis, cam).normalized;
                    Handles.DrawWireArc(position, axis, from, 180, size);
                }

                if (id == GUIUtility.hotControl || id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    Handles.color = temp;
                }
                break;
            }

            return(rotation);
        }
Exemplo n.º 27
0
#pragma warning disable 618
        internal static Vector3 Do(int id, Vector3 position, Vector3 handleDirection, Vector3 slideDirection, float size, Handles.DrawCapFunction drawFunc, float snap)
#pragma warning disable 618
        {
            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            case EventType.MouseMove:
                // This is an ugly hack. It would be better if the drawFunc can handle it's own layout.
                if (drawFunc == Handles.ArrowCap)
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToLine(position, position + slideDirection * size));
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + slideDirection * size, size * .2f));
                }
                else
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, size * .2f));
                }
                break;

            case EventType.MouseDown:
                // am I closest to the thingy?
                if ((HandleUtility.nearestControl == id && evt.button == 0) && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    GUIUtility.hotControl  = id;       // Grab mouse focus
                    s_CurrentMousePosition = s_StartMousePosition = evt.mousePosition;
                    s_StartPosition        = position;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }

                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += evt.delta;
                    float dist = HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, slideDirection);

                    dist = Handles.SnapValue(dist, snap);

                    Vector3 worldDirection = Handles.matrix.MultiplyVector(slideDirection);
                    Vector3 worldPosition  = Handles.matrix.MultiplyPoint(s_StartPosition) + worldDirection * dist;
                    position    = Handles.inverseMatrix.MultiplyPoint(worldPosition);
                    GUI.changed = true;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.Repaint:
                Color temp = Color.white;

                if (id == GUIUtility.hotControl)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.preselectionColor;
                }
                drawFunc(id, position, Quaternion.LookRotation(handleDirection), size);

                if (id == GUIUtility.hotControl || id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    Handles.color = temp;
                }
                break;
            }
            return(position);
        }
Exemplo n.º 28
0
        public static float DoAxis(int id, float scale, Vector3 position, Vector3 direction, Quaternion rotation, float size, bool snapping, float snap, CSGHandles.InitFunction initFunction, CSGHandles.InitFunction shutdownFunction)
        {
            var evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            {
                HandleUtility.AddControl(id, HandleUtility.DistanceToLine(position, position + direction * size));
                HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + direction * size, size * .2f));
                break;
            }

            case EventType.MouseDown:
            {
                if (CSGHandles.disabled)
                {
                    break;
                }
                if (((HandleUtility.nearestControl == id && evt.button == 0) ||
                     (GUIUtility.keyboardControl == id && evt.button == 2)) && GUIUtility.hotControl == 0)
                {
                    if (initFunction != null)
                    {
                        initFunction();
                    }
                    GUIUtility.hotControl  = GUIUtility.keyboardControl = id;
                    s_CurrentMousePosition = s_StartMousePosition = evt.mousePosition;
                    s_StartScale           = scale;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                break;
            }

            case EventType.MouseDrag:
            {
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += evt.delta;
                    float dist = 1 + HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, position, direction) / size;
                    dist        = SnapValue(dist, snap, snapping);
                    scale       = s_StartScale * dist;
                    GUI.changed = true;
                    evt.Use();
                }
                break;
            }

            case EventType.MouseUp:
            {
                if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    if (shutdownFunction != null)
                    {
                        shutdownFunction();
                    }
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;
            }

            case EventType.Repaint:
            {
                var originalColor = Handles.color;
                if (id == GUIUtility.keyboardControl)
                {
                    Handles.color = Handles.selectedColor;
                }
                else
                if (CSGHandles.disabled)
                {
                    Handles.color = Color.Lerp(originalColor, Handles.secondaryColor, 0.75f);
                }

                float s = size;
                if (GUIUtility.hotControl == id)
                {
                    s = size * scale / s_StartScale;
                }
#if UNITY_5_6_OR_NEWER
                Handles.ConeHandleCap(id, position + direction * s * s_ScaleDrawLength, rotation, size * .1f, EventType.repaint);
#else
                Handles.CubeCap(id, position + direction * s * s_ScaleDrawLength, rotation, size * .1f);
#endif
                Handles.DrawLine(position, position + direction * (s * s_ScaleDrawLength - size * .05f));

                Handles.color = originalColor;
                break;
            }
            }

            return(scale);
        }
Exemplo n.º 29
0
        internal static Vector3 Do(int id, Vector3 position, Vector3 handleDirection, Vector3 slideDirection, float size, Handles.CapFunction drawFunc, float snap)
#endif
        {
            Event current = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if ((HandleUtility.nearestControl == id && current.button == 0 || GUIUtility.keyboardControl == id && current.button == 2) && GUIUtility.hotControl == 0)
                {
                    int num2 = id;
                    GUIUtility.keyboardControl = num2;
                    GUIUtility.hotControl      = num2;
                    s_CurrentMousePosition     = s_StartMousePosition = current.mousePosition;
                    s_StartPosition            = position;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }
                return(position);

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                return(position);

            case EventType.MouseMove:
            case EventType.KeyDown:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
                return(position);

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += current.delta;
                    float   num    = Handles.SnapValue(HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, slideDirection), snap);
                    Vector3 vector = Handles.matrix.MultiplyVector(slideDirection);
                    Vector3 v      = Handles.matrix.MultiplyPoint(s_StartPosition) + vector * num;
                    position    = Handles.matrix.inverse.MultiplyPoint(v);
                    GUI.changed = true;
                    current.Use();
                }
                return(position);

            case EventType.Repaint:
            {
                Color white = Color.white;
                if (id == GUIUtility.keyboardControl && GUI.enabled)
                {
                    white         = Handles.color;
                    Handles.color = Color.green;
                }
#if !UNITY_5_6_OR_NEWER
                drawFunc(id, position, Quaternion.LookRotation(handleDirection), size);
#else
                drawFunc(id, position, Quaternion.LookRotation(handleDirection), size, current.type);
#endif
                if (id == GUIUtility.keyboardControl)
                {
                    Handles.color = white;
                }
                return(position);
            }

            case EventType.Layout:
#if !UNITY_5_6_OR_NEWER
                if (drawFunc != Handles.ArrowCap)
#else
                if (drawFunc != Handles.ArrowHandleCap)
#endif

                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, size * 0.2f));
                    return(position);
                }
                HandleUtility.AddControl(id, HandleUtility.DistanceToLine(position, position + slideDirection * size));
                HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + slideDirection * size, size * 0.2f));
                return(position);
            }
            return(position);
        }