Example #1
0
        private void DoPivotGUI()
        {
            EditorGUI.BeginChangeCheck();
            int num = SpriteEditorMenu.s_Setting.spriteAlignment;

            num = EditorGUILayout.Popup(SpriteEditorMenu.s_Styles.pivotLabel, num, SpriteEditorMenu.s_Styles.spriteAlignmentOptions, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RegisterCompleteObjectUndo(SpriteEditorMenu.s_Setting, "Change Alignment");
                SpriteEditorMenu.s_Setting.spriteAlignment = num;
                SpriteEditorMenu.s_Setting.pivot           = SpriteEditorUtility.GetPivotValue((SpriteAlignment)num, SpriteEditorMenu.s_Setting.pivot);
            }
            Vector2 vector = SpriteEditorMenu.s_Setting.pivot;

            EditorGUI.BeginChangeCheck();
            using (new EditorGUI.DisabledScope(num != 9))
            {
                vector = EditorGUILayout.Vector2Field(SpriteEditorMenu.s_Styles.customPivotLabel, vector, new GUILayoutOption[0]);
            }
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RegisterCompleteObjectUndo(SpriteEditorMenu.s_Setting, "Change custom pivot");
                SpriteEditorMenu.s_Setting.pivot = vector;
            }
        }
        private void DoPivotGUI()
        {
            EditorGUI.BeginChangeCheck();
            int spriteAlignment = s_Setting.spriteAlignment;

            spriteAlignment = EditorGUILayout.Popup(s_Styles.pivotLabel, spriteAlignment, s_Styles.spriteAlignmentOptions, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RegisterCompleteObjectUndo(s_Setting, "Change Alignment");
                s_Setting.spriteAlignment = spriteAlignment;
                s_Setting.pivot           = SpriteEditorUtility.GetPivotValue((SpriteAlignment)spriteAlignment, s_Setting.pivot);
            }
            Vector2 pivot = s_Setting.pivot;

            EditorGUI.BeginChangeCheck();
            using (new EditorGUI.DisabledScope(spriteAlignment != 9))
            {
                pivot = EditorGUILayout.Vector2Field(s_Styles.customPivotLabel, pivot, new GUILayoutOption[0]);
            }
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RegisterCompleteObjectUndo(s_Setting, "Change custom pivot");
                s_Setting.pivot = pivot;
            }
        }
        private void DoPivotGUI()
        {
            EditorGUI.BeginChangeCheck();
            int num = EditorGUILayout.Popup("Pivot", SpriteEditorMenu.s_Setting.spriteAlignment, this.spriteAlignmentOptions, new GUILayoutOption[0]);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RegisterCompleteObjectUndo((UnityEngine.Object)SpriteEditorMenu.s_Setting, "Change Alignment");
                SpriteEditorMenu.s_Setting.spriteAlignment = num;
                SpriteEditorMenu.s_Setting.pivot           = SpriteEditorUtility.GetPivotValue((SpriteAlignment)num, SpriteEditorMenu.s_Setting.pivot);
            }
            Vector2 pivot = SpriteEditorMenu.s_Setting.pivot;

            EditorGUI.BeginChangeCheck();
            EditorGUI.BeginDisabledGroup(num != 9);
            Vector2 vector2 = EditorGUILayout.Vector2Field("Custom Pivot", pivot);

            EditorGUI.EndDisabledGroup();
            if (!EditorGUI.EndChangeCheck())
            {
                return;
            }
            Undo.RegisterCompleteObjectUndo((UnityEngine.Object)SpriteEditorMenu.s_Setting, "Change custom pivot");
            SpriteEditorMenu.s_Setting.pivot = vector2;
        }
