AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
Location.cs
1 /************************************************/
2 /* */
3 /* Copyright (c) 2018 - 2021 monitor1394 */
4 /* https://github.com/monitor1394 */
5 /* */
6 /************************************************/
7 
8 using System;
9 using UnityEngine;
10 #if dUI_TextMeshPro
11 using TMPro;
12 #endif
13 
14 namespace XCharts
15 {
20  [Serializable]
22  {
26  public enum Align
27  {
28  TopLeft,
29  TopRight,
30  TopCenter,
31  BottomLeft,
32  BottomRight,
33  BottomCenter,
34  Center,
35  CenterLeft,
36  CenterRight
37  }
38 
39  [SerializeField] private Align m_Align = Align.TopCenter;
40  [SerializeField] private float m_Left;
41  [SerializeField] private float m_Right;
42  [SerializeField] private float m_Top;
43  [SerializeField] private float m_Bottom;
44 
45  private TextAnchor m_TextAlignment;
46 #if dUI_TextMeshPro
47  private TextAlignmentOptions m_TMPTextAlignment;
48 #endif
49  private Vector2 m_AnchorMin;
50  private Vector2 m_AnchorMax;
51  private Vector2 m_Pivot;
52 
56  public Align align
57  {
58  get { return m_Align; }
59  set { if (PropertyUtil.SetStruct(ref m_Align, value)) { SetComponentDirty(); UpdateAlign(); } }
60  }
65  public float left
66  {
67  get { return m_Left; }
68  set { if (PropertyUtil.SetStruct(ref m_Left, value)) { SetComponentDirty(); UpdateAlign(); } }
69  }
74  public float right
75  {
76  get { return m_Right; }
77  set { if (PropertyUtil.SetStruct(ref m_Right, value)) { SetComponentDirty(); UpdateAlign(); } }
78  }
83  public float top
84  {
85  get { return m_Top; }
86  set { if (PropertyUtil.SetStruct(ref m_Top, value)) { SetComponentDirty(); UpdateAlign(); } }
87  }
92  public float bottom
93  {
94  get { return m_Bottom; }
95  set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) { SetComponentDirty(); UpdateAlign(); } }
96  }
97 
103  public TextAnchor runtimeTextAlignment { get { return m_TextAlignment; } }
104 
105 #if dUI_TextMeshPro
106  public TextAlignmentOptions runtimeTMPTextAlignment { get { return m_TMPTextAlignment; } }
107 #endif
108  public Vector2 runtimeAnchorMin { get { return m_AnchorMin; } }
119  public Vector2 runtimeAnchorMax { get { return m_AnchorMax; } }
125  public Vector2 runtimePivot { get { return m_Pivot; } }
126 
127  public static Location defaultLeft
128  {
129  get
130  {
131  return new Location()
132  {
133  align = Align.CenterLeft,
134  left = 5,
135  right = 0,
136  top = 0,
137  bottom = 0
138  };
139  }
140  }
141 
142  public static Location defaultRight
143  {
144  get
145  {
146  return new Location()
147  {
148  align = Align.CenterRight,
149  left = 0,
150  right = 5,
151  top = 0,
152  bottom = 0
153  };
154  }
155  }
156 
157  public static Location defaultTop
158  {
159  get
160  {
161  return new Location()
162  {
163  align = Align.TopCenter,
164  left = 0,
165  right = 0,
166  top = 5,
167  bottom = 0
168  };
169  }
170  }
171 
172  public static Location defaultBottom
173  {
174  get
175  {
176  return new Location()
177  {
178  align = Align.BottomCenter,
179  left = 0,
180  right = 0,
181  top = 0,
182  bottom = 5
183  };
184  }
185  }
186 
187  private void UpdateAlign()
188  {
189  switch (m_Align)
190  {
191  case Align.BottomCenter:
192  m_TextAlignment = TextAnchor.LowerCenter;
193 #if dUI_TextMeshPro
194  m_TMPTextAlignment = TextAlignmentOptions.Bottom;
195 #endif
196  m_AnchorMin = new Vector2(0.5f, 0);
197  m_AnchorMax = new Vector2(0.5f, 0);
198  m_Pivot = new Vector2(0.5f, 0);
199  break;
200  case Align.BottomLeft:
201  m_TextAlignment = TextAnchor.LowerLeft;
202 #if dUI_TextMeshPro
203  m_TMPTextAlignment = TextAlignmentOptions.BottomLeft;
204 #endif
205  m_AnchorMin = new Vector2(0, 0);
206  m_AnchorMax = new Vector2(0, 0);
207  m_Pivot = new Vector2(0, 0);
208  break;
209  case Align.BottomRight:
210  m_TextAlignment = TextAnchor.LowerRight;
211 #if dUI_TextMeshPro
212  m_TMPTextAlignment = TextAlignmentOptions.BottomRight;
213 #endif
214  m_AnchorMin = new Vector2(1, 0);
215  m_AnchorMax = new Vector2(1, 0);
216  m_Pivot = new Vector2(1, 0);
217  break;
218  case Align.Center:
219  m_TextAlignment = TextAnchor.MiddleCenter;
220 #if dUI_TextMeshPro
221  m_TMPTextAlignment = TextAlignmentOptions.Center;
222 #endif
223  m_AnchorMin = new Vector2(0.5f, 0.5f);
224  m_AnchorMax = new Vector2(0.5f, 0.5f);
225  m_Pivot = new Vector2(0.5f, 0.5f);
226  break;
227  case Align.CenterLeft:
228  m_TextAlignment = TextAnchor.MiddleLeft;
229 #if dUI_TextMeshPro
230  m_TMPTextAlignment = TextAlignmentOptions.Left;
231 #endif
232  m_AnchorMin = new Vector2(0, 0.5f);
233  m_AnchorMax = new Vector2(0, 0.5f);
234  m_Pivot = new Vector2(0, 0.5f);
235  break;
236  case Align.CenterRight:
237  m_TextAlignment = TextAnchor.MiddleRight;
238 #if dUI_TextMeshPro
239  m_TMPTextAlignment = TextAlignmentOptions.Right;
240 #endif
241  m_AnchorMin = new Vector2(1, 0.5f);
242  m_AnchorMax = new Vector2(1, 0.5f);
243  m_Pivot = new Vector2(1, 0.5f);
244  break;
245  case Align.TopCenter:
246  m_TextAlignment = TextAnchor.UpperCenter;
247 #if dUI_TextMeshPro
248  m_TMPTextAlignment = TextAlignmentOptions.Top;
249 #endif
250  m_AnchorMin = new Vector2(0.5f, 1);
251  m_AnchorMax = new Vector2(0.5f, 1);
252  m_Pivot = new Vector2(0.5f, 1);
253  break;
254  case Align.TopLeft:
255  m_TextAlignment = TextAnchor.UpperLeft;
256 #if dUI_TextMeshPro
257  m_TMPTextAlignment = TextAlignmentOptions.TopLeft;
258 #endif
259  m_AnchorMin = new Vector2(0, 1);
260  m_AnchorMax = new Vector2(0, 1);
261  m_Pivot = new Vector2(0, 1);
262  break;
263  case Align.TopRight:
264  m_TextAlignment = TextAnchor.UpperRight;
265 #if dUI_TextMeshPro
266  m_TMPTextAlignment = TextAlignmentOptions.TopRight;
267 #endif
268  m_AnchorMin = new Vector2(1, 1);
269  m_AnchorMax = new Vector2(1, 1);
270  m_Pivot = new Vector2(1, 1);
271  break;
272  default:
273  break;
274  }
275  }
276 
283  public Vector3 GetPosition(float chartWidth, float chartHeight)
284  {
285  switch (align)
286  {
287  case Align.BottomCenter:
288  return new Vector3(chartWidth / 2, bottom);
289  case Align.BottomLeft:
290  return new Vector3(left, bottom);
291  case Align.BottomRight:
292  return new Vector3(chartWidth - right, bottom);
293  case Align.Center:
294  return new Vector3(chartWidth / 2, chartHeight / 2);
295  case Align.CenterLeft:
296  return new Vector3(left, chartHeight / 2);
297  case Align.CenterRight:
298  return new Vector3(chartWidth - right, chartHeight / 2);
299  case Align.TopCenter:
300  return new Vector3(chartWidth / 2, chartHeight - top);
301  case Align.TopLeft:
302  return new Vector3(left, chartHeight - top);
303  case Align.TopRight:
304  return new Vector3(chartWidth - right, chartHeight - top);
305  default:
306  return Vector2.zero;
307  }
308  }
309 
313  public void OnChanged()
314  {
315  UpdateAlign();
316  }
317  }
318 }
XCharts.Location.GetPosition
Vector3 GetPosition(float chartWidth, float chartHeight)
返回在坐标系中的具体位置
Definition: Location.cs:283
XCharts.IPropertyChanged
属性变更接口
Definition: IPropertyChanged.cs:13
XCharts.Location.Align
Align
对齐方式
Definition: Location.cs:26
XCharts.Location
Location type. Quick to set the general location. 位置类型。通过Align快速设置大体位置,再通过left,right,top,bottom微调具体位置...
Definition: Location.cs:21
XCharts.Location.right
float right
Distance between component and the left side of the container. 离容器右侧的距离。
Definition: Location.cs:75
XCharts.Location.runtimeTextAlignment
TextAnchor runtimeTextAlignment
the anchor of text. Location对应的Anchor锚点
Definition: Location.cs:103
XCharts.Align
Align
对齐方式
Definition: Serie.cs:250
XCharts.SubComponent
Definition: ChartComponent.cs:71
XCharts.Location.runtimePivot
Vector2 runtimePivot
the povot. Loation对应的中心点。
Definition: Location.cs:125
XCharts
Definition: RewardChart.cs:14
XCharts.Location.runtimeAnchorMin
Vector2 runtimeAnchorMin
the minimum achor. Location对应的anchorMin。
Definition: Location.cs:113
XCharts.Location.top
float top
Distance between component and the left side of the container. 离容器上侧的距离。
Definition: Location.cs:84
XCharts.Location.left
float left
Distance between component and the left side of the container. 离容器左侧的距离。
Definition: Location.cs:66
XCharts.Location.OnChanged
void OnChanged()
属性变更时更新textAnchor,minAnchor,maxAnchor,pivot
Definition: Location.cs:313
XCharts.Location.runtimeAnchorMax
Vector2 runtimeAnchorMax
the maximun achor. Location对应的anchorMax.
Definition: Location.cs:119
XCharts.Location.bottom
float bottom
Distance between component and the left side of the container. 离容器下侧的距离。
Definition: Location.cs:93
XCharts.Location.align
Align align
对齐方式。
Definition: Location.cs:57