Advertisement
Pro_Unit

RectDrawer

May 4th, 2023
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using UnityEditor;
  2.  
  3. using UnityEngine;
  4.  
  5. namespace Game.Utilities
  6. {
  7.     public class RectDrawer
  8.     {
  9.         private const float Offset = 2f;
  10.         private readonly IRectLineDrawer[] _drawers;
  11.         private readonly int _length;
  12.  
  13.         public RectDrawer(params IRectLineDrawer[] drawers)
  14.         {
  15.             _drawers = drawers;
  16.             _length = _drawers.Length;
  17.         }
  18.  
  19.         public void Draw(Rect position)
  20.         {
  21.             var current = new Rect(position) { height = EditorGUIUtility.singleLineHeight };
  22.  
  23.             for (int i = 0; i < _length; i++)
  24.             {
  25.                 IRectLineDrawer drawer = _drawers[i];
  26.                 drawer.Draw(current);
  27.  
  28.                 float currentY = i != _length - 1
  29.                     ? EditorGUIUtility.singleLineHeight + Offset
  30.                     : 0;
  31.  
  32.                 current.y += currentY;
  33.             }
  34.         }
  35.  
  36.         public float Height => _length * EditorGUIUtility.singleLineHeight + (_length + 1) * Offset;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement