A game about forced loneliness, made by TACStudios
at master 3.7 kB view raw
1using System; 2using UnityEngine; 3using UnityEngine.UIElements; 4using UnityEngine.UIElements.StyleSheets; 5 6namespace UnityEditor.ShaderGraph.Drawing 7{ 8 [Serializable] 9 internal class WindowDockingLayout 10 { 11 [SerializeField] 12 bool m_DockingLeft; 13 14 public bool dockingLeft 15 { 16 get => m_DockingLeft; 17 set => m_DockingLeft = value; 18 } 19 20 [SerializeField] 21 bool m_DockingTop; 22 23 public bool dockingTop 24 { 25 get => m_DockingTop; 26 set => m_DockingTop = value; 27 } 28 29 [SerializeField] 30 float m_VerticalOffset; 31 32 public float verticalOffset 33 { 34 get => m_VerticalOffset; 35 set => m_VerticalOffset = value; 36 } 37 38 [SerializeField] 39 float m_HorizontalOffset; 40 41 public float horizontalOffset 42 { 43 get => m_HorizontalOffset; 44 set => m_HorizontalOffset = value; 45 } 46 47 [SerializeField] 48 Vector2 m_Size; 49 50 public Vector2 size 51 { 52 get => m_Size; 53 set => m_Size = value; 54 } 55 56 public void CalculateDockingCornerAndOffset(Rect layout, Rect parentLayout) 57 { 58 Vector2 layoutCenter = new Vector2(layout.x + layout.width * .5f, layout.y + layout.height * .5f); 59 layoutCenter /= parentLayout.size; 60 61 m_DockingLeft = layoutCenter.x < .5f; 62 m_DockingTop = layoutCenter.y < .5f; 63 64 if (m_DockingLeft) 65 { 66 m_HorizontalOffset = layout.x; 67 } 68 else 69 { 70 m_HorizontalOffset = parentLayout.width - layout.x - layout.width; 71 } 72 73 if (m_DockingTop) 74 { 75 m_VerticalOffset = layout.y; 76 } 77 else 78 { 79 m_VerticalOffset = parentLayout.height - layout.y - layout.height; 80 } 81 82 m_Size = layout.size; 83 } 84 85 public void ClampToParentWindow() 86 { 87 m_HorizontalOffset = Mathf.Max(0f, m_HorizontalOffset); 88 m_VerticalOffset = Mathf.Max(0f, m_VerticalOffset); 89 } 90 91 public void ApplyPosition(VisualElement target) 92 { 93 if (dockingLeft) 94 { 95 target.style.right = float.NaN; 96 target.style.left = horizontalOffset; 97 } 98 else 99 { 100 target.style.right = horizontalOffset; 101 target.style.left = float.NaN; 102 } 103 104 if (dockingTop) 105 { 106 target.style.bottom = float.NaN; 107 target.style.top = verticalOffset; 108 } 109 else 110 { 111 target.style.top = float.NaN; 112 target.style.bottom = verticalOffset; 113 } 114 } 115 116 public void ApplySize(VisualElement target) 117 { 118 target.style.width = size.x; 119 target.style.height = size.y; 120 } 121 122 public Rect GetLayout(Rect parentLayout) 123 { 124 Rect layout = new Rect(); 125 126 layout.size = size; 127 128 if (dockingLeft) 129 { 130 layout.x = horizontalOffset; 131 } 132 else 133 { 134 layout.x = parentLayout.width - size.x - horizontalOffset; 135 } 136 137 if (dockingTop) 138 { 139 layout.y = verticalOffset; 140 } 141 else 142 { 143 layout.y = parentLayout.height - size.y - verticalOffset; 144 } 145 146 return layout; 147 } 148 } 149}