internal static void CalculatePositionSnapValues(Transform parentSpace, Transform self, RectTransform parentRect, RectTransform rect)
 {
     for (int index = 0; index < 2; ++index)
     {
         RectTransformSnapping.s_SnapGuides[index].Clear();
     }
     if ((Object)parentSpace == (Object)null)
     {
         return;
     }
     for (int axis = 0; axis < 2; ++axis)
     {
         for (int side = 0; side < RectTransformSnapping.kSidesAndMiddle.Length; ++side)
         {
             using (List <SnapGuide> .Enumerator enumerator = RectTransformSnapping.GetSnapGuides(parentSpace, self, parentRect, rect, axis, side).GetEnumerator())
             {
                 while (enumerator.MoveNext())
                 {
                     SnapGuide current = enumerator.Current;
                     current.value = RectTransformSnapping.GetGuideValueForRect(rect, current.value, axis, RectTransformSnapping.kSidesAndMiddle[side]);
                     RectTransformSnapping.s_SnapGuides[axis].AddGuide(current);
                 }
             }
         }
     }
 }
Esempio n. 2
0
        private static Vector3 PivotHandleGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            int       controlID      = GUIUtility.GetControlID(RectTool.s_PivotHandleHash, FocusType.Passive);
            EventType typeForControl = Event.current.GetTypeForControl(controlID);

            if (GUI.color.a > 0f || GUIUtility.hotControl == controlID)
            {
                EventType eventType = typeForControl;
                EditorGUI.BeginChangeCheck();
                Vector3 a = Handles.Slider2D(controlID, pivot, rotation * Vector3.forward, rotation * Vector3.right, rotation * Vector3.up, HandleUtility.GetHandleSize(pivot) * 0.1f, new Handles.DrawCapFunction(RectHandles.PivotCap), Vector2.zero);
                if (eventType == EventType.MouseDown && GUIUtility.hotControl == controlID)
                {
                    RectTransformSnapping.CalculatePivotSnapValues(rect, pivot, rotation);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    Vector2 vector = Quaternion.Inverse(rotation) * (a - pivot);
                    vector.x /= rect.width;
                    vector.y /= rect.height;
                    Vector2 vector2      = new Vector2(-rect.x / rect.width, -rect.y / rect.height);
                    Vector2 vector3      = vector2 + vector;
                    Vector2 snapDistance = HandleUtility.GetHandleSize(pivot) * 0.05f * new Vector2(1f / rect.width, 1f / rect.height);
                    vector3   = RectTransformSnapping.SnapToGuides(vector3, snapDistance);
                    vector    = vector3 - vector2;
                    vector.x *= rect.width;
                    vector.y *= rect.height;
                    pivot    += rotation * vector;
                }
            }
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingPivot", typeForControl);
            return(pivot);
        }
        private static List <SnapGuide> GetSnapGuides(Transform parentSpace, Transform self, RectTransform parentRect, RectTransform rect, int axis, int side)
        {
            List <SnapGuide> list = new List <SnapGuide>();

            if (parentRect != null)
            {
                float num  = RectTransformSnapping.kSidesAndMiddle[side];
                float num2 = Mathf.Lerp(rect.anchorMin[axis], rect.anchorMax[axis], num);
                list.Add(new SnapGuide(num2 * parentRect.rect.size[axis], RectTransformSnapping.GetGuideLineForRect(parentRect, axis, num2)));
                float num3 = Mathf.Lerp(rect.anchorMin[axis], rect.anchorMax[axis], num);
                if (num != num3)
                {
                    list.Add(new SnapGuide(num * parentRect.rect.size[axis], false, RectTransformSnapping.GetGuideLineForRect(parentRect, axis, num)));
                }
            }
            IEnumerator enumerator = parentSpace.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    Transform transform = (Transform)enumerator.Current;
                    if (!(transform == self))
                    {
                        RectTransform component = transform.GetComponent <RectTransform>();
                        if (component)
                        {
                            if (side == 0)
                            {
                                bool safe = component.anchorMin[axis] == rect.anchorMin[axis];
                                list.Add(new SnapGuide(component.GetRectInParentSpace().min[axis], safe, RectTransformSnapping.GetGuideLineForRect(component, axis, 0f)));
                                safe = (component.anchorMax[axis] == rect.anchorMin[axis]);
                                list.Add(new SnapGuide(component.GetRectInParentSpace().max[axis], safe, RectTransformSnapping.GetGuideLineForRect(component, axis, 1f)));
                            }
                            if (side == 2)
                            {
                                bool safe = component.anchorMax[axis] == rect.anchorMax[axis];
                                list.Add(new SnapGuide(component.GetRectInParentSpace().max[axis], safe, RectTransformSnapping.GetGuideLineForRect(component, axis, 1f)));
                                safe = (component.anchorMin[axis] == rect.anchorMax[axis]);
                                list.Add(new SnapGuide(component.GetRectInParentSpace().min[axis], safe, RectTransformSnapping.GetGuideLineForRect(component, axis, 0f)));
                            }
                            if (side == 1)
                            {
                                bool safe = component.anchorMin[axis] - rect.anchorMin[axis] == -(component.anchorMax[axis] - rect.anchorMax[axis]);
                                list.Add(new SnapGuide(component.GetRectInParentSpace().center[axis], safe, RectTransformSnapping.GetGuideLineForRect(component, axis, 0.5f)));
                            }
                        }
                    }
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            return(list);
        }
 internal static void CalculateOffsetSnapValues(Transform parentSpace, Transform self, RectTransform parentRect, RectTransform rect, int xHandle, int yHandle)
 {
     for (int index = 0; index < 2; ++index)
     {
         RectTransformSnapping.s_SnapGuides[index].Clear();
     }
     if ((Object)parentSpace == (Object)null)
     {
         return;
     }
     for (int axis = 0; axis < 2; ++axis)
     {
         int side = axis != 0 ? yHandle : xHandle;
         if (side != 1)
         {
             using (List <SnapGuide> .Enumerator enumerator = RectTransformSnapping.GetSnapGuides(parentSpace, self, parentRect, rect, axis, side).GetEnumerator())
             {
                 while (enumerator.MoveNext())
                 {
                     SnapGuide current = enumerator.Current;
                     RectTransformSnapping.s_SnapGuides[axis].AddGuide(current);
                 }
             }
         }
     }
 }
 internal static void CalculateAnchorSnapValues(Transform parentSpace, Transform self, RectTransform gui, int minmaxX, int minmaxY)
 {
     for (int i = 0; i < 2; i++)
     {
         RectTransformSnapping.s_SnapGuides[i].Clear();
         RectTransform component = parentSpace.GetComponent <RectTransform>();
         component.GetWorldCorners(RectTransformSnapping.s_Corners);
         for (int j = 0; j < RectTransformSnapping.kSidesAndMiddle.Length; j++)
         {
             float num = RectTransformSnapping.kSidesAndMiddle[j];
             RectTransformSnapping.s_SnapGuides[i].AddGuide(new SnapGuide(num, new Vector3[]
             {
                 RectTransformSnapping.GetInterpolatedCorner(RectTransformSnapping.s_Corners, i, num, 0f),
                 RectTransformSnapping.GetInterpolatedCorner(RectTransformSnapping.s_Corners, i, num, 1f)
             }));
         }
         IEnumerator enumerator = parentSpace.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 Transform transform = (Transform)enumerator.Current;
                 if (!(transform == self))
                 {
                     RectTransform component2 = transform.GetComponent <RectTransform>();
                     if (component2)
                     {
                         RectTransformSnapping.s_SnapGuides[i].AddGuide(new SnapGuide(component2.anchorMin[i], new Vector3[0]));
                         RectTransformSnapping.s_SnapGuides[i].AddGuide(new SnapGuide(component2.anchorMax[i], new Vector3[0]));
                     }
                 }
             }
         }
         finally
         {
             IDisposable disposable;
             if ((disposable = (enumerator as IDisposable)) != null)
             {
                 disposable.Dispose();
             }
         }
         int num2 = (i != 0) ? minmaxY : minmaxX;
         if (num2 == 0)
         {
             RectTransformSnapping.s_SnapGuides[i].AddGuide(new SnapGuide(gui.anchorMax[i], new Vector3[0]));
         }
         if (num2 == 1)
         {
             RectTransformSnapping.s_SnapGuides[i].AddGuide(new SnapGuide(gui.anchorMin[i], new Vector3[0]));
         }
     }
 }
        private static List <SnapGuide> GetSnapGuides(Transform parentSpace, Transform self, RectTransform parentRect, RectTransform rect, int axis, int side)
        {
            List <SnapGuide> list = new List <SnapGuide>();

            if (parentRect != null)
            {
                float num  = RectTransformSnapping.kSidesAndMiddle[side];
                float num2 = Mathf.Lerp(rect.anchorMin[axis], rect.anchorMax[axis], num);
                list.Add(new SnapGuide(num2 * parentRect.rect.size[axis], RectTransformSnapping.GetGuideLineForRect(parentRect, axis, num2)));
                float num3 = Mathf.Lerp(rect.anchorMin[axis], rect.anchorMax[axis], num);
                if (num != num3)
                {
                    list.Add(new SnapGuide(num * parentRect.rect.size[axis], false, RectTransformSnapping.GetGuideLineForRect(parentRect, axis, num)));
                }
            }
            foreach (Transform transform in parentSpace)
            {
                if (!(transform == self))
                {
                    RectTransform component = transform.GetComponent <RectTransform>();
                    if (component)
                    {
                        if (side == 0)
                        {
                            bool safe = component.anchorMin[axis] == rect.anchorMin[axis];
                            list.Add(new SnapGuide(component.GetRectInParentSpace().min[axis], safe, RectTransformSnapping.GetGuideLineForRect(component, axis, 0f)));
                            safe = (component.anchorMax[axis] == rect.anchorMin[axis]);
                            list.Add(new SnapGuide(component.GetRectInParentSpace().max[axis], safe, RectTransformSnapping.GetGuideLineForRect(component, axis, 1f)));
                        }
                        if (side == 2)
                        {
                            bool safe = component.anchorMax[axis] == rect.anchorMax[axis];
                            list.Add(new SnapGuide(component.GetRectInParentSpace().max[axis], safe, RectTransformSnapping.GetGuideLineForRect(component, axis, 1f)));
                            safe = (component.anchorMin[axis] == rect.anchorMax[axis]);
                            list.Add(new SnapGuide(component.GetRectInParentSpace().min[axis], safe, RectTransformSnapping.GetGuideLineForRect(component, axis, 0f)));
                        }
                        if (side == 1)
                        {
                            bool safe = component.anchorMin[axis] - rect.anchorMin[axis] == -(component.anchorMax[axis] - rect.anchorMax[axis]);
                            list.Add(new SnapGuide(component.GetRectInParentSpace().center[axis], safe, RectTransformSnapping.GetGuideLineForRect(component, axis, 0.5f)));
                        }
                    }
                }
            }
            return(list);
        }
        private static List <SnapGuide> GetSnapGuides(Transform parentSpace, Transform self, RectTransform parentRect, RectTransform rect, int axis, int side)
        {
            List <SnapGuide> snapGuideList = new List <SnapGuide>();

            if ((Object)parentRect != (Object)null)
            {
                float num1  = RectTransformSnapping.kSidesAndMiddle[side];
                float side1 = Mathf.Lerp(rect.anchorMin[axis], rect.anchorMax[axis], num1);
                snapGuideList.Add(new SnapGuide(side1 * parentRect.rect.size[axis], RectTransformSnapping.GetGuideLineForRect(parentRect, axis, side1)));
                float num2 = Mathf.Lerp(rect.anchorMin[axis], rect.anchorMax[axis], num1);
                if ((double)num1 != (double)num2)
                {
                    snapGuideList.Add(new SnapGuide(num1 * parentRect.rect.size[axis], false, RectTransformSnapping.GetGuideLineForRect(parentRect, axis, num1)));
                }
            }
            foreach (Transform transform in parentSpace)
            {
                if (!((Object)transform == (Object)self))
                {
                    RectTransform component = transform.GetComponent <RectTransform>();
                    if ((bool)((Object)component))
                    {
                        if (side == 0)
                        {
                            bool safe1 = (double)component.anchorMin[axis] == (double)rect.anchorMin[axis];
                            snapGuideList.Add(new SnapGuide(component.GetRectInParentSpace().min[axis], safe1, RectTransformSnapping.GetGuideLineForRect(component, axis, 0.0f)));
                            bool safe2 = (double)component.anchorMax[axis] == (double)rect.anchorMin[axis];
                            snapGuideList.Add(new SnapGuide(component.GetRectInParentSpace().max[axis], safe2, RectTransformSnapping.GetGuideLineForRect(component, axis, 1f)));
                        }
                        if (side == 2)
                        {
                            bool safe1 = (double)component.anchorMax[axis] == (double)rect.anchorMax[axis];
                            snapGuideList.Add(new SnapGuide(component.GetRectInParentSpace().max[axis], safe1, RectTransformSnapping.GetGuideLineForRect(component, axis, 1f)));
                            bool safe2 = (double)component.anchorMin[axis] == (double)rect.anchorMax[axis];
                            snapGuideList.Add(new SnapGuide(component.GetRectInParentSpace().min[axis], safe2, RectTransformSnapping.GetGuideLineForRect(component, axis, 0.0f)));
                        }
                        if (side == 1)
                        {
                            bool safe = (double)component.anchorMin[axis] - (double)rect.anchorMin[axis] == -((double)component.anchorMax[axis] - (double)rect.anchorMax[axis]);
                            snapGuideList.Add(new SnapGuide(component.GetRectInParentSpace().center[axis], safe, RectTransformSnapping.GetGuideLineForRect(component, axis, 0.5f)));
                        }
                    }
                }
            }
            return(snapGuideList);
        }
 internal static void CalculatePositionSnapValues(Transform parentSpace, Transform self, RectTransform parentRect, RectTransform rect)
 {
     for (int i = 0; i < 2; i++)
     {
         RectTransformSnapping.s_SnapGuides[i].Clear();
     }
     if (!(parentSpace == null))
     {
         for (int j = 0; j < 2; j++)
         {
             for (int k = 0; k < RectTransformSnapping.kSidesAndMiddle.Length; k++)
             {
                 List <SnapGuide> snapGuides = RectTransformSnapping.GetSnapGuides(parentSpace, self, parentRect, rect, j, k);
                 foreach (SnapGuide current in snapGuides)
                 {
                     current.value = RectTransformSnapping.GetGuideValueForRect(rect, current.value, j, RectTransformSnapping.kSidesAndMiddle[k]);
                     RectTransformSnapping.s_SnapGuides[j].AddGuide(current);
                 }
             }
         }
     }
 }
 internal static void CalculateOffsetSnapValues(Transform parentSpace, Transform self, RectTransform parentRect, RectTransform rect, int xHandle, int yHandle)
 {
     for (int i = 0; i < 2; i++)
     {
         RectTransformSnapping.s_SnapGuides[i].Clear();
     }
     if (!(parentSpace == null))
     {
         for (int j = 0; j < 2; j++)
         {
             int num = (j != 0) ? yHandle : xHandle;
             if (num != 1)
             {
                 List <SnapGuide> snapGuides = RectTransformSnapping.GetSnapGuides(parentSpace, self, parentRect, rect, j, num);
                 foreach (SnapGuide current in snapGuides)
                 {
                     RectTransformSnapping.s_SnapGuides[j].AddGuide(current);
                 }
             }
         }
     }
 }