Example #4
0
        public static void DrawBox(Rect position)
        {
            Vector3[] vector3Array1 = new Vector3[5];
            int       num1          = 0;

            Vector3[] vector3Array2 = vector3Array1;
            int       index1        = num1;
            int       num2          = 1;
            int       num3          = index1 + num2;

            vector3Array2[index1] = new Vector3(position.xMin, position.yMin, 0.0f);
            Vector3[] vector3Array3 = vector3Array1;
            int       index2        = num3;
            int       num4          = 1;
            int       num5          = index2 + num4;

            vector3Array3[index2] = new Vector3(position.xMax, position.yMin, 0.0f);
            Vector3[] vector3Array4 = vector3Array1;
            int       index3        = num5;
            int       num6          = 1;
            int       num7          = index3 + num6;

            vector3Array4[index3] = new Vector3(position.xMax, position.yMax, 0.0f);
            Vector3[] vector3Array5 = vector3Array1;
            int       index4        = num7;
            int       num8          = 1;
            int       num9          = index4 + num8;

            vector3Array5[index4] = new Vector3(position.xMin, position.yMax, 0.0f);
            SpriteEditorUtility.DrawLine(vector3Array1[0], vector3Array1[1]);
            SpriteEditorUtility.DrawLine(vector3Array1[1], vector3Array1[2]);
            SpriteEditorUtility.DrawLine(vector3Array1[2], vector3Array1[3]);
            SpriteEditorUtility.DrawLine(vector3Array1[3], vector3Array1[0]);
        }
        private static Rect GetCurrentRect(bool screenSpace, float textureWidth, float textureHeight, Vector2 startPoint, Vector2 endPoint)
        {
            Rect rect = SpriteEditorUtility.ClampedRect(SpriteEditorUtility.RoundToInt(EditorGUIExt.FromToRect(Handles.s_InverseMatrix.MultiplyPoint((Vector3)startPoint), Handles.s_InverseMatrix.MultiplyPoint((Vector3)endPoint))), new Rect(0f, 0f, textureWidth, textureHeight), false);

            if (screenSpace)
            {
                Vector2 vector  = Handles.matrix.MultiplyPoint((Vector3) new Vector2(rect.xMin, rect.yMin));
                Vector2 vector2 = Handles.matrix.MultiplyPoint((Vector3) new Vector2(rect.xMax, rect.yMax));
                rect = new Rect(vector.x, vector.y, vector2.x - vector.x, vector2.y - vector.y);
            }
            return(rect);
        }
        private static Rect GetCurrentRect(bool screenSpace, Rect clampArea, Vector2 startPoint, Vector2 endPoint)
        {
            Rect rect = EditorGUIExt.FromToRect(Handles.inverseMatrix.MultiplyPoint(startPoint), Handles.inverseMatrix.MultiplyPoint(endPoint));

            rect = SpriteEditorUtility.ClampedRect(SpriteEditorUtility.RoundToInt(rect), clampArea, false);
            if (screenSpace)
            {
                Vector2 vector  = Handles.matrix.MultiplyPoint(new Vector2(rect.xMin, rect.yMin));
                Vector2 vector2 = Handles.matrix.MultiplyPoint(new Vector2(rect.xMax, rect.yMax));
                rect = new Rect(vector.x, vector.y, vector2.x - vector.x, vector2.y - vector.y);
            }
            return(rect);
        }
Example #7
0
        public static void DrawBox(Rect position)
        {
            Vector3[] array = new Vector3[5];
            int       num   = 0;

            array[num++] = new Vector3(position.xMin, position.yMin, 0f);
            array[num++] = new Vector3(position.xMax, position.yMin, 0f);
            array[num++] = new Vector3(position.xMax, position.yMax, 0f);
            array[num++] = new Vector3(position.xMin, position.yMax, 0f);
            SpriteEditorUtility.DrawLine(array[0], array[1]);
            SpriteEditorUtility.DrawLine(array[1], array[2]);
            SpriteEditorUtility.DrawLine(array[2], array[3]);
            SpriteEditorUtility.DrawLine(array[3], array[0]);
        }
        static private Rect GetCurrentRect(bool screenSpace, Rect clampArea, Vector2 startPoint, Vector2 endPoint)
        {
            Rect r = EditorGUIExt.FromToRect(Handles.inverseMatrix.MultiplyPoint(startPoint), Handles.inverseMatrix.MultiplyPoint(endPoint));

            r = SpriteEditorUtility.ClampedRect(SpriteEditorUtility.RoundToInt(r), clampArea, false);

            if (screenSpace)
            {
                Vector2 topleft     = Handles.matrix.MultiplyPoint(new Vector2(r.xMin, r.yMin));
                Vector2 bottomright = Handles.matrix.MultiplyPoint(new Vector2(r.xMax, r.yMax));

                r = new Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y);
            }
            return(r);
        }
