AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
TextStyle.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]
21  public class TextStyle : SubComponent
22  {
23  [SerializeField] private Font m_Font;
24  [SerializeField] private bool m_AutoWrap = false;
25  [SerializeField] private bool m_AutoAlign = true;
26  [SerializeField] private float m_Rotate = 0;
27  [SerializeField] private Vector2 m_Offset = Vector2.zero;
28  [SerializeField] private Color m_Color = Color.clear;
29  [SerializeField] private Color m_BackgroundColor = Color.clear;
30  [SerializeField] private int m_FontSize = 0;
31  [SerializeField] private FontStyle m_FontStyle = FontStyle.Normal;
32  [SerializeField] private float m_LineSpacing = 1f;
33  [SerializeField] private TextAnchor m_Alignment = TextAnchor.MiddleCenter;
34 #if dUI_TextMeshPro
35  [SerializeField] private TMP_FontAsset m_TMPFont;
36  [SerializeField] private FontStyles m_TMPFontStyle = FontStyles.Normal;
37  [SerializeField] private TextAlignmentOptions m_TMPAlignment = TextAlignmentOptions.Left;
38 #endif
39  public float rotate
45  {
46  get { return m_Rotate; }
47  set { if (PropertyUtil.SetStruct(ref m_Rotate, value)) SetComponentDirty(); }
48  }
54  public Vector2 offset
55  {
56  get { return m_Offset; }
57  set { if (PropertyUtil.SetStruct(ref m_Offset, value)) SetComponentDirty(); }
58  }
59 
60  public Vector3 offsetv3 { get { return new Vector3(m_Offset.x, m_Offset.y, 0); } }
61 
67  public Color color
68  {
69  get { return m_Color; }
70  set { if (PropertyUtil.SetColor(ref m_Color, value)) SetComponentDirty(); }
71  }
77  public Color backgroundColor
78  {
79  get { return m_BackgroundColor; }
80  set { if (PropertyUtil.SetColor(ref m_BackgroundColor, value)) SetComponentDirty(); }
81  }
87  public Font font
88  {
89  get { return m_Font; }
90  set { if (PropertyUtil.SetClass(ref m_Font, value)) SetComponentDirty(); }
91  }
97  public int fontSize
98  {
99  get { return m_FontSize; }
100  set { if (PropertyUtil.SetStruct(ref m_FontSize, value)) SetComponentDirty(); }
101  }
107  public FontStyle fontStyle
108  {
109  get { return m_FontStyle; }
110  set { if (PropertyUtil.SetStruct(ref m_FontStyle, value)) SetComponentDirty(); }
111  }
117  public float lineSpacing
118  {
119  get { return m_LineSpacing; }
120  set { if (PropertyUtil.SetStruct(ref m_LineSpacing, value)) SetComponentDirty(); }
121  }
125  public bool autoWrap
126  {
127  get { return m_AutoWrap; }
128  set { if (PropertyUtil.SetStruct(ref m_AutoWrap, value)) SetComponentDirty(); }
129  }
133  public bool autoAlign
134  {
135  get { return m_AutoAlign; }
136  set { if (PropertyUtil.SetStruct(ref m_AutoAlign, value)) SetComponentDirty(); }
137  }
141  public TextAnchor alignment
142  {
143  get { return m_Alignment; }
144  set { if (PropertyUtil.SetStruct(ref m_Alignment, value)) SetComponentDirty(); }
145  }
146 #if dUI_TextMeshPro
147  public TMP_FontAsset tmpFont
148  {
149  get { return m_TMPFont; }
150  set { if (PropertyUtil.SetClass(ref m_TMPFont, value)) SetComponentDirty(); }
151  }
152 
153  public FontStyles tmpFontStyle
154  {
155  get { return m_TMPFontStyle; }
156  set { if (PropertyUtil.SetStruct(ref m_TMPFontStyle, value)) SetComponentDirty(); }
157  }
158  public TextAlignmentOptions tmpAlignment
159  {
160  get { return m_TMPAlignment; }
161  set { if (PropertyUtil.SetStruct(ref m_TMPAlignment, value)) SetComponentDirty(); }
162  }
163 #endif
164 
165  public TextStyle()
166  {
167  }
168 
169  public TextStyle(int fontSize)
170  {
171  this.fontSize = fontSize;
172  }
173 
174  public TextStyle(int fontSize, FontStyle fontStyle)
175  {
176  this.fontSize = fontSize;
177  this.fontStyle = fontStyle;
178  }
179 
180  public TextStyle(int fontSize, FontStyle fontStyle, Color color)
181  {
182  this.fontSize = fontSize;
183  this.fontStyle = fontStyle;
184  this.color = color;
185  }
186 
187  public TextStyle(int fontSize, FontStyle fontStyle, Color color, int rorate)
188  {
189  this.fontSize = fontSize;
190  this.fontStyle = fontStyle;
191  this.color = color;
192  this.rotate = rotate;
193  }
194 
195  public void Copy(TextStyle textStyle)
196  {
197  font = textStyle.font;
198  rotate = textStyle.rotate;
199  offset = textStyle.offset;
200  color = textStyle.color;
201  backgroundColor = textStyle.backgroundColor;
202  fontSize = textStyle.fontSize;
203  fontStyle = textStyle.fontStyle;
204  lineSpacing = textStyle.lineSpacing;
205  alignment = textStyle.alignment;
206  autoWrap = textStyle.autoWrap;
207  autoAlign = textStyle.autoAlign;
208 #if dUI_TextMeshPro
209  m_TMPFont = textStyle.tmpFont;
210  m_TMPAlignment = textStyle.tmpAlignment;
211  m_TMPFontStyle = textStyle.tmpFontStyle;
212 #endif
213  }
214 
215  public void UpdateAlignmentByLocation(Location location)
216  {
217 #if dUI_TextMeshPro
218  m_TMPAlignment = location.runtimeTMPTextAlignment;
219 #else
220  m_Alignment = location.runtimeTextAlignment;
221 #endif
222  }
223 
224  public Color GetColor(Color defaultColor)
225  {
226  if (ChartHelper.IsClearColor(color)) return defaultColor;
227  else return color;
228  }
229 
230  public int GetFontSize(ComponentTheme defaultTheme)
231  {
232  if (fontSize == 0) return defaultTheme.fontSize;
233  else return fontSize;
234  }
235 
236  public TextAnchor GetAlignment(TextAnchor systemAlignment)
237  {
238  return m_AutoAlign ? systemAlignment : alignment;
239  }
240  }
241 }
XCharts.TextStyle.backgroundColor
Color backgroundColor
the color of text. 文本的背景颜色。 [default: Color.clear]
Definition: TextStyle.cs:78
XCharts.TextStyle
Settings related to text. 文本的相关设置。
Definition: TextStyle.cs:21
XCharts.SubComponent
Definition: ChartComponent.cs:71
XCharts
Definition: RewardChart.cs:14
XCharts.TextStyle.lineSpacing
float lineSpacing
text line spacing. 行间距。 [default: 1f]
Definition: TextStyle.cs:118
XCharts.TextStyle.rotate
float rotate
Rotation of text. 文本的旋转。 [default: 0f]
Definition: TextStyle.cs:45
XCharts.TextStyle.offset
Vector2 offset
the offset of position. 坐标偏移。 [Default: Vector2.zero]
Definition: TextStyle.cs:55
XCharts.TextStyle.fontStyle
FontStyle fontStyle
font style. 文本字体的风格。 [default: FontStyle.Normal]
Definition: TextStyle.cs:108
XCharts.TextStyle.color
Color color
the color of text. 文本的颜色。 [default: Color.clear]
Definition: TextStyle.cs:68
XCharts.TextStyle.autoWrap
bool autoWrap
是否自动换行。
Definition: TextStyle.cs:126
XCharts.TextStyle.alignment
TextAnchor alignment
对齐方式。
Definition: TextStyle.cs:142
XCharts.TextStyle.font
Font font
the font of text. When null, the theme's font is used by default. 文本字体。 [default: null]
Definition: TextStyle.cs:88
XCharts.TextStyle.autoAlign
bool autoAlign
文本是否让系统自动选对齐方式。为false时才会用alignment。
Definition: TextStyle.cs:134
XCharts.TextStyle.fontSize
int fontSize
font size. 文本字体大小。 [default: 18]
Definition: TextStyle.cs:98