Esempio n. 10
0
 internal static void CalculateAnchorSnapValues(Transform parentSpace, Transform self, RectTransform gui, int minmaxX, int minmaxY)
 {
     for (int i = 0; i < 2; i++)
     {
         RectTransformSnapping.s_SnapGuides[i].Clear();
         RectTransform component = parentSpace.GetComponent <RectTransform>();
         component.GetWorldCorners(RectTransformSnapping.s_Corners);
         for (int j = 0; j < RectTransformSnapping.kSidesAndMiddle.Length; j++)
         {
             float num = RectTransformSnapping.kSidesAndMiddle[j];
             RectTransformSnapping.s_SnapGuides[i].AddGuide(new SnapGuide(num, new Vector3[]
             {
                 RectTransformSnapping.GetInterpolatedCorner(RectTransformSnapping.s_Corners, i, num, 0f),
                 RectTransformSnapping.GetInterpolatedCorner(RectTransformSnapping.s_Corners, i, num, 1f)
             }));
         }
         foreach (Transform transform in parentSpace)
         {
             if (!(transform == self))
             {
                 RectTransform component2 = transform.GetComponent <RectTransform>();
                 if (component2)
                 {
                     RectTransformSnapping.s_SnapGuides[i].AddGuide(new SnapGuide(component2.anchorMin[i], new Vector3[0]));
                     RectTransformSnapping.s_SnapGuides[i].AddGuide(new SnapGuide(component2.anchorMax[i], new Vector3[0]));
                 }
             }
         }
         int num2 = (i != 0) ? minmaxY : minmaxX;
         if (num2 == 0)
         {
             RectTransformSnapping.s_SnapGuides[i].AddGuide(new SnapGuide(gui.anchorMax[i], new Vector3[0]));
         }
         if (num2 == 1)
         {
             RectTransformSnapping.s_SnapGuides[i].AddGuide(new SnapGuide(gui.anchorMin[i], new Vector3[0]));
         }
     }
 }
