private void DrawGizmos()
 {
     if (eventSystem.current.type != EventType.Repaint)
     {
         return;
     }
     for (int i = 0; i < spriteCount; i++)
     {
         List <Vector2[]> outline = GetSpriteOutlineAt(i);
         Vector2          offset  = GetSpriteRectAt(i).size * 0.5f;
         if (outline.Count > 0)
         {
             SpriteEditorUtility.BeginLines(new Color(0.75f, 0.75f, 0.75f, 0.75f));
             for (int j = 0; j < outline.Count; ++j)
             {
                 for (int k = 0, last = outline[j].Length - 1; k < outline[j].Length; last = k, ++k)
                 {
                     SpriteEditorUtility.DrawLine(outline[j][last] + offset, outline[j][k] + offset);
                 }
             }
             SpriteEditorUtility.EndLines();
         }
     }
     DrawSpriteRectGizmos();
 }
 private void DrawGizmos()
 {
     if (eventSystem.current.type == EventType.Repaint)
     {
         var selected = spriteEditorWindow.selectedSpriteRect;
         if (selected != null)
         {
             SpriteEditorUtility.BeginLines(styles.spriteBorderColor);
             SpriteEditorUtility.DrawBox(selected.rect);
             SpriteEditorUtility.EndLines();
         }
     }
 }
