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();
 }
        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();
            }
        }