Esempio n. 11
0
        static Vector3 PivotHandleGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            int       id        = GUIUtility.GetControlID(s_PivotHandleHash, FocusType.Passive);
            EventType eventType = Event.current.GetTypeForControl(id);

            if (GUI.color.a > 0 || GUIUtility.hotControl == id)
            {
                EventType typeBefore = eventType;

                EditorGUI.BeginChangeCheck();
                Vector3 newPivot = Handles.Slider2D(id, pivot, rotation * Vector3.forward, rotation * Vector3.right, rotation * Vector3.up, HandleUtility.GetHandleSize(pivot) * 0.1f, RectHandles.PivotHandleCap, Vector2.zero);

                if (typeBefore == EventType.MouseDown && GUIUtility.hotControl == id)
                {
                    RectTransformSnapping.CalculatePivotSnapValues(rect, pivot, rotation);
                }

                if (EditorGUI.EndChangeCheck())
                {
                    Vector2 offset = Quaternion.Inverse(rotation) * (newPivot - pivot);
                    offset.x /= rect.width;
                    offset.y /= rect.height;
                    Vector2 pivotCoordBefore = new Vector2(-rect.x / rect.width, -rect.y / rect.height);
                    Vector2 pivotCoordAfter  = pivotCoordBefore + offset;

                    Vector2 snapSize = HandleUtility.GetHandleSize(pivot) * RectTransformSnapping.kSnapThreshold * new Vector2(1 / rect.width, 1 / rect.height);
                    pivotCoordAfter = RectTransformSnapping.SnapToGuides(pivotCoordAfter, snapSize);

                    offset    = (pivotCoordAfter - pivotCoordBefore);
                    offset.x *= rect.width;
                    offset.y *= rect.height;
                    pivot    += rotation * offset;
                }
            }
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingPivot, eventType);

            return(pivot);
        }
 internal static void CalculateAnchorSnapValues(Transform parentSpace, Transform self, RectTransform gui, int minmaxX, int minmaxY)
 {
     for (int mainAxis = 0; mainAxis < 2; ++mainAxis)
     {
         RectTransformSnapping.s_SnapGuides[mainAxis].Clear();
         parentSpace.GetComponent <RectTransform>().GetWorldCorners(RectTransformSnapping.s_Corners);
         for (int index = 0; index < RectTransformSnapping.kSidesAndMiddle.Length; ++index)
         {
             float alongMainAxis = RectTransformSnapping.kSidesAndMiddle[index];
             RectTransformSnapping.s_SnapGuides[mainAxis].AddGuide(new SnapGuide(alongMainAxis, new Vector3[2]
             {
                 RectTransformSnapping.GetInterpolatedCorner(RectTransformSnapping.s_Corners, mainAxis, alongMainAxis, 0.0f),
                 RectTransformSnapping.GetInterpolatedCorner(RectTransformSnapping.s_Corners, mainAxis, alongMainAxis, 1f)
             }));
         }
         foreach (Transform transform in parentSpace)
         {
             if (!((Object)transform == (Object)self))
             {
                 RectTransform component = transform.GetComponent <RectTransform>();
                 if ((bool)((Object)component))
                 {
                     RectTransformSnapping.s_SnapGuides[mainAxis].AddGuide(new SnapGuide(component.anchorMin[mainAxis], new Vector3[0]));
                     RectTransformSnapping.s_SnapGuides[mainAxis].AddGuide(new SnapGuide(component.anchorMax[mainAxis], new Vector3[0]));
                 }
             }
         }
         int num = mainAxis != 0 ? minmaxY : minmaxX;
         if (num == 0)
         {
             RectTransformSnapping.s_SnapGuides[mainAxis].AddGuide(new SnapGuide(gui.anchorMax[mainAxis], new Vector3[0]));
         }
         if (num == 1)
         {
             RectTransformSnapping.s_SnapGuides[mainAxis].AddGuide(new SnapGuide(gui.anchorMin[mainAxis], new Vector3[0]));
         }
     }
 }
