Inheritance: ManipulationTool
Beispiel #1
0
        private static float DistanceToRectangle(Vector2[] screenPoints, Vector2 mousePos)
        {
            bool flag = false;
            int  num  = 4;

            for (int i = 0; i < 5; i++)
            {
                Vector3 vector  = screenPoints[i % 4];
                Vector3 vector2 = screenPoints[num % 4];
                if (vector.y > mousePos.y != vector2.y > mousePos.y && mousePos.x < (vector2.x - vector.x) * (mousePos.y - vector.y) / (vector2.y - vector.y) + vector.x)
                {
                    flag = !flag;
                }
                num = i;
            }
            if (!flag)
            {
                float num2 = -1f;
                for (int j = 0; j < 4; j++)
                {
                    Vector3 v    = screenPoints[j];
                    Vector3 v2   = screenPoints[(j + 1) % 4];
                    float   num3 = RectTool.DistancePointToLineSegment(mousePos, v, v2);
                    if (num3 < num2 || num2 < 0f)
                    {
                        num2 = num3;
                    }
                }
                return(num2);
            }
            return(0f);
        }
Beispiel #2
0
        private static Quaternion RotationHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            Vector3 eulerAngles = rotation.eulerAngles;

            for (int i = 0; i <= 2; i += 2)
            {
                for (int j = 0; j <= 2; j += 2)
                {
                    Vector3 rectPointInWorld = RectTool.GetRectPointInWorld(rect, pivot, rotation, i, j);
                    float   handleSize       = 0.05f * HandleUtility.GetHandleSize(rectPointInWorld);
                    int     controlID        = GUIUtility.GetControlID(RectTool.s_RotationHandlesHash, FocusType.Passive);
                    if (GUI.color.a > 0f || GUIUtility.hotControl == controlID)
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector3 outwardsDir  = rotation * Vector3.right * (float)(i - 1);
                        Vector3 outwardsDir2 = rotation * Vector3.up * (float)(j - 1);
                        float   num          = RectHandles.RotationSlider(controlID, rectPointInWorld, eulerAngles.z, pivot, rotation * Vector3.forward, outwardsDir, outwardsDir2, handleSize, null, Vector2.zero);
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (Event.current.shift)
                            {
                                num = Mathf.Round((num - eulerAngles.z) / 15f) * 15f + eulerAngles.z;
                            }
                            eulerAngles.z = num;
                            rotation      = Quaternion.Euler(eulerAngles);
                        }
                    }
                }
            }
            return(rotation);
        }
Beispiel #3
0
        private static Quaternion RotationHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            Vector3 eulerAngles = rotation.eulerAngles;
            int     xHandle     = 0;

            while (xHandle <= 2)
            {
                int yHandle = 0;
                while (yHandle <= 2)
                {
                    Vector3 rectPointInWorld = RectTool.GetRectPointInWorld(rect, pivot, rotation, xHandle, yHandle);
                    float   handleSize       = 0.05f * HandleUtility.GetHandleSize(rectPointInWorld);
                    int     controlId        = GUIUtility.GetControlID(RectTool.s_RotationHandlesHash, FocusType.Passive);
                    if ((double)GUI.color.a > 0.0 || GUIUtility.hotControl == controlId)
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector3 outwardsDir1 = rotation * Vector3.right * (float)(xHandle - 1);
                        Vector3 outwardsDir2 = rotation * Vector3.up * (float)(yHandle - 1);
                        float   num          = RectHandles.RotationSlider(controlId, rectPointInWorld, eulerAngles.z, pivot, rotation * Vector3.forward, outwardsDir1, outwardsDir2, handleSize, (Handles.DrawCapFunction)null, Vector2.zero);
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (Event.current.shift)
                            {
                                num = Mathf.Round((float)(((double)num - (double)eulerAngles.z) / 15.0)) * 15f + eulerAngles.z;
                            }
                            eulerAngles.z = num;
                            rotation      = Quaternion.Euler(eulerAngles);
                        }
                    }
                    yHandle += 2;
                }
                xHandle += 2;
            }
            return(rotation);
        }
Beispiel #4
0
        private static float DistanceToRectangle(Vector2[] screenPoints, Vector2 mousePos)
        {
            bool flag = false;
            int  num1 = 4;

            for (int index = 0; index < 5; ++index)
            {
                Vector3 screenPoint1 = (Vector3)screenPoints[index % 4];
                Vector3 screenPoint2 = (Vector3)screenPoints[num1 % 4];
                if ((double)screenPoint1.y > (double)mousePos.y != (double)screenPoint2.y > (double)mousePos.y && (double)mousePos.x < ((double)screenPoint2.x - (double)screenPoint1.x) * ((double)mousePos.y - (double)screenPoint1.y) / ((double)screenPoint2.y - (double)screenPoint1.y) + (double)screenPoint1.x)
                {
                    flag = !flag;
                }
                num1 = index;
            }
            if (flag)
            {
                return(0.0f);
            }
            float num2 = -1f;

            for (int index = 0; index < 4; ++index)
            {
                Vector3 screenPoint1 = (Vector3)screenPoints[index];
                Vector3 screenPoint2 = (Vector3)screenPoints[(index + 1) % 4];
                float   lineSegment  = RectTool.DistancePointToLineSegment(mousePos, (Vector2)screenPoint1, (Vector2)screenPoint2);
                if ((double)lineSegment < (double)num2 || (double)num2 < 0.0)
                {
                    num2 = lineSegment;
                }
            }
            return(num2);
        }
