Tanoda
LeapTextGraphic.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using System.Collections.Generic;
12
14
16
17 [TextArea]
18 [SerializeField]
19 private string _text;
20
21 [Header("Character")]
22 [EditTimeOnly, SerializeField]
23 private FontStyle _fontStyle;
24
25 [EditTimeOnly, SerializeField]
26 private int _fontSize = 14;
27
28 [EditTimeOnly, SerializeField]
29 private float _lineSpacing = 1;
30
31 [Header("Paragraph")]
32 [EditTimeOnly, SerializeField]
33 private HorizontalAlignment _horizontalAlignment;
34
35 [EditTimeOnly, SerializeField]
36 private VerticalAlignment _verticalAlignment;
37
38 [EditTimeOnly, SerializeField]
39 private Color _color = Color.black;
40
41 private bool _tokensDirty = true;
42 private List<TextWrapper.Token> _cachedTokens = new List<TextWrapper.Token>();
43
44 public List<TextWrapper.Token> tokens {
45 get {
46 if (_tokensDirty) {
47 _cachedTokens.Clear();
48 TextWrapper.Tokenize(text, _cachedTokens);
49 _tokensDirty = false;
50 }
51 return _cachedTokens;
52 }
53 }
54
55 public string text {
56 get {
57 if (_text == null) {
58 return "";
59 } else {
60 return _text;
61 }
62 }
63 set {
64 if (value != _text) {
65 _tokensDirty = true;
66 _text = value;
68 }
69 }
70 }
71
72 public FontStyle fontStyle {
73 get {
74 return _fontStyle;
75 }
76 set {
77 if (value != _fontStyle) {
78 _fontStyle = value;
80 }
81 }
82 }
83
84 public int fontSize {
85 get {
86 return _fontSize;
87 }
88 set {
89 if (value != _fontSize) {
90 _fontSize = value;
92 }
93 }
94 }
95
96 public float lineSpacing {
97 get {
98 return _lineSpacing;
99 }
100 set {
101 if (value != _lineSpacing) {
102 _lineSpacing = value;
104 }
105 }
106 }
107
109 get {
110 return _horizontalAlignment;
111 }
112 set {
113 if (value != _horizontalAlignment) {
114 _horizontalAlignment = value;
116 }
117 }
118 }
119
121 get {
122 return _verticalAlignment;
123 }
124 set {
125 if (value != _verticalAlignment) {
126 _verticalAlignment = value;
128 }
129 }
130 }
131
132 public Color color {
133 get {
134 return _color;
135 }
136 set {
137 if (value != _color) {
138 _color = value;
140 }
141 }
142 }
143
144 protected override void OnValidate() {
145 base.OnValidate();
146
147 _tokensDirty = true;
148 }
149
150 private Rect _prevRect;
151 public bool HasRectChanged() {
152 RectTransform rectTransform = transform as RectTransform;
153 if (rectTransform == null) {
154 return false;
155 }
156
157 Rect newRect = rectTransform.rect;
158 if (newRect != _prevRect) {
159 _prevRect = newRect;
160 return true;
161 }
162
163 return false;
164 }
165
167 Left,
168 Center,
169 Right
170 }
171
172 public enum VerticalAlignment {
173 Top,
174 Center,
175 Bottom
176 }
177 }
178}
UnityEngine.Color Color
Definition: TestScript.cs:32
bool isRepresentationDirty
An internal flag that returns true if the visual representation of this graphic needs to be updated....
Definition: LeapGraphic.cs:64