Esempio n. 13
0
 internal static void CalculatePivotSnapValues(Rect rect, Vector3 pivot, Quaternion rotation)
 {
     for (int i = 0; i < 2; i++)
     {
         RectTransformSnapping.s_SnapGuides[i].Clear();
         for (int j = 0; j < RectTransformSnapping.kSidesAndMiddle.Length; j++)
         {
             RectTransformSnapping.s_SnapGuides[i].AddGuide(new SnapGuide(RectTransformSnapping.kSidesAndMiddle[j], RectTransformSnapping.GetGuideLineForRect(rect, pivot, rotation, i, RectTransformSnapping.kSidesAndMiddle[j])));
         }
     }
 }
 internal static void CalculatePivotSnapValues(Rect rect, Vector3 pivot, Quaternion rotation)
 {
     for (int axis = 0; axis < 2; ++axis)
     {
         RectTransformSnapping.s_SnapGuides[axis].Clear();
         for (int index = 0; index < RectTransformSnapping.kSidesAndMiddle.Length; ++index)
         {
             RectTransformSnapping.s_SnapGuides[axis].AddGuide(new SnapGuide(RectTransformSnapping.kSidesAndMiddle[index], RectTransformSnapping.GetGuideLineForRect(rect, pivot, rotation, axis, RectTransformSnapping.kSidesAndMiddle[index])));
         }
     }
 }