Beispiel #5
0
 public static void OnGUI(SceneView view)
 {
     if (RectTool.s_Instance == null)
     {
         RectTool.s_Instance = new RectTool();
     }
     RectTool.s_Instance.OnToolGUI(view);
 }
Beispiel #6
0
		public static void OnGUI(SceneView view)
		{
			if (RectTool.s_Instance == null)
			{
				RectTool.s_Instance = new RectTool();
			}
			RectTool.s_Instance.OnToolGUI(view);
		}
Beispiel #7
0
 private static float SceneViewDistanceToRectangle(Vector3[] worldPoints, Vector2 mousePos)
 {
     Vector2[] array = new Vector2[4];
     for (int i = 0; i < 4; i++)
     {
         array[i] = HandleUtility.WorldToGUIPoint(worldPoints[i]);
     }
     return(RectTool.DistanceToRectangle(array, mousePos));
 }
Beispiel #8
0
 private static float SceneViewDistanceToRectangle(Vector3[] worldPoints, Vector2 mousePos)
 {
     Vector2[] screenPoints = new Vector2[4];
     for (int index = 0; index < 4; ++index)
     {
         screenPoints[index] = HandleUtility.WorldToGUIPoint(worldPoints[index]);
     }
     return(RectTool.DistanceToRectangle(screenPoints, mousePos));
 }
Beispiel #9
0
        public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic)
        {
            Rect       handleRect         = Tools.handleRect;
            Quaternion handleRectRotation = Tools.handleRectRotation;

            Vector3[] array = new Vector3[4];
            for (int i = 0; i < 4; i++)
            {
                Vector3 point = RectTool.GetLocalRectPoint(handleRect, i);
                array[i] = handleRectRotation * point + handlePosition;
            }
            RectHandles.RenderRectWithShadow(false, array);
            Color color = GUI.color;

            if (Camera.current)
            {
                Vector3 planeNormal = (!Camera.current.orthographic) ? (handlePosition + handleRectRotation * handleRect.center - Camera.current.transform.position) : Camera.current.transform.forward;
                Vector3 vector      = handleRectRotation * Vector3.right * handleRect.width;
                Vector3 vector2     = handleRectRotation * Vector3.up * handleRect.height;
                float   num         = Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(vector, planeNormal), Vector3.ProjectOnPlane(vector2, planeNormal)).magnitude);
                num /= HandleUtility.GetHandleSize(handlePosition);
                float num2   = Mathf.Clamp01((num - 0.2f) / 0.2f * 2f);
                Color color2 = color;
                color2.a *= num2;
                GUI.color = color2;
            }
            Vector3 handlePosition2 = Tools.GetHandlePosition();

            if (!Tools.vertexDragging)
            {
                RectTransform component = Selection.activeTransform.GetComponent <RectTransform>();
                bool          flag      = Selection.transforms.Length > 1;
                bool          flag2     = !flag && Tools.pivotMode == PivotMode.Pivot && component != null;
                using (new EditorGUI.DisabledScope(!flag && !flag2))
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 a = RectTool.PivotHandleGUI(handleRect, handlePosition2, handleRectRotation);
                    if (EditorGUI.EndChangeCheck() && !isStatic)
                    {
                        if (flag)
                        {
                            Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (a - handlePosition2);
                        }
                        else if (flag2)
                        {
                            Transform activeTransform = Selection.activeTransform;
                            Undo.RecordObject(component, "Move Rectangle Pivot");
                            Transform transform = (!Tools.rectBlueprintMode || !InternalEditorUtility.SupportsRectLayout(activeTransform)) ? activeTransform : activeTransform.parent;
                            Vector2   b         = transform.InverseTransformVector(a - handlePosition2);
                            b.x /= component.rect.width;
                            b.y /= component.rect.height;
                            Vector2 vector3 = component.pivot + b;
                            RectTransformEditor.SetPivotSmart(component, vector3.x, 0, true, transform != component.transform);
                            RectTransformEditor.SetPivotSmart(component, vector3.y, 1, true, transform != component.transform);
                        }
                    }
                }
            }
            TransformManipulator.BeginManipulationHandling(true);
            if (!Tools.vertexDragging)
            {
                EditorGUI.BeginChangeCheck();
                Vector3 pivotPosition = handlePosition;
                Vector3 scaleDelta    = RectTool.ResizeHandlesGUI(handleRect, handlePosition, handleRectRotation, out pivotPosition);
                if (EditorGUI.EndChangeCheck() && !isStatic)
                {
                    TransformManipulator.SetResizeDelta(scaleDelta, pivotPosition, handleRectRotation);
                }
                bool flag3 = true;
                if (Tools.rectBlueprintMode)
                {
                    Transform[] transforms = Selection.transforms;
                    for (int j = 0; j < transforms.Length; j++)
                    {
                        Transform transform2 = transforms[j];
                        if (transform2.GetComponent <RectTransform>() != null)
                        {
                            flag3 = false;
                        }
                    }
                }
                if (flag3)
                {
                    EditorGUI.BeginChangeCheck();
                    Quaternion rhs = RectTool.RotationHandlesGUI(handleRect, handlePosition, handleRectRotation);
                    if (EditorGUI.EndChangeCheck() && !isStatic)
                    {
                        float   angle;
                        Vector3 vector4;
                        (Quaternion.Inverse(handleRectRotation) * rhs).ToAngleAxis(out angle, out vector4);
                        vector4 = handleRectRotation * vector4;
                        Undo.RecordObjects(Selection.transforms, "Rotate");
                        Transform[] transforms2 = Selection.transforms;
                        for (int k = 0; k < transforms2.Length; k++)
                        {
                            Transform transform3 = transforms2[k];
                            transform3.RotateAround(handlePosition, vector4, angle);
                            transform3.SetLocalEulerHint(transform3.GetLocalEulerAngles(transform3.rotationOrder));
                            if (transform3.parent != null)
                            {
                                transform3.SendTransformChangedScale();
                            }
                        }
                        Tools.handleRotation = Quaternion.AngleAxis(angle, vector4) * Tools.handleRotation;
                    }
                }
            }
            TransformManipulator.EndManipulationHandling();
            TransformManipulator.BeginManipulationHandling(false);
            EditorGUI.BeginChangeCheck();
            Vector3 vector5 = RectTool.MoveHandlesGUI(handleRect, handlePosition, handleRectRotation);

            if (EditorGUI.EndChangeCheck() && !isStatic)
            {
                if (GridSnapping.active)
                {
                    vector5 = GridSnapping.Snap(vector5);
                }
                if (TransformManipulator.HandleHasMoved(vector5))
                {
                    TransformManipulator.SetPositionDelta(vector5, TransformManipulator.mouseDownHandlePosition);
                }
            }
            TransformManipulator.EndManipulationHandling();
            GUI.color = color;
        }
