public override void DoManipulate()
        {
            Rect rect = GetRect(rectManipulatorParams.position, rectManipulatorParams.rotation);

            int vertexCount = 0;

            foreach (IVertexManipulable vm in manipulables)
            {
                vertexCount += vm.GetManipulableVertexCount();
            }

            if (Event.current.type == EventType.MouseDown &&
                Event.current.button == 0)
            {
                foreach (IVertexManipulable vm in manipulables)
                {
                    Normalize(vm, rect, rectManipulatorParams.position, rectManipulatorParams.rotation);
                }
            }

            if (!EditorGUI.actionKey && vertexCount > 2)
            {
                EditorGUI.BeginChangeCheck();

                RectHandles.Do(ref rect, ref rectManipulatorParams.position, ref rectManipulatorParams.rotation, true, true);

                if (EditorGUI.EndChangeCheck())
                {
                    foreach (IVertexManipulable vm in manipulables)
                    {
                        Denormalize(vm, rect, rectManipulatorParams.position, rectManipulatorParams.rotation);
                    }
                }
            }
        }
示例#2
0
        public static Rect Do(int controlID)
        {
            EventType eventType = Event.current.GetTypeForControl(controlID);

            if (eventType == EventType.MouseDown)
            {
                s_StartPosition        = HandlesExtra.GUIToWorld(Event.current.mousePosition);
                s_EndPosition          = s_StartPosition;
                s_currentRect.position = s_StartPosition;
                s_currentRect.size     = Vector2.zero;
            }

            if (eventType == EventType.Layout)
            {
                HandleUtility.AddDefaultControl(controlID);
            }

            if (eventType == EventType.Repaint)
            {
                if (GUIUtility.hotControl == controlID)
                {
                    RectHandles.RenderRect(s_currentRect, Vector3.zero, Quaternion.identity, new Color(0f, 1f, 1f, 1f),
                                           0.05f, 0.8f);
                }
            }

            if (Camera.current)
            {
#if UNITY_5_6_OR_NEWER
                s_EndPosition = Handles.Slider2D(controlID, s_EndPosition, Vector3.forward, Vector3.right, Vector3.up,
                                                 HandleUtility.GetHandleSize(s_EndPosition) / 4f, (id, pos, rot, size, evt) => { }, Vector2.zero);
#else
                s_EndPosition =
                    Handles.Slider2D(controlID, s_EndPosition, Vector3.forward, Vector3.right, Vector3.up, HandleUtility.GetHandleSize(s_EndPosition) / 4f, (id, pos, rot, size) => {}, Vector2.zero);
#endif
            }
            else
            {
                s_EndPosition = HandlesExtra.Slider2D(controlID, s_EndPosition, null);
            }

            s_currentRect.min = s_StartPosition;
            s_currentRect.max = s_EndPosition;

            return(s_currentRect);
        }
示例#3
0
        protected override void DoGUI()
        {
            if (canShow())
            {
                Vector3    pos  = Vector3.zero;
                Quaternion rot  = Quaternion.identity;
                Rect       rect = spriteMeshCache.rect;

                EditorGUI.BeginChangeCheck();

                RectHandles.Do(ref rect, ref pos, ref rot, false);

                if (EditorGUI.EndChangeCheck())
                {
                    spriteMeshCache.RegisterUndo("set rect");

                    spriteMeshCache.rect = rect;
                }
            }
        }