Esempio n. 15
0
        private static Vector3 ResizeHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation, out Vector3 scalePivot)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                s_StartRect = rect;
            }
            scalePivot = pivot;
            Vector3    one        = Vector3.one;
            Quaternion quaternion = Quaternion.Inverse(rotation);

            for (int i = 0; i <= 2; i++)
            {
                for (int j = 0; j <= 2; j++)
                {
                    if ((i != 1) || (j != 1))
                    {
                        Vector3 vector2   = GetRectPointInWorld(s_StartRect, pivot, rotation, i, j);
                        Vector3 position  = GetRectPointInWorld(rect, pivot, rotation, i, j);
                        float   size      = 0.05f * HandleUtility.GetHandleSize(position);
                        int     controlID = GUIUtility.GetControlID(s_ResizeHandlesHash, FocusType.Passive);
                        if ((GUI.color.a > 0f) || (GUIUtility.hotControl == controlID))
                        {
                            Vector3 vector4;
                            EditorGUI.BeginChangeCheck();
                            EventType typeBefore = Event.current.type;
                            if ((i == 1) || (j == 1))
                            {
                                Vector3 sideVector = (i != 1) ? ((Vector3)((rotation * Vector3.up) * rect.height)) : ((Vector3)((rotation * Vector3.right) * rect.width));
                                Vector3 direction  = (i != 1) ? ((Vector3)(rotation * Vector3.right)) : ((Vector3)(rotation * Vector3.up));
                                vector4 = RectHandles.SideSlider(controlID, position, sideVector, direction, size, null, 0f);
                            }
                            else
                            {
                                Vector3 vector7 = (Vector3)((rotation * Vector3.right) * (i - 1));
                                Vector3 vector8 = (Vector3)((rotation * Vector3.up) * (j - 1));
                                vector4 = RectHandles.CornerSlider(controlID, position, (Vector3)(rotation * Vector3.forward), vector7, vector8, size, new Handles.DrawCapFunction(RectHandles.RectScalingCap), 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 parentRect      = parent.GetComponent <RectTransform>();
                                if ((typeBefore == EventType.MouseDown) && (Event.current.type != EventType.MouseDown))
                                {
                                    RectTransformSnapping.CalculateOffsetSnapValues(parent, activeTransform, parentRect, component, i, j);
                                }
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                ManipulationToolUtility.SetMinDragDifferenceForPos(position);
                                if (flag)
                                {
                                    Transform     transform5   = Selection.activeTransform.parent;
                                    RectTransform transform6   = transform5.GetComponent <RectTransform>();
                                    Vector2       snapDistance = (Vector2)((Vector2.one * HandleUtility.GetHandleSize(vector4)) * 0.05f);
                                    Vector3       vector14     = (Vector3)(quaternion * transform5.TransformVector(Vector3.right));
                                    snapDistance.x /= vector14.x;
                                    Vector3 vector15 = (Vector3)(quaternion * transform5.TransformVector(Vector3.up));
                                    snapDistance.y /= vector15.y;
                                    Vector3 vector10 = transform5.InverseTransformPoint(vector4) - transform6.rect.min;
                                    Vector3 positionAfterSnapping = (Vector3)(RectTransformSnapping.SnapToGuides(vector10, snapDistance) + (Vector3.forward * vector10.z));
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(vector10, positionAfterSnapping);
                                    vector4 = transform5.TransformPoint(positionAfterSnapping + transform6.rect.min);
                                }
                                bool alt       = Event.current.alt;
                                bool actionKey = EditorGUI.actionKey;
                                bool flag4     = Event.current.shift && !actionKey;
                                if (!alt)
                                {
                                    scalePivot = GetRectPointInWorld(s_StartRect, pivot, rotation, 2 - i, 2 - j);
                                }
                                if (flag4)
                                {
                                    vector4 = Vector3.Project(vector4 - scalePivot, vector2 - scalePivot) + scalePivot;
                                }
                                Vector3 vector12 = (Vector3)(quaternion * (vector2 - scalePivot));
                                Vector3 vector13 = (Vector3)(quaternion * (vector4 - scalePivot));
                                if (i != 1)
                                {
                                    one.x = vector13.x / vector12.x;
                                }
                                if (j != 1)
                                {
                                    one.y = vector13.y / vector12.y;
                                }
                                if (flag4)
                                {
                                    float num5 = (i != 1) ? one.x : one.y;
                                    one = (Vector3)(Vector3.one * num5);
                                }
                                if (actionKey && (i == 1))
                                {
                                    if (Event.current.shift)
                                    {
                                        one.x = one.z = 1f / Mathf.Sqrt(Mathf.Max(one.y, 0.0001f));
                                    }
                                    else
                                    {
                                        one.x = 1f / Mathf.Max(one.y, 0.0001f);
                                    }
                                }
                                if (flag4)
                                {
                                    float num6 = (i != 1) ? one.x : one.y;
                                    one = (Vector3)(Vector3.one * num6);
                                }
                                if (actionKey && (i == 1))
                                {
                                    if (Event.current.shift)
                                    {
                                        one.x = one.z = 1f / Mathf.Sqrt(Mathf.Max(one.y, 0.0001f));
                                    }
                                    else
                                    {
                                        one.x = 1f / Mathf.Max(one.y, 0.0001f);
                                    }
                                }
                                if (actionKey && (j == 1))
                                {
                                    if (Event.current.shift)
                                    {
                                        one.y = one.z = 1f / Mathf.Sqrt(Mathf.Max(one.x, 0.0001f));
                                    }
                                    else
                                    {
                                        one.y = 1f / Mathf.Max(one.x, 0.0001f);
                                    }
                                }
                            }
                            switch (i)
                            {
                            case 0:
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingLeft", typeBefore);
                                break;

                            case 2:
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingRight", typeBefore);
                                break;
                            }
                            if (i != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingWidth", typeBefore);
                            }
                            if (j == 0)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingBottom", typeBefore);
                            }
                            if (j == 2)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingTop", typeBefore);
                            }
                            if (j != 1)
                            {
                                ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp("ChangingHeight", typeBefore);
                            }
                        }
                    }
                }
            }
            return(one);
        }
 internal static Vector2 SnapToGuides(Vector2 value, Vector2 snapDistance)
 {
     return(new Vector2(RectTransformSnapping.SnapToGuides(value.x, snapDistance.x, 0), RectTransformSnapping.SnapToGuides(value.y, snapDistance.y, 1)));
 }