Beispiel #10
0
        private static Vector3 MoveHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            int     controlID = GUIUtility.GetControlID(RectTool.s_MoveHandleHash, FocusType.Passive);
            Vector3 vector    = pivot;
            float   num       = HandleUtility.GetHandleSize(pivot) * 0.2f;
            float   num2      = 1f - GUI.color.a;

            Vector3[] array = new Vector3[]
            {
                rotation *new Vector2(rect.x, rect.y) + pivot,
                rotation *new Vector2(rect.xMax, rect.y) + pivot,
                rotation *new Vector2(rect.xMax, rect.yMax) + pivot,
                rotation *new Vector2(rect.x, rect.yMax) + pivot
            };
            VertexSnapping.HandleKeyAndMouseMove(controlID);
            bool      flag           = Selection.transforms.Length == 1 && InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation;
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(controlID);
            Plane     plane          = new Plane(array[0], array[1], array[2]);

            switch (typeForControl)
            {
            case EventType.MouseDown:
            {
                bool flag2 = Tools.vertexDragging || (current.button == 0 && current.modifiers == EventModifiers.None && RectHandles.RaycastGUIPointToWorldHit(current.mousePosition, plane, out RectTool.s_StartMouseWorldPos) && (RectTool.SceneViewDistanceToRectangle(array, current.mousePosition) == 0f || (num2 > 0f && RectTool.SceneViewDistanceToDisc(pivot, rotation * Vector3.forward, num, current.mousePosition) == 0f)));
                if (flag2)
                {
                    RectTool.s_StartPosition = pivot;
                    RectTool.s_StartMousePos = (RectTool.s_CurrentMousePos = current.mousePosition);
                    RectTool.s_Moving        = false;
                    RectTool.s_LockAxis      = -1;
                    int num3 = controlID;
                    GUIUtility.keyboardControl = num3;
                    GUIUtility.hotControl      = num3;
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    HandleUtility.ignoreRaySnapObjects = null;
                    current.Use();
                    if (flag)
                    {
                        Transform     activeTransform = Selection.activeTransform;
                        RectTransform component       = activeTransform.GetComponent <RectTransform>();
                        Transform     parent          = activeTransform.parent;
                        RectTransform component2      = parent.GetComponent <RectTransform>();
                        RectTool.s_StartRectPosition = component.anchoredPosition;
                        RectTransformSnapping.CalculatePositionSnapValues(parent, activeTransform, component2, component);
                    }
                }
                break;
            }

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    if (!RectTool.s_Moving)
                    {
                        Selection.activeGameObject = SceneViewPicking.PickGameObject(current.mousePosition);
                    }
                    GUIUtility.hotControl = 0;
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    HandleUtility.ignoreRaySnapObjects = null;
                    current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    RectTool.s_CurrentMousePos += current.delta;
                    if (!RectTool.s_Moving && (RectTool.s_CurrentMousePos - RectTool.s_StartMousePos).magnitude > 3f)
                    {
                        RectTool.s_Moving = true;
                        RectHandles.RaycastGUIPointToWorldHit(RectTool.s_CurrentMousePos, plane, out RectTool.s_StartMouseWorldPos);
                    }
                    if (RectTool.s_Moving)
                    {
                        if (Tools.vertexDragging)
                        {
                            if (HandleUtility.ignoreRaySnapObjects == null)
                            {
                                Handles.SetupIgnoreRaySnapObjects();
                            }
                            Vector3 vector2;
                            if (HandleUtility.FindNearestVertex(RectTool.s_CurrentMousePos, null, out vector2))
                            {
                                vector      = vector2;
                                GUI.changed = true;
                            }
                            ManipulationToolUtility.minDragDifference = Vector2.zero;
                        }
                        else
                        {
                            ManipulationToolUtility.SetMinDragDifferenceForPos(pivot);
                            Vector3 a;
                            if (RectHandles.RaycastGUIPointToWorldHit(RectTool.s_CurrentMousePos, plane, out a))
                            {
                                Vector3 vector3 = a - RectTool.s_StartMouseWorldPos;
                                if (current.shift)
                                {
                                    vector3 = Quaternion.Inverse(rotation) * vector3;
                                    if (RectTool.s_LockAxis == -1)
                                    {
                                        RectTool.s_LockAxis = ((Mathf.Abs(vector3.x) <= Mathf.Abs(vector3.y)) ? 1 : 0);
                                    }
                                    vector3[1 - RectTool.s_LockAxis] = 0f;
                                    vector3 = rotation * vector3;
                                }
                                else
                                {
                                    RectTool.s_LockAxis = -1;
                                }
                                if (flag)
                                {
                                    Transform parent2 = Selection.activeTransform.parent;
                                    Vector3   vector4 = RectTool.s_StartRectPosition + parent2.InverseTransformVector(vector3);
                                    vector4.z = 0f;
                                    Quaternion rotation2    = Quaternion.Inverse(rotation);
                                    Vector2    snapDistance = Vector2.one * HandleUtility.GetHandleSize(vector) * 0.05f;
                                    snapDistance.x /= (rotation2 * parent2.TransformVector(Vector3.right)).x;
                                    snapDistance.y /= (rotation2 * parent2.TransformVector(Vector3.up)).y;
                                    Vector3 vector5 = RectTransformSnapping.SnapToGuides(vector4, snapDistance);
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(vector4, vector5);
                                    vector3 = parent2.TransformVector(vector5 - RectTool.s_StartRectPosition);
                                }
                                vector      = RectTool.s_StartPosition + vector3;
                                GUI.changed = true;
                            }
                        }
                    }
                    current.Use();
                }
                break;

            case EventType.Repaint:
                if (Tools.vertexDragging)
                {
                    RectHandles.RectScalingHandleCap(controlID, pivot, rotation, 1f, EventType.Repaint);
                }
                else
                {
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 1.5f * num2);
                    Handles.CircleHandleCap(controlID, pivot, rotation, num, EventType.Repaint);
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 0.3f * num2);
                    Handles.DrawSolidDisc(pivot, rotation * Vector3.forward, num);
                }
                break;
            }
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPosX", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPosY", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", typeForControl);
            return(vector);
        }