Example #9
0
        private void DoPivotGUI()
        {
            EditorGUI.BeginChangeCheck();
            int spriteAlignment = s_Setting.spriteAlignment;

            spriteAlignment = EditorGUILayout.Popup("Pivot", spriteAlignment, this.spriteAlignmentOptions, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RegisterCompleteObjectUndo(s_Setting, "Change Alignment");
                s_Setting.spriteAlignment = spriteAlignment;
                s_Setting.pivot           = SpriteEditorUtility.GetPivotValue((SpriteAlignment)spriteAlignment, s_Setting.pivot);
            }
            Vector2 pivot = s_Setting.pivot;

            EditorGUI.BeginChangeCheck();
            EditorGUI.BeginDisabledGroup(spriteAlignment != 9);
            pivot = EditorGUILayout.Vector2Field("Custom Pivot", pivot, new GUILayoutOption[0]);
            EditorGUI.EndDisabledGroup();
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RegisterCompleteObjectUndo(s_Setting, "Change custom pivot");
                s_Setting.pivot = pivot;
            }
        }
Example #10
0
        internal static Rect RectCreator(float textureWidth, float textureHeight, GUIStyle rectStyle)
        {
            Event   current       = Event.current;
            Vector2 mousePosition = current.mousePosition;
            int     num           = SpriteEditorHandles.s_RectSelectionID;
            Rect    result        = default(Rect);

            switch (current.GetTypeForControl(num))
            {
            case EventType.MouseDown:
                if (current.button == 0)
                {
                    GUIUtility.hotControl = num;
                    Rect    rect = new Rect(0f, 0f, textureWidth, textureHeight);
                    Vector2 v    = Handles.s_InverseMatrix.MultiplyPoint(mousePosition);
                    v.x = Mathf.Min(Mathf.Max(v.x, rect.xMin), rect.xMax);
                    v.y = Mathf.Min(Mathf.Max(v.y, rect.yMin), rect.yMax);
                    SpriteEditorHandles.s_DragStartScreenPosition = Handles.s_Matrix.MultiplyPoint(v);
                    SpriteEditorHandles.s_CurrentMousePosition    = mousePosition;
                    current.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == num && current.button == 0)
                {
                    if (SpriteEditorHandles.ValidRect(SpriteEditorHandles.s_DragStartScreenPosition, SpriteEditorHandles.s_CurrentMousePosition))
                    {
                        result      = SpriteEditorHandles.GetCurrentRect(false, textureWidth, textureHeight, SpriteEditorHandles.s_DragStartScreenPosition, SpriteEditorHandles.s_CurrentMousePosition);
                        GUI.changed = true;
                        current.Use();
                    }
                    GUIUtility.hotControl = 0;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == num)
                {
                    SpriteEditorHandles.s_CurrentMousePosition = new Vector2(mousePosition.x, mousePosition.y);
                    current.Use();
                }
                break;

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

            case EventType.Repaint:
                if (GUIUtility.hotControl == num && SpriteEditorHandles.ValidRect(SpriteEditorHandles.s_DragStartScreenPosition, SpriteEditorHandles.s_CurrentMousePosition))
                {
                    SpriteEditorUtility.BeginLines(Color.green * 1.5f);
                    SpriteEditorUtility.DrawBox(SpriteEditorHandles.GetCurrentRect(false, textureWidth, textureHeight, SpriteEditorHandles.s_DragStartScreenPosition, SpriteEditorHandles.s_CurrentMousePosition));
                    SpriteEditorUtility.EndLines();
                }
                break;
            }
            return(result);
        }
        internal static Rect RectCreator(float textureWidth, float textureHeight, GUIStyle rectStyle)
        {
            Event   current       = Event.current;
            Vector2 mousePosition = current.mousePosition;
            int     controlID     = s_RectSelectionID;
            Rect    rect          = new Rect();

            switch (current.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                if (current.button == 0)
                {
                    GUIUtility.hotControl = controlID;
                    Rect    rect2   = new Rect(0f, 0f, textureWidth, textureHeight);
                    Vector2 vector2 = Handles.s_InverseMatrix.MultiplyPoint((Vector3)mousePosition);
                    float   a       = Mathf.Max(vector2.x, rect2.xMin);
                    vector2.x = Mathf.Min(a, rect2.xMax);
                    float introduced9 = Mathf.Max(vector2.y, rect2.yMin);
                    vector2.y = Mathf.Min(introduced9, rect2.yMax);
                    s_DragStartScreenPosition = Handles.s_Matrix.MultiplyPoint((Vector3)vector2);
                    s_CurrentMousePosition    = mousePosition;
                    current.Use();
                }
                return(rect);

            case EventType.MouseUp:
                if ((GUIUtility.hotControl == controlID) && (current.button == 0))
                {
                    if (ValidRect(s_DragStartScreenPosition, s_CurrentMousePosition))
                    {
                        rect        = GetCurrentRect(false, textureWidth, textureHeight, s_DragStartScreenPosition, s_CurrentMousePosition);
                        GUI.changed = true;
                        current.Use();
                    }
                    GUIUtility.hotControl = 0;
                }
                return(rect);

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

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    s_CurrentMousePosition = new Vector2(mousePosition.x, mousePosition.y);
                    current.Use();
                }
                return(rect);

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

            case EventType.Repaint:
                if ((GUIUtility.hotControl == controlID) && ValidRect(s_DragStartScreenPosition, s_CurrentMousePosition))
                {
                    SpriteEditorUtility.BeginLines((Color)(Color.green * 1.5f));
                    SpriteEditorUtility.DrawBox(GetCurrentRect(false, textureWidth, textureHeight, s_DragStartScreenPosition, s_CurrentMousePosition));
                    SpriteEditorUtility.EndLines();
                }
                return(rect);
            }
            return(rect);
        }
        static internal Rect RectCreator(Rect textureArea, GUIStyle rectStyle)
        {
            Event   evt      = Event.current;
            Vector2 mousePos = evt.mousePosition;
            int     id       = s_RectSelectionID;
            Rect    result   = new Rect();

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (evt.button == 0)
                {
                    GUIUtility.hotControl = id;

                    // Make sure that the starting position is clamped to inside texture area
                    Vector2 point = Handles.inverseMatrix.MultiplyPoint(mousePos);

                    point.x = Mathf.Min(Mathf.Max(point.x, textureArea.xMin), textureArea.xMax);
                    point.y = Mathf.Min(Mathf.Max(point.y, textureArea.yMin), textureArea.yMax);

                    // Save clamped starting position for later use
                    s_DragStartScreenPosition = Handles.matrix.MultiplyPoint(point);

                    // Actual position
                    s_CurrentMousePosition = mousePos;

                    evt.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition = new Vector2(mousePos.x, mousePos.y);
                    evt.Use();
                }
                break;

            case EventType.Repaint:
                if (GUIUtility.hotControl == id && ValidRect(s_DragStartScreenPosition, s_CurrentMousePosition))
                {
                    // TODO: use rectstyle
                    //rectStyle.Draw (GetCurrentRect (true, textureWidth, textureHeight, s_DragStartScreenPosition, s_CurrentMousePosition), GUIContent.none, false, false, false, false);
                    SpriteEditorUtility.BeginLines(Color.green * 1.5f);
                    SpriteEditorUtility.DrawBox(GetCurrentRect(false, textureArea, s_DragStartScreenPosition, s_CurrentMousePosition));
                    SpriteEditorUtility.EndLines();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && evt.button == 0)
                {
                    if (ValidRect(s_DragStartScreenPosition, s_CurrentMousePosition))
                    {
                        result      = GetCurrentRect(false, textureArea, s_DragStartScreenPosition, s_CurrentMousePosition);
                        GUI.changed = true;
                        evt.Use();
                    }

                    GUIUtility.hotControl = 0;
                }
                break;

            case EventType.KeyDown:
                if (GUIUtility.hotControl == id)
                {
                    if (evt.keyCode == KeyCode.Escape)
                    {
                        GUIUtility.hotControl = 0;
                        GUI.changed           = true;
                        evt.Use();
                    }
                }
                break;
            }
            return(result);
        }