Esempio n. 17
0
        private static Vector3 MoveHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            bool    flag2;
            int     controlID = GUIUtility.GetControlID(s_MoveHandleHash, FocusType.Passive);
            Vector3 position  = pivot;
            float   radius    = HandleUtility.GetHandleSize(pivot) * 0.2f;
            float   num3      = 1f - GUI.color.a;

            Vector3[] worldPoints = 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(worldPoints[0], worldPoints[1], worldPoints[2]);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                flag2 = false;
                if (!Tools.vertexDragging)
                {
                    flag2 = (((current.button == 0) && (current.modifiers == EventModifiers.None)) && RectHandles.RaycastGUIPointToWorldHit(current.mousePosition, plane, out s_StartMouseWorldPos)) && ((SceneViewDistanceToRectangle(worldPoints, current.mousePosition) == 0f) || ((num3 > 0f) && (SceneViewDistanceToDisc(pivot, (Vector3)(rotation * Vector3.forward), radius, current.mousePosition) == 0f)));
                    break;
                }
                flag2 = true;
                break;

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

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

            case EventType.Repaint:
                if (!Tools.vertexDragging)
                {
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 1.5f * num3);
                    Handles.CircleCap(controlID, pivot, rotation, radius);
                    Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 0.3f * num3);
                    Handles.DrawSolidDisc(pivot, (Vector3)(rotation * Vector3.forward), radius);
                }
                else
                {
                    RectHandles.RectScalingHandleCap(controlID, pivot, rotation, 1f, EventType.Repaint);
                }
                goto Label_0620;

            default:
                goto Label_0620;
            }
            if (flag2)
            {
                s_StartPosition = pivot;
                s_StartMousePos = s_CurrentMousePos = current.mousePosition;
                s_Moving        = false;
                s_LockAxis      = -1;
                int num4 = controlID;
                GUIUtility.keyboardControl = num4;
                GUIUtility.hotControl      = num4;
                EditorGUIUtility.SetWantsMouseJumping(1);
                HandleUtility.ignoreRaySnapObjects = null;
                current.Use();
                if (flag)
                {
                    Transform     activeTransform = Selection.activeTransform;
                    RectTransform component       = activeTransform.GetComponent <RectTransform>();
                    Transform     parentSpace     = activeTransform.parent;
                    RectTransform parentRect      = parentSpace.GetComponent <RectTransform>();
                    s_StartRectPosition = (Vector3)component.anchoredPosition;
                    RectTransformSnapping.CalculatePositionSnapValues(parentSpace, activeTransform, parentRect, component);
                }
            }
Label_0620:
            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);
        }