Beispiel #11
0
        private static Vector3 ResizeHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation, out Vector3 scalePivot)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                RectTool.s_StartRect = rect;
            }
            scalePivot = pivot;
            Vector3    result    = Vector3.one;
            Quaternion rotation2 = Quaternion.Inverse(rotation);

            for (int i = 0; i <= 2; i++)
            {
                for (int j = 0; j <= 2; j++)
                {
                    if (i != 1 || j != 1)
                    {
                        Vector3 rectPointInWorld  = RectTool.GetRectPointInWorld(RectTool.s_StartRect, pivot, rotation, i, j);
                        Vector3 rectPointInWorld2 = RectTool.GetRectPointInWorld(rect, pivot, rotation, i, j);
                        float   num       = 0.05f * HandleUtility.GetHandleSize(rectPointInWorld2);
                        int     controlID = GUIUtility.GetControlID(RectTool.s_ResizeHandlesHash, FocusType.Passive);
                        if (GUI.color.a > 0f || GUIUtility.hotControl == controlID)
                        {
                            EditorGUI.BeginChangeCheck();
                            EventType type = Event.current.type;
                            Vector3   vector;
                            if (i == 1 || j == 1)
                            {
                                Vector3 sideVector = (i != 1) ? (rotation * Vector3.up * rect.height) : (rotation * Vector3.right * rect.width);
                                Vector3 direction  = (i != 1) ? (rotation * Vector3.right) : (rotation * Vector3.up);
                                vector = RectHandles.SideSlider(controlID, rectPointInWorld2, sideVector, direction, num, null, 0f);
                            }
                            else
                            {
                                Vector3 vector2   = rotation * Vector3.right * (float)(i - 1);
                                Vector3 vector3   = rotation * Vector3.up * (float)(j - 1);
                                int     arg_1AB_0 = controlID;
                                Vector3 arg_1AB_1 = rectPointInWorld2;
                                Vector3 arg_1AB_2 = rotation * Vector3.forward;
                                Vector3 arg_1AB_3 = vector2;
                                Vector3 arg_1AB_4 = vector3;
                                float   arg_1AB_5 = num;
                                if (RectTool.< > f__mg$cache0 == null)
                                {
                                    RectTool.< > f__mg$cache0 = new Handles.CapFunction(RectHandles.RectScalingHandleCap);
                                }
                                vector = RectHandles.CornerSlider(arg_1AB_0, arg_1AB_1, arg_1AB_2, arg_1AB_3, arg_1AB_4, arg_1AB_5, RectTool.< > f__mg$cache0, Vector2.zero);
                            }
                            bool flag = Selection.transforms.Length == 1 && InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation;
                            if (flag)
                            {
                                Transform     activeTransform = Selection.activeTransform;
                                RectTransform component       = activeTransform.GetComponent <RectTransform>();
                                Transform     parent          = activeTransform.parent;
                                RectTransform component2      = parent.GetComponent <RectTransform>();
                                if (type == EventType.MouseDown && Event.current.type != EventType.MouseDown)
                                {
                                    RectTransformSnapping.CalculateOffsetSnapValues(parent, activeTransform, component2, component, i, j);
                                }
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                ManipulationToolUtility.SetMinDragDifferenceForPos(rectPointInWorld2, 0.1f);
                                if (flag)
                                {
                                    Transform     parent2      = Selection.activeTransform.parent;
                                    RectTransform component3   = parent2.GetComponent <RectTransform>();
                                    Vector2       snapDistance = Vector2.one * HandleUtility.GetHandleSize(vector) * 0.05f;
                                    snapDistance.x /= (rotation2 * parent2.TransformVector(Vector3.right)).x;
                                    snapDistance.y /= (rotation2 * parent2.TransformVector(Vector3.up)).y;
                                    Vector3 vector4 = parent2.InverseTransformPoint(vector) - component3.rect.min;
                                    Vector3 vector5 = RectTransformSnapping.SnapToGuides(vector4, snapDistance) + Vector3.forward * vector4.z;
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(vector4, vector5);
                                    vector = parent2.TransformPoint(vector5 + component3.rect.min);
                                }
                                bool alt       = Event.current.alt;
                                bool actionKey = EditorGUI.actionKey;
                                bool flag2     = Event.current.shift && !actionKey;
                                if (!alt)
                                {
                                    scalePivot = RectTool.GetRectPointInWorld(RectTool.s_StartRect, pivot, rotation, 2 - i, 2 - j);
                                }
                                if (flag2)
                                {
                                    vector = Vector3.Project(vector - scalePivot, rectPointInWorld - scalePivot) + scalePivot;
                                }
                                Vector3 vector6 = rotation2 * (rectPointInWorld - scalePivot);
                                Vector3 vector7 = rotation2 * (vector - scalePivot);
                                if (i != 1)
                                {
                                    result.x = vector7.x / vector6.x;
                                }
                                if (j != 1)
                                {
                                    result.y = vector7.y / vector6.y;
                                }
                                if (flag2)
                                {
                                    float d = (i != 1) ? result.x : result.y;
                                    result = Vector3.one * d;
                                }
                                if (actionKey && i == 1)
                                {
                                    if (Event.current.shift)
                                    {
                                        result.x = (result.z = 1f / Mathf.Sqrt(Mathf.Max(result.y, 0.0001f)));
                                    }
                                    else
                                    {
                                        result.x = 1f / Mathf.Max(result.y, 0.0001f);
                                    }
                                }
                                if (flag2)
                                {
                                    float d2 = (i != 1) ? result.x : result.y;
                                    result = Vector3.one * d2;
                                }
                                if (actionKey && i == 1)
                                {
                                    if (Event.current.shift)
                                    {
                                        result.x = (result.z = 1f / Mathf.Sqrt(Mathf.Max(result.y, 0.0001f)));
                                    }
                                    else
                                    {
                                        result.x = 1f / Mathf.Max(result.y, 0.0001f);
                                    }
                                }
                                if (actionKey && j == 1)
                                {
                                    if (Event.current.shift)
                                    {
                                        result.y = (result.z = 1f / Mathf.Sqrt(Mathf.Max(result.x, 0.0001f)));
                                    }
                                    else
                                    {
                                        result.y = 1f / Mathf.Max(result.x, 0.0001f);
                                    }
                                }
                            }
                            if (i == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", type);
                            }
                            if (i == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", type);
                            }
                            if (i != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingWidth", type);
                            }
                            if (j == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", type);
                            }
                            if (j == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", type);
                            }
                            if (j != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingHeight", type);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Beispiel #12
0
        public override void ToolGUI(SceneView view, Vector3 handlePosition, bool isStatic)
        {
            Rect       handleRect         = Tools.handleRect;
            Quaternion handleRectRotation = Tools.handleRectRotation;

            Vector3[] vector3Array = new Vector3[4];
            for (int index = 0; index < 4; ++index)
            {
                Vector3 localRectPoint = (Vector3)RectTool.GetLocalRectPoint(handleRect, index);
                vector3Array[index] = handleRectRotation * localRectPoint + handlePosition;
            }
            RectHandles.RenderRectWithShadow(false, vector3Array);
            Color color1 = GUI.color;

            if ((bool)((Object)Camera.current))
            {
                Vector3 planeNormal = !Camera.current.orthographic ? handlePosition + handleRectRotation * (Vector3)handleRect.center - Camera.current.transform.position : Camera.current.transform.forward;
                Vector3 vector1     = handleRectRotation * Vector3.right * handleRect.width;
                Vector3 vector2     = handleRectRotation * Vector3.up * handleRect.height;
                float   num         = Mathf.Clamp01((float)(((double)(Mathf.Sqrt(Vector3.Cross(Vector3.ProjectOnPlane(vector1, planeNormal), Vector3.ProjectOnPlane(vector2, planeNormal)).magnitude) / HandleUtility.GetHandleSize(handlePosition)) - 0.200000002980232) / 0.200000002980232 * 2.0));
                Color   color2      = color1;
                color2.a *= num;
                GUI.color = color2;
            }
            Vector3 handlePosition1 = Tools.GetHandlePosition();

            if (!Tools.vertexDragging)
            {
                RectTransform component = Selection.activeTransform.GetComponent <RectTransform>();
                bool          flag1     = Selection.transforms.Length > 1;
                bool          flag2     = !flag1 && Tools.pivotMode == PivotMode.Pivot && (Object)component != (Object)null;
                EditorGUI.BeginDisabledGroup(!flag1 && !flag2);
                EditorGUI.BeginChangeCheck();
                Vector3 vector3 = RectTool.PivotHandleGUI(handleRect, handlePosition1, handleRectRotation);
                if (EditorGUI.EndChangeCheck() && !isStatic)
                {
                    if (flag1)
                    {
                        Tools.localHandleOffset += Quaternion.Inverse(Tools.handleRotation) * (vector3 - handlePosition1);
                    }
                    else if (flag2)
                    {
                        Transform activeTransform = Selection.activeTransform;
                        Undo.RecordObject((Object)component, "Move Rectangle Pivot");
                        Transform transform = !Tools.rectBlueprintMode || !InternalEditorUtility.SupportsRectLayout(activeTransform) ? activeTransform : activeTransform.parent;
                        Vector2   vector2_1 = (Vector2)transform.InverseTransformVector(vector3 - handlePosition1);
                        vector2_1.x /= component.rect.width;
                        vector2_1.y /= component.rect.height;
                        Vector2 vector2_2 = component.pivot + vector2_1;
                        RectTransformEditor.SetPivotSmart(component, vector2_2.x, 0, true, (Object)transform != (Object)component.transform);
                        RectTransformEditor.SetPivotSmart(component, vector2_2.y, 1, true, (Object)transform != (Object)component.transform);
                    }
                }
                EditorGUI.EndDisabledGroup();
            }
            TransformManipulator.BeginManipulationHandling(true);
            if (!Tools.vertexDragging)
            {
                EditorGUI.BeginChangeCheck();
                Vector3 scalePivot = handlePosition;
                Vector3 scaleDelta = RectTool.ResizeHandlesGUI(handleRect, handlePosition, handleRectRotation, out scalePivot);
                if (EditorGUI.EndChangeCheck() && !isStatic)
                {
                    TransformManipulator.SetResizeDelta(scaleDelta, scalePivot, handleRectRotation);
                }
                bool flag = true;
                if (Tools.rectBlueprintMode)
                {
                    foreach (Component transform in Selection.transforms)
                    {
                        if ((Object)transform.GetComponent <RectTransform>() != (Object)null)
                        {
                            flag = false;
                        }
                    }
                }
                if (flag)
                {
                    EditorGUI.BeginChangeCheck();
                    Quaternion quaternion = RectTool.RotationHandlesGUI(handleRect, handlePosition, handleRectRotation);
                    if (EditorGUI.EndChangeCheck() && !isStatic)
                    {
                        float   angle;
                        Vector3 axis1;
                        (Quaternion.Inverse(handleRectRotation) * quaternion).ToAngleAxis(out angle, out axis1);
                        Vector3 axis2 = handleRectRotation * axis1;
                        Undo.RecordObjects((Object[])Selection.transforms, "Rotate");
                        foreach (Transform transform in Selection.transforms)
                        {
                            transform.RotateAround(handlePosition, axis2, angle);
                            if ((Object)transform.parent != (Object)null)
                            {
                                transform.SendTransformChangedScale();
                            }
                        }
                        Tools.handleRotation = Quaternion.AngleAxis(angle, axis2) * Tools.handleRotation;
                    }
                }
            }
            int num1 = (int)TransformManipulator.EndManipulationHandling();

            TransformManipulator.BeginManipulationHandling(false);
            EditorGUI.BeginChangeCheck();
            Vector3 vector3_1 = RectTool.MoveHandlesGUI(handleRect, handlePosition, handleRectRotation);

            if (EditorGUI.EndChangeCheck() && !isStatic)
            {
                TransformManipulator.SetPositionDelta(vector3_1 - TransformManipulator.mouseDownHandlePosition);
            }
            int num2 = (int)TransformManipulator.EndManipulationHandling();

            GUI.color = color1;
        }
Beispiel #13
0
        private static Vector3 MoveHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            int     controlId = GUIUtility.GetControlID(RectTool.s_MoveHandleHash, FocusType.Passive);
            Vector3 position  = pivot;
            float   num1      = HandleUtility.GetHandleSize(pivot) * 0.2f;
            float   num2      = 1f - GUI.color.a;

            Vector3[] worldPoints = new Vector3[4] {
                rotation *(Vector3) new Vector2(rect.x, rect.y) + pivot, rotation *(Vector3) new Vector2(rect.xMax, rect.y) + pivot, rotation *(Vector3) new Vector2(rect.xMax, rect.yMax) + pivot, rotation *(Vector3) new Vector2(rect.x, rect.yMax) + pivot
            };
            VertexSnapping.HandleKeyAndMouseMove(controlId);
            bool      flag           = Selection.transforms.Length == 1 && InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation;
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(controlId);
            Plane     plane          = new Plane(worldPoints[0], worldPoints[1], worldPoints[2]);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (Tools.vertexDragging || current.button == 0 && current.modifiers == EventModifiers.None && RectHandles.RaycastGUIPointToWorldHit(current.mousePosition, plane, out RectTool.s_StartMouseWorldPos) && ((double)RectTool.SceneViewDistanceToRectangle(worldPoints, current.mousePosition) == 0.0 || (double)num2 > 0.0 && (double)RectTool.SceneViewDistanceToDisc(pivot, rotation * Vector3.forward, num1, current.mousePosition) == 0.0))
                {
                    RectTool.s_StartPosition = pivot;
                    RectTool.s_StartMousePos = RectTool.s_CurrentMousePos = current.mousePosition;
                    RectTool.s_Moving        = false;
                    RectTool.s_LockAxis      = -1;
                    int num3 = controlId;
                    GUIUtility.keyboardControl = num3;
                    GUIUtility.hotControl      = num3;
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    HandleUtility.ignoreRaySnapObjects = (Transform[])null;
                    current.Use();
                    if (flag)
                    {
                        Transform     activeTransform = Selection.activeTransform;
                        RectTransform component1      = activeTransform.GetComponent <RectTransform>();
                        Transform     parent          = activeTransform.parent;
                        RectTransform component2      = parent.GetComponent <RectTransform>();
                        RectTool.s_StartRectPosition = (Vector3)component1.anchoredPosition;
                        RectTransformSnapping.CalculatePositionSnapValues(parent, activeTransform, component2, component1);
                        break;
                    }
                    break;
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlId)
                {
                    if (!RectTool.s_Moving)
                    {
                        Selection.activeGameObject = SceneViewPicking.PickGameObject(current.mousePosition);
                    }
                    GUIUtility.hotControl = 0;
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    HandleUtility.ignoreRaySnapObjects = (Transform[])null;
                    current.Use();
                    break;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlId)
                {
                    RectTool.s_CurrentMousePos += current.delta;
                    if (!RectTool.s_Moving && (double)(RectTool.s_CurrentMousePos - RectTool.s_StartMousePos).magnitude > 3.0)
                    {
                        RectTool.s_Moving = true;
                        RectHandles.RaycastGUIPointToWorldHit(RectTool.s_CurrentMousePos, plane, out RectTool.s_StartMouseWorldPos);
                    }
                    if (RectTool.s_Moving)
                    {
                        if (Tools.vertexDragging)
                        {
                            if (HandleUtility.ignoreRaySnapObjects == null)
                            {
                                Handles.SetupIgnoreRaySnapObjects();
                            }
                            Vector3 vertex;
                            if (HandleUtility.FindNearestVertex(RectTool.s_CurrentMousePos, (Transform[])null, out vertex))
                            {
                                position    = vertex;
                                GUI.changed = true;
                            }
                            ManipulationToolUtility.minDragDifference = (Vector3)Vector2.zero;
                        }
                        else
                        {
                            ManipulationToolUtility.SetMinDragDifferenceForPos(pivot);
                            Vector3 hit;
                            if (RectHandles.RaycastGUIPointToWorldHit(RectTool.s_CurrentMousePos, plane, out hit))
                            {
                                Vector3 vector = hit - RectTool.s_StartMouseWorldPos;
                                if (current.shift)
                                {
                                    vector = Quaternion.Inverse(rotation) * vector;
                                    if (RectTool.s_LockAxis == -1)
                                    {
                                        RectTool.s_LockAxis = (double)Mathf.Abs(vector.x) <= (double)Mathf.Abs(vector.y) ? 1 : 0;
                                    }
                                    vector[1 - RectTool.s_LockAxis] = 0.0f;
                                    vector = rotation * vector;
                                }
                                else
                                {
                                    RectTool.s_LockAxis = -1;
                                }
                                if (flag)
                                {
                                    Transform parent = Selection.activeTransform.parent;
                                    Vector3   positionBeforeSnapping = RectTool.s_StartRectPosition + parent.InverseTransformVector(vector);
                                    positionBeforeSnapping.z = 0.0f;
                                    Quaternion quaternion   = Quaternion.Inverse(rotation);
                                    Vector2    snapDistance = Vector2.one * HandleUtility.GetHandleSize(position) * 0.05f;
                                    snapDistance.x /= (quaternion * parent.TransformVector(Vector3.right)).x;
                                    snapDistance.y /= (quaternion * parent.TransformVector(Vector3.up)).y;
                                    Vector3 guides = (Vector3)RectTransformSnapping.SnapToGuides((Vector2)positionBeforeSnapping, snapDistance);
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(positionBeforeSnapping, guides);
                                    vector = parent.TransformVector(guides - RectTool.s_StartRectPosition);
                                }
                                position    = RectTool.s_StartPosition + vector;
                                GUI.changed = true;
                            }
                        }
                    }
                    current.Use();
                    break;
                }
                break;

            case EventType.Repaint:
                if (Tools.vertexDragging)
                {
                    RectHandles.RectScalingCap(controlId, pivot, rotation, 1f);
                    break;
                }
                Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 1.5f * num2);
                Handles.CircleCap(controlId, pivot, rotation, num1);
                Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 0.3f * num2);
                Handles.DrawSolidDisc(pivot, rotation * Vector3.forward, num1);
                break;
            }
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPosX", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPosY", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", typeForControl);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", typeForControl);
            return(position);
        }