예제 #3
0
        protected void DrawTexturespaceBackground()
        {
            float   size   = Mathf.Max(maxRect.width, maxRect.height);
            Vector2 offset = new Vector2(maxRect.xMin, maxRect.yMin);

            float halfSize = size * .5f;
            float alpha    = EditorGUIUtility.isProSkin ? 0.15f : 0.08f;
            float gridSize = 8f;

            SpriteEditorUtility.BeginLines(new Color(0f, 0f, 0f, alpha));
            for (float v = 0; v <= size; v += gridSize)
            {
                SpriteEditorUtility.DrawLine(new Vector2(-halfSize + v, halfSize + v) + offset, new Vector2(halfSize + v, -halfSize + v) + offset);
            }
            SpriteEditorUtility.EndLines();
        }
        protected void DrawRectGizmos(IEnumerable <Rect> rects, Color color)
        {
            if (eventSystem.current.type != EventType.Repaint)
            {
                return;
            }

            SpriteEditorUtility.BeginLines(color);
            foreach (var rect in rects)
            {
                SpriteEditorUtility.DrawLine(new Vector3(rect.xMin, rect.yMin), new Vector3(rect.xMin, rect.yMax));
                SpriteEditorUtility.DrawLine(new Vector3(rect.xMax, rect.yMin), new Vector3(rect.xMax, rect.yMax));

                SpriteEditorUtility.DrawLine(new Vector3(rect.xMin, rect.yMin), new Vector3(rect.xMax, rect.yMin));
                SpriteEditorUtility.DrawLine(new Vector3(rect.xMin, rect.yMax), new Vector3(rect.xMax, rect.yMax));
            }
            SpriteEditorUtility.EndLines();
        }
        protected void DrawSpriteRectGizmos()
        {
            if (eventSystem.current.type != EventType.Repaint)
            {
                return;
            }

            SpriteEditorUtility.BeginLines(new Color(0f, 1f, 0f, 0.7f));
            int currentSelectedSpriteIndex = CurrentSelectedSpriteIndex();

            for (int i = 0; i < spriteCount; i++)
            {
                Vector4 border = GetSpriteBorderAt(i);
                if (currentSelectedSpriteIndex != i && m_GizmoMode != GizmoMode.BorderEditing)
                {
                    if (Mathf.Approximately(border.sqrMagnitude, 0))
                    {
                        continue;
                    }
                }


                var rect = GetSpriteRectAt(i);
                SpriteEditorUtility.DrawLine(new Vector3(rect.xMin + border.x, rect.yMin), new Vector3(rect.xMin + border.x, rect.yMax));
                SpriteEditorUtility.DrawLine(new Vector3(rect.xMax - border.z, rect.yMin), new Vector3(rect.xMax - border.z, rect.yMax));

                SpriteEditorUtility.DrawLine(new Vector3(rect.xMin, rect.yMin + border.y), new Vector3(rect.xMax, rect.yMin + border.y));
                SpriteEditorUtility.DrawLine(new Vector3(rect.xMin, rect.yMax - border.w), new Vector3(rect.xMax, rect.yMax - border.w));
            }
            SpriteEditorUtility.EndLines();

            if (ShouldShowRectScaling())
            {
                Rect r = selectedSpriteRect;
                SpriteEditorUtility.BeginLines(new Color(0f, 0.1f, 0.3f, 0.25f));
                SpriteEditorUtility.DrawBox(new Rect(r.xMin + 1f / m_Zoom, r.yMin + 1f / m_Zoom, r.width, r.height));
                SpriteEditorUtility.EndLines();
                SpriteEditorUtility.BeginLines(new Color(0.25f, 0.5f, 1f, 0.75f));
                SpriteEditorUtility.DrawBox(r);
                SpriteEditorUtility.EndLines();
            }
        }
        protected void DrawSpriteRectGizmos()
        {
            if (eventSystem.current.type != EventType.Repaint)
            {
                return;
            }

            SpriteEditorUtility.BeginLines(new Color(0f, 1f, 0f, 0.7f));
            var selectedGUID = selected != null ? selected.spriteID : new GUID();

            for (int i = 0; i < spriteCount; i++)
            {
                Vector4 border = GetSpriteBorderAt(i);
                if (m_GizmoMode != GizmoMode.BorderEditing && (m_RectsCache != null && m_RectsCache.spriteRects[i].spriteID != selectedGUID))
                {
                    // border does not contain negative values
                    if (border.sqrMagnitude < Mathf.Epsilon * 8)
                    {
                        continue;
                    }
                }

                var rect = GetSpriteRectAt(i);
                SpriteEditorUtility.DrawLine(new Vector3(rect.xMin + border.x, rect.yMin), new Vector3(rect.xMin + border.x, rect.yMax));
                SpriteEditorUtility.DrawLine(new Vector3(rect.xMax - border.z, rect.yMin), new Vector3(rect.xMax - border.z, rect.yMax));

                SpriteEditorUtility.DrawLine(new Vector3(rect.xMin, rect.yMin + border.y), new Vector3(rect.xMax, rect.yMin + border.y));
                SpriteEditorUtility.DrawLine(new Vector3(rect.xMin, rect.yMax - border.w), new Vector3(rect.xMax, rect.yMax - border.w));
            }
            SpriteEditorUtility.EndLines();

            if (ShouldShowRectScaling())
            {
                Rect r = selectedSpriteRect;
                SpriteEditorUtility.BeginLines(new Color(0f, 0.1f, 0.3f, 0.25f));
                SpriteEditorUtility.DrawBox(new Rect(r.xMin + 1f / m_Zoom, r.yMin + 1f / m_Zoom, r.width, r.height));
                SpriteEditorUtility.EndLines();
                SpriteEditorUtility.BeginLines(new Color(0.25f, 0.5f, 1f, 0.75f));
                SpriteEditorUtility.DrawBox(r);
                SpriteEditorUtility.EndLines();
            }
        }
예제 #7
0
        protected override void DoTextureGUIExtras()
        {
            HandleFrameSelected();

            if (m_EventSystem.current.type == EventType.Repaint)
            {
                SpriteEditorUtility.BeginLines(new Color(1f, 1f, 1f, 0.5f));
                var selectedRect = selectedSpriteRect != null ? selectedSpriteRect.spriteID : new GUID();
                for (int i = 0; i < m_RectsCache.Count; i++)
                {
                    if (m_RectsCache[i].spriteID != selectedRect)
                    {
                        SpriteEditorUtility.DrawBox(m_RectsCache[i].rect);
                    }
                }
                SpriteEditorUtility.EndLines();
            }

            m_CurrentModule.DoMainGUI();
        }
예제 #8
0
        static internal Rect RectCreator(Rect textureArea, GUIStyle rectStyle)
        {
            var     evt      = UnityEvent.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);
        }