Esempio n. 18
0
        static Vector3 ResizeHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation, out Vector3 scalePivot)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                s_StartRect = rect;
            }

            scalePivot = pivot;
            Vector3 scale = Vector3.one;

            Quaternion inverseRotation = Quaternion.Inverse(rotation);

            // Loop through the 8 handles (sides and corners) using a nested loop.
            // (The loop covers 9 combinations, but the center position is ignored.)
            for (int xHandle = 0; xHandle <= 2; xHandle++)
            {
                for (int yHandle = 0; yHandle <= 2; yHandle++)
                {
                    // Ignore center
                    if (xHandle == 1 && yHandle == 1)
                    {
                        continue;
                    }

                    Vector3 origPos = GetRectPointInWorld(s_StartRect, pivot, rotation, xHandle, yHandle);
                    Vector3 curPos  = GetRectPointInWorld(rect, pivot, rotation, xHandle, yHandle);

                    float size = 0.05f * HandleUtility.GetHandleSize(curPos);
                    int   id   = GUIUtility.GetControlID(s_ResizeHandlesHash, FocusType.Passive);
                    if (GUI.color.a > 0 || GUIUtility.hotControl == id)
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector3 newPos;

                        EventType typeBefore = Event.current.type;

                        if (xHandle == 1 || yHandle == 1)
                        {
                            // Side resizer (1D)
                            Vector3 sideDir  = (xHandle == 1 ? rotation * Vector3.right * rect.width : rotation * Vector3.up * rect.height);
                            Vector3 slideDir = (xHandle == 1 ? rotation * Vector3.up : rotation * Vector3.right);
                            newPos = RectHandles.SideSlider(id, curPos, sideDir, slideDir, size, null, EditorSnapSettings.move);
                        }
                        else
                        {
                            // Corner handle (2D)
                            Vector3 outwardsA = rotation * Vector3.right * (xHandle - 1);
                            Vector3 outwardsB = rotation * Vector3.up * (yHandle - 1);
                            newPos = RectHandles.CornerSlider(id, curPos, rotation * Vector3.forward, outwardsA, outwardsB, size, RectHandles.RectScalingHandleCap, EditorSnapSettings.move);
                        }

                        // Calculate snapping values if applicable
                        bool supportsRectSnapping = Selection.transforms.Length == 1 &&
                                                    UnityEditorInternal.InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) &&
                                                    Selection.activeTransform.parent.rotation == rotation;
                        if (supportsRectSnapping)
                        {
                            Transform     transform           = Selection.activeTransform;
                            RectTransform rectTransform       = transform.GetComponent <RectTransform>();
                            Transform     transformParent     = transform.parent;
                            RectTransform rectTransformParent = transformParent.GetComponent <RectTransform>();
                            if (typeBefore == EventType.MouseDown && Event.current.type != EventType.MouseDown)
                            {
                                RectTransformSnapping.CalculateOffsetSnapValues(transformParent, transform, rectTransformParent, rectTransform, xHandle, yHandle);
                            }
                        }

                        if (EditorGUI.EndChangeCheck())
                        {
                            // Resize handles require more fine grained rounding of values than other tools.
                            // With other tools, the slight rounding is not notizable as long as it's just sub-pixel,
                            // because the manipulated object is being moved at the same time.
                            // However, with resize handles, when dragging one edge or corner,
                            // the opposite is standing still, and even slight rounding can cause shaking/vibration.
                            // At a fraction of the normal rounding, the shaking is very unlikely to happen though.
                            ManipulationToolUtility.SetMinDragDifferenceForPos(curPos, 0.1f);

                            if (supportsRectSnapping)
                            {
                                Transform     transformParent = Selection.activeTransform.parent;
                                RectTransform rectParent      = transformParent.GetComponent <RectTransform>();

                                Vector2 snapSize = Vector2.one * HandleUtility.GetHandleSize(newPos) * RectTransformSnapping.kSnapThreshold;
                                snapSize.x /= (inverseRotation * transformParent.TransformVector(Vector3.right)).x;
                                snapSize.y /= (inverseRotation * transformParent.TransformVector(Vector3.up)).y;

                                Vector3 newPosInParent        = transformParent.InverseTransformPoint(newPos) - (Vector3)rectParent.rect.min;
                                Vector3 newPosInParentSnapped = (Vector3)RectTransformSnapping.SnapToGuides(newPosInParent, snapSize) + Vector3.forward * newPosInParent.z;
                                ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(newPosInParent, newPosInParentSnapped);
                                newPos = transformParent.TransformPoint(newPosInParentSnapped + (Vector3)rectParent.rect.min);
                            }

                            bool scaleFromPivot = Event.current.alt;
                            bool uniformScaling = Event.current.shift;

                            if (!scaleFromPivot)
                            {
                                scalePivot = GetRectPointInWorld(s_StartRect, pivot, rotation, 2 - xHandle, 2 - yHandle);
                            }

                            if (uniformScaling)
                            {
                                newPos = Vector3.Project(newPos - scalePivot, origPos - scalePivot) + scalePivot;
                            }

                            Vector3 sizeBefore = inverseRotation * (origPos - scalePivot);
                            Vector3 sizeAfter  = inverseRotation * (newPos - scalePivot);
                            if (xHandle != 1)
                            {
                                scale.x = sizeAfter.x / sizeBefore.x;
                            }
                            if (yHandle != 1)
                            {
                                scale.y = sizeAfter.y / sizeBefore.y;
                            }

                            if (uniformScaling)
                            {
                                float refScale = (xHandle == 1 ? scale.y : scale.x);
                                scale = Vector3.one * refScale;
                            }

                            if (uniformScaling)
                            {
                                float refScale = (xHandle == 1 ? scale.y : scale.x);
                                scale = Vector3.one * refScale;
                            }
                        }

                        if (xHandle == 0)
                        {
                            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingLeft, typeBefore);
                        }
                        if (xHandle == 2)
                        {
                            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingRight, typeBefore);
                        }
                        if (xHandle != 1)
                        {
                            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingWidth, typeBefore);
                        }
                        if (yHandle == 0)
                        {
                            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingBottom, typeBefore);
                        }
                        if (yHandle == 2)
                        {
                            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingTop, typeBefore);
                        }
                        if (yHandle != 1)
                        {
                            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingHeight, typeBefore);
                        }
                    }
                }
            }

            return(scale);
        }
Esempio n. 19
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);
        }
Esempio n. 20
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);
        }
Esempio n. 21
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);
        }
Esempio n. 22
0
        static Vector3 MoveHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
        {
            int id = GUIUtility.GetControlID(s_MoveHandleHash, FocusType.Passive);

            Vector3 newPos      = pivot;
            float   discSize    = HandleUtility.GetHandleSize(pivot) * 0.2f;
            float   discOpacity = (1 - GUI.color.a);

            Vector3[] corners = new Vector3[4];
            corners[0] = rotation * new Vector2(rect.x, rect.y) + pivot;
            corners[1] = rotation * new Vector2(rect.xMax, rect.y) + pivot;
            corners[2] = rotation * new Vector2(rect.xMax, rect.yMax) + pivot;
            corners[3] = rotation * new Vector2(rect.x, rect.yMax) + pivot;

            VertexSnapping.HandleMouseMove(id);

            bool supportsRectSnapping = Selection.transforms.Length == 1 &&
                                        UnityEditorInternal.InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) &&
                                        Selection.activeTransform.parent.rotation == rotation;

            Event     evt       = Event.current;
            EventType eventType = evt.GetTypeForControl(id);
            Plane     guiPlane  = new Plane(corners[0], corners[1], corners[2]);

            switch (eventType)
            {
            case EventType.MouseDown:
            {
                bool acceptClick = false;

                if (Tools.vertexDragging)
                {
                    acceptClick = true;
                }
                else
                {
                    acceptClick =
                        evt.button == 0 &&
                        evt.modifiers == 0 &&
                        RectHandles.RaycastGUIPointToWorldHit(evt.mousePosition, guiPlane, out s_StartMouseWorldPos) &&
                        (
                            SceneViewDistanceToRectangle(corners, evt.mousePosition) == 0f ||
                            (discOpacity > 0 && SceneViewDistanceToDisc(pivot, rotation * Vector3.forward, discSize, evt.mousePosition) == 0f)
                        );
                }

                if (acceptClick)
                {
                    s_StartPosition       = pivot;
                    s_StartMousePos       = s_CurrentMousePos = evt.mousePosition;
                    s_Moving              = false;
                    s_LockAxis            = -1;
                    GUIUtility.hotControl = GUIUtility.keyboardControl = id;
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    HandleUtility.ignoreRaySnapObjects = null;
                    evt.Use();

                    // Calculate snapping values if applicable
                    if (supportsRectSnapping)
                    {
                        Transform     transform           = Selection.activeTransform;
                        RectTransform rectTransform       = transform.GetComponent <RectTransform>();
                        Transform     transformParent     = transform.parent;
                        RectTransform rectTransformParent = transformParent.GetComponent <RectTransform>();

                        s_StartRectPosition = rectTransform.anchoredPosition;

                        RectTransformSnapping.CalculatePositionSnapValues(transformParent, transform, rectTransformParent, rectTransform);
                    }
                }
                break;
            }

            case EventType.MouseDrag:
            {
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePos += evt.delta;
                    if (!s_Moving && (s_CurrentMousePos - s_StartMousePos).magnitude > 3f)
                    {
                        s_Moving = true;
                        // Re-raycast to get start mouse pos when effective dragging starts.
                        // This prevents a sudden unsnap when the dragging is enabled.
                        RectHandles.RaycastGUIPointToWorldHit(s_CurrentMousePos, guiPlane, out s_StartMouseWorldPos);
                    }
                    if (s_Moving)
                    {
                        if (Tools.vertexDragging)
                        {
                            if (HandleUtility.ignoreRaySnapObjects == null)
                            {
                                Handles.SetupIgnoreRaySnapObjects();
                            }
                            Vector3 near;
                            if (HandleUtility.FindNearestVertex(s_CurrentMousePos, null, out near))
                            {
                                // Snap position based on found near vertex
                                newPos      = near;
                                GUI.changed = true;
                            }
                            ManipulationToolUtility.minDragDifference = Vector2.zero;
                        }
                        else
                        {
                            ManipulationToolUtility.SetMinDragDifferenceForPos(pivot);
                            Vector3 pos;
                            if (RectHandles.RaycastGUIPointToWorldHit(s_CurrentMousePos, guiPlane, out pos))
                            {
                                Vector3 offset = pos - s_StartMouseWorldPos;

                                // Snap to axis
                                if (evt.shift)
                                {
                                    // Get offset in rect handles space
                                    offset = Quaternion.Inverse(rotation) * offset;
                                    // Determine lock axis if not already set
                                    if (s_LockAxis == -1)
                                    {
                                        s_LockAxis = Mathf.Abs(offset.x) > Mathf.Abs(offset.y) ? 0 : 1;
                                    }
                                    // Cancel mocement on other axis
                                    offset[1 - s_LockAxis] = 0;
                                    // Put offset back in world space
                                    offset = rotation * offset;
                                }
                                else
                                {
                                    s_LockAxis = -1;
                                }

                                if (supportsRectSnapping)
                                {
                                    Transform transformParent = Selection.activeTransform.parent;
                                    Vector3   rectPosition    = s_StartRectPosition + transformParent.InverseTransformVector(offset);
                                    rectPosition.z = 0;

                                    Quaternion inverseRotation = Quaternion.Inverse(rotation);
                                    Vector2    snapSize        = Vector2.one * HandleUtility.GetHandleSize(newPos) * RectTransformSnapping.kSnapThreshold;
                                    snapSize.x /= (inverseRotation * transformParent.TransformVector(Vector3.right)).x;
                                    snapSize.y /= (inverseRotation * transformParent.TransformVector(Vector3.up)).y;

                                    Vector3 newRectPosition = RectTransformSnapping.SnapToGuides(rectPosition, snapSize);
                                    ManipulationToolUtility.DisableMinDragDifferenceBasedOnSnapping(rectPosition, newRectPosition);
                                    offset = transformParent.TransformVector(newRectPosition - s_StartRectPosition);
                                }

                                newPos = s_StartPosition + offset;

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

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

            case EventType.Repaint:
            {
                if (Tools.vertexDragging)
                {
                    RectHandles.RectScalingHandleCap(id, pivot, rotation, 1, EventType.Repaint);
                }
                else
                {
                    Handles.color = Handles.secondaryColor * new Color(1, 1, 1, 1.5f * discOpacity);
                    Handles.CircleHandleCap(id, pivot, rotation, discSize, EventType.Repaint);
                    Handles.color = Handles.secondaryColor * new Color(1, 1, 1, 0.3f * discOpacity);
                    Handles.DrawSolidDisc(pivot, rotation * Vector3.forward, discSize);
                }
                break;
            }
            }

            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingPosX, eventType);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingLeft, eventType);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingRight, eventType);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingPosY, eventType);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingTop, eventType);
            ManipulationToolUtility.DetectDraggingBasedOnMouseDownUp(kChangingBottom, eventType);

            return(newPos);
        }
Esempio n. 23
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);
        }