Beispiel #14
0
        private static Vector3 ResizeHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation, out Vector3 scalePivot)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                RectTool.s_StartRect = rect;
            }
            scalePivot = pivot;
            Vector3    vector3_1  = Vector3.one;
            Quaternion quaternion = Quaternion.Inverse(rotation);

            for (int xHandle = 0; xHandle <= 2; ++xHandle)
            {
                for (int yHandle = 0; yHandle <= 2; ++yHandle)
                {
                    if (xHandle != 1 || yHandle != 1)
                    {
                        Vector3 rectPointInWorld1 = RectTool.GetRectPointInWorld(RectTool.s_StartRect, pivot, rotation, xHandle, yHandle);
                        Vector3 rectPointInWorld2 = RectTool.GetRectPointInWorld(rect, pivot, rotation, xHandle, yHandle);
                        float   num       = 0.05f * HandleUtility.GetHandleSize(rectPointInWorld2);
                        int     controlId = GUIUtility.GetControlID(RectTool.s_ResizeHandlesHash, FocusType.Passive);
                        if ((double)GUI.color.a > 0.0 || GUIUtility.hotControl == controlId)
                        {
                            EditorGUI.BeginChangeCheck();
                            EventType type = Event.current.type;
                            Vector3   position;
                            if (xHandle == 1 || yHandle == 1)
                            {
                                Vector3 sideVector = xHandle != 1 ? rotation * Vector3.up * rect.height : rotation * Vector3.right * rect.width;
                                Vector3 direction  = xHandle != 1 ? rotation * Vector3.right : rotation * Vector3.up;
                                position = RectHandles.SideSlider(controlId, rectPointInWorld2, sideVector, direction, num, (Handles.DrawCapFunction)null, 0.0f);
                            }
                            else
                            {
                                Vector3 outwardsDir1 = rotation * Vector3.right * (float)(xHandle - 1);
                                Vector3 outwardsDir2 = rotation * Vector3.up * (float)(yHandle - 1);
                                position = RectHandles.CornerSlider(controlId, rectPointInWorld2, rotation * Vector3.forward, outwardsDir1, outwardsDir2, num, new Handles.DrawCapFunction(RectHandles.RectScalingCap), Vector2.zero);
                            }
                            bool flag1 = Selection.transforms.Length == 1 && InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) && Selection.activeTransform.parent.rotation == rotation;
                            if (flag1)
                            {
                                Transform     activeTransform = Selection.activeTransform;
                                RectTransform component1      = activeTransform.GetComponent <RectTransform>();
                                Transform     parent          = activeTransform.parent;
                                RectTransform component2      = parent.GetComponent <RectTransform>();
                                if (type == EventType.MouseDown && Event.current.type != EventType.MouseDown)
                                {
                                    RectTransformSnapping.CalculateOffsetSnapValues(parent, activeTransform, component2, component1, xHandle, yHandle);
                                }
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                ManipulationToolUtility.SetMinDragDifferenceForPos(rectPointInWorld2);
                                if (flag1)
                                {
                                    Transform     parent       = Selection.activeTransform.parent;
                                    RectTransform component    = parent.GetComponent <RectTransform>();
                                    Vector2       snapDistance = Vector2.one * HandleUtility.GetHandleSize(position) * 0.05f;
                                    snapDistance.x /= (quaternion * parent.TransformVector(Vector3.right)).x;
                                    snapDistance.y /= (quaternion * parent.TransformVector(Vector3.up)).y;
                                    Vector3 positionBeforeSnapping = parent.InverseTransformPoint(position) - (Vector3)component.rect.min;
                                    Vector3 positionAfterSnapping  = (Vector3)RectTransformSnapping.SnapToGuides((Vector2)positionBeforeSnapping, snapDistance) + Vector3.forward * positionBeforeSnapping.z;
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(positionBeforeSnapping, positionAfterSnapping);
                                    position = parent.TransformPoint(positionAfterSnapping + (Vector3)component.rect.min);
                                }
                                bool alt       = Event.current.alt;
                                bool actionKey = EditorGUI.actionKey;
                                bool flag2     = Event.current.shift && !actionKey;
                                if (!alt)
                                {
                                    scalePivot = RectTool.GetRectPointInWorld(RectTool.s_StartRect, pivot, rotation, 2 - xHandle, 2 - yHandle);
                                }
                                if (flag2)
                                {
                                    position = Vector3.Project(position - scalePivot, rectPointInWorld1 - scalePivot) + scalePivot;
                                }
                                Vector3 vector3_2 = quaternion * (rectPointInWorld1 - scalePivot);
                                Vector3 vector3_3 = quaternion * (position - scalePivot);
                                if (xHandle != 1)
                                {
                                    vector3_1.x = vector3_3.x / vector3_2.x;
                                }
                                if (yHandle != 1)
                                {
                                    vector3_1.y = vector3_3.y / vector3_2.y;
                                }
                                if (flag2)
                                {
                                    vector3_1 = Vector3.one * (xHandle != 1 ? vector3_1.x : vector3_1.y);
                                }
                                if (actionKey && xHandle == 1)
                                {
                                    vector3_1.x = !Event.current.shift ? 1f / Mathf.Max(vector3_1.y, 0.0001f) : (vector3_1.z = 1f / Mathf.Sqrt(Mathf.Max(vector3_1.y, 0.0001f)));
                                }
                                if (flag2)
                                {
                                    vector3_1 = Vector3.one * (xHandle != 1 ? vector3_1.x : vector3_1.y);
                                }
                                if (actionKey && xHandle == 1)
                                {
                                    vector3_1.x = !Event.current.shift ? 1f / Mathf.Max(vector3_1.y, 0.0001f) : (vector3_1.z = 1f / Mathf.Sqrt(Mathf.Max(vector3_1.y, 0.0001f)));
                                }
                                if (actionKey && yHandle == 1)
                                {
                                    vector3_1.y = !Event.current.shift ? 1f / Mathf.Max(vector3_1.x, 0.0001f) : (vector3_1.z = 1f / Mathf.Sqrt(Mathf.Max(vector3_1.x, 0.0001f)));
                                }
                            }
                            if (xHandle == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", type);
                            }
                            if (xHandle == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", type);
                            }
                            if (xHandle != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingWidth", type);
                            }
                            if (yHandle == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", type);
                            }
                            if (yHandle == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", type);
                            }
                            if (yHandle != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingHeight", type);
                            }
                        }
                    }
                }
            }
            return(vector3_1);
        }