Hue Preserving Color Blending
TMP_Settings.cs
1 using UnityEngine;
2 using System.Collections;
3 using System.Collections.Generic;
4 
5 
6 #pragma warning disable 0649 // Disabled warnings related to serialized fields not assigned in this script but used in the editor.
7 
8 namespace TMPro
9 {
10  [System.Serializable]
11  [ExecuteInEditMode]
12  public class TMP_Settings : ScriptableObject
13  {
14  private static TMP_Settings s_Instance;
15 
19  public static string version
20  {
21  get { return "1.3.0"; }
22  }
23 
27  public static bool enableWordWrapping
28  {
29  get { return instance.m_enableWordWrapping; }
30  }
31  [SerializeField]
32  private bool m_enableWordWrapping;
33 
37  public static bool enableKerning
38  {
39  get { return instance.m_enableKerning; }
40  }
41  [SerializeField]
42  private bool m_enableKerning;
43 
47  public static bool enableExtraPadding
48  {
49  get { return instance.m_enableExtraPadding; }
50  }
51  [SerializeField]
52  private bool m_enableExtraPadding;
53 
57  public static bool enableTintAllSprites
58  {
59  get { return instance.m_enableTintAllSprites; }
60  }
61  [SerializeField]
62  private bool m_enableTintAllSprites;
63 
67  public static bool enableParseEscapeCharacters
68  {
69  get { return instance.m_enableParseEscapeCharacters; }
70  }
71  [SerializeField]
72  private bool m_enableParseEscapeCharacters;
73 
77  public static int missingGlyphCharacter
78  {
79  get { return instance.m_missingGlyphCharacter; }
80  }
81  [SerializeField]
82  private int m_missingGlyphCharacter;
83 
87  public static bool warningsDisabled
88  {
89  get { return instance.m_warningsDisabled; }
90  }
91  [SerializeField]
92  private bool m_warningsDisabled;
93 
97  public static TMP_FontAsset defaultFontAsset
98  {
99  get { return instance.m_defaultFontAsset; }
100  }
101  [SerializeField]
102  private TMP_FontAsset m_defaultFontAsset;
103 
107  public static string defaultFontAssetPath
108  {
109  get { return instance.m_defaultFontAssetPath; }
110  }
111  [SerializeField]
112  private string m_defaultFontAssetPath;
113 
117  public static float defaultFontSize
118  {
119  get { return instance.m_defaultFontSize; }
120  }
121  [SerializeField]
122  private float m_defaultFontSize;
123 
127  public static float defaultTextAutoSizingMinRatio
128  {
129  get { return instance.m_defaultAutoSizeMinRatio; }
130  }
131  [SerializeField]
132  private float m_defaultAutoSizeMinRatio;
133 
137  public static float defaultTextAutoSizingMaxRatio
138  {
139  get { return instance.m_defaultAutoSizeMaxRatio; }
140  }
141  [SerializeField]
142  private float m_defaultAutoSizeMaxRatio;
143 
147  public static Vector2 defaultTextMeshProTextContainerSize
148  {
149  get { return instance.m_defaultTextMeshProTextContainerSize; }
150  }
151  [SerializeField]
152  private Vector2 m_defaultTextMeshProTextContainerSize;
153 
157  public static Vector2 defaultTextMeshProUITextContainerSize
158  {
159  get { return instance.m_defaultTextMeshProUITextContainerSize; }
160  }
161  [SerializeField]
162  private Vector2 m_defaultTextMeshProUITextContainerSize;
163 
167  public static bool autoSizeTextContainer
168  {
169  get { return instance.m_autoSizeTextContainer; }
170  }
171  [SerializeField]
172  private bool m_autoSizeTextContainer;
173 
177  public static List<TMP_FontAsset> fallbackFontAssets
178  {
179  get { return instance.m_fallbackFontAssets; }
180  }
181  [SerializeField]
182  private List<TMP_FontAsset> m_fallbackFontAssets;
183 
187  public static bool matchMaterialPreset
188  {
189  get { return instance.m_matchMaterialPreset; }
190  }
191  [SerializeField]
192  private bool m_matchMaterialPreset;
193 
197  public static TMP_SpriteAsset defaultSpriteAsset
198  {
199  get { return instance.m_defaultSpriteAsset; }
200  }
201  [SerializeField]
202  private TMP_SpriteAsset m_defaultSpriteAsset;
203 
207  public static string defaultSpriteAssetPath
208  {
209  get { return instance.m_defaultSpriteAssetPath; }
210  }
211  [SerializeField]
212  private string m_defaultSpriteAssetPath;
213 
217  public static string defaultColorGradientPresetsPath
218  {
219  get { return instance.m_defaultColorGradientPresetsPath; }
220  }
221  [SerializeField]
222  private string m_defaultColorGradientPresetsPath;
223 
227  public static bool enableEmojiSupport
228  {
229  get { return instance.m_enableEmojiSupport; }
230  set { instance.m_enableEmojiSupport = value; }
231  }
232  [SerializeField]
233  private bool m_enableEmojiSupport;
234 
238  public static TMP_StyleSheet defaultStyleSheet
239  {
240  get { return instance.m_defaultStyleSheet; }
241  }
242  [SerializeField]
243  private TMP_StyleSheet m_defaultStyleSheet;
244 
248  public static TextAsset leadingCharacters
249  {
250  get { return instance.m_leadingCharacters; }
251  }
252  [SerializeField]
253  private TextAsset m_leadingCharacters;
254 
258  public static TextAsset followingCharacters
259  {
260  get { return instance.m_followingCharacters; }
261  }
262  [SerializeField]
263  private TextAsset m_followingCharacters;
264 
268  public static LineBreakingTable linebreakingRules
269  {
270  get
271  {
272  if (instance.m_linebreakingRules == null)
273  LoadLinebreakingRules();
274 
275  return instance.m_linebreakingRules;
276  }
277  }
278  [SerializeField]
279  private LineBreakingTable m_linebreakingRules;
280 
284  public static TMP_Settings instance
285  {
286  get
287  {
288  if (TMP_Settings.s_Instance == null)
289  {
290  TMP_Settings.s_Instance = Resources.Load<TMP_Settings>("TMP Settings");
291 
292  #if UNITY_EDITOR
293  // Make sure TextMesh Pro UPM packages resources have been added to the user project
294  if (TMP_Settings.s_Instance == null)
295  {
296  // Open TMP Resources Importer
297  PackageResourceImporterWindow.ShowPackageImporterWindow();
298  }
299  #endif
300  }
301 
302  return TMP_Settings.s_Instance;
303  }
304  }
305 
306 
312  {
313  if (s_Instance == null)
314  {
315  // Load settings from TMP_Settings file
316  TMP_Settings settings = Resources.Load<TMP_Settings>("TMP Settings");
317  if (settings != null)
318  s_Instance = settings;
319  }
320 
321  return s_Instance;
322  }
323 
324 
329  public static TMP_Settings GetSettings()
330  {
331  if (TMP_Settings.instance == null) return null;
332 
333  return TMP_Settings.instance;
334  }
335 
336 
341  public static TMP_FontAsset GetFontAsset()
342  {
343  if (TMP_Settings.instance == null) return null;
344 
345  return TMP_Settings.instance.m_defaultFontAsset;
346  }
347 
348 
354  {
355  if (TMP_Settings.instance == null) return null;
356 
357  return TMP_Settings.instance.m_defaultSpriteAsset;
358  }
359 
360 
366  {
367  if (TMP_Settings.instance == null) return null;
368 
369  return TMP_Settings.instance.m_defaultStyleSheet;
370  }
371 
372 
373  public static void LoadLinebreakingRules()
374  {
375  //Debug.Log("Loading Line Breaking Rules for Asian Languages.");
376 
377  if (TMP_Settings.instance == null) return;
378 
379  if (s_Instance.m_linebreakingRules == null)
380  s_Instance.m_linebreakingRules = new LineBreakingTable();
381 
382  s_Instance.m_linebreakingRules.leadingCharacters = GetCharacters(s_Instance.m_leadingCharacters);
383  s_Instance.m_linebreakingRules.followingCharacters = GetCharacters(s_Instance.m_followingCharacters);
384  }
385 
386 
392  private static Dictionary<int, char> GetCharacters(TextAsset file)
393  {
394  Dictionary<int, char> dict = new Dictionary<int, char>();
395  string text = file.text;
396 
397  for (int i = 0; i < text.Length; i++)
398  {
399  char c = text[i];
400  // Check to make sure we don't include duplicates
401  if (dict.ContainsKey((int)c) == false)
402  {
403  dict.Add((int)c, c);
404  //Debug.Log("Adding [" + (int)c + "] to dictionary.");
405  }
406  //else
407  // Debug.Log("Character [" + text[i] + "] is a duplicate.");
408  }
409 
410  return dict;
411  }
412 
413 
414  public class LineBreakingTable
415  {
416  public Dictionary<int, char> leadingCharacters;
417  public Dictionary<int, char> followingCharacters;
418  }
419  }
420 }
static string version
Returns the release version of the product.
Definition: TMP_Settings.cs:20
static bool enableKerning
Controls if Kerning is enabled on newly created text objects by default.
Definition: TMP_Settings.cs:38
static string defaultFontAssetPath
The relative path to a Resources folder in the project.
static bool enableParseEscapeCharacters
Controls if Escape Characters will be parsed in the Text Input Box on newly created text objects.
Definition: TMP_Settings.cs:68
static TMP_StyleSheet defaultStyleSheet
The Default Style Sheet used by the text objects.
static bool autoSizeTextContainer
Set the size of the text container of newly created text objects to match the size of the text.
static TextAsset followingCharacters
Text file that contains the following characters used for line breaking for Asian languages.
static float defaultFontSize
The Default Point Size of newly created text objects.
static string defaultSpriteAssetPath
The relative path to a Resources folder in the project.
static Vector2 defaultTextMeshProTextContainerSize
The Default Size of the Text Container of a TextMeshPro object.
static TMP_FontAsset defaultFontAsset
Returns the Default Font Asset to be used by newly created text objects.
Definition: TMP_Settings.cs:98
static TMP_Settings instance
Get a singleton instance of the settings class.
static TMP_FontAsset GetFontAsset()
Returns the Font Asset defined in the TMP Settings file.
static TMP_SpriteAsset GetSpriteAsset()
Returns the Sprite Asset defined in the TMP Settings file.
static TMP_Settings GetSettings()
Returns the Sprite Asset defined in the TMP Settings file.
static bool enableTintAllSprites
Controls if TintAllSprites is enabled on newly created text objects by default.
Definition: TMP_Settings.cs:58
static int missingGlyphCharacter
The character the will be used as a replacement for missing glyphs in a font asset.
Definition: TMP_Settings.cs:78
static bool enableEmojiSupport
Determines if Emoji support is enabled in the Input Field TouchScreenKeyboard.
static bool enableWordWrapping
Controls if Word Wrapping will be enabled on newly created text objects by default.
Definition: TMP_Settings.cs:28
static bool enableExtraPadding
Controls if Extra Padding is enabled on newly created text objects by default.
Definition: TMP_Settings.cs:48
static TextAsset leadingCharacters
Text file that contains the leading characters used for line breaking for Asian languages.
static bool matchMaterialPreset
Controls whether or not TMP will create a matching material preset or use the default material of the...
static Vector2 defaultTextMeshProUITextContainerSize
The Default Width of the Text Container of a TextMeshProUI object.
static TMP_Settings LoadDefaultSettings()
Static Function to load the TMP Settings file.
static float defaultTextAutoSizingMaxRatio
The multiplier used to computer the default Max point size when Text Auto Sizing is used.
static bool warningsDisabled
Controls the display of warning message in the console.
Definition: TMP_Settings.cs:88
static string defaultColorGradientPresetsPath
The relative path to a Resources folder in the project that contains Color Gradient Presets.
static float defaultTextAutoSizingMinRatio
The multiplier used to computer the default Min point size when Text Auto Sizing is used.
static TMP_StyleSheet GetStyleSheet()
Returns the Sprite Asset defined in the TMP Settings file.
static List< TMP_FontAsset > fallbackFontAssets
Returns the list of Fallback Fonts defined in the TMP Settings file.
static TMP_SpriteAsset defaultSpriteAsset
The Default Sprite Asset to be used by default.
static Dictionary< int, char > GetCharacters(TextAsset file)
Get the characters from the line breaking files
static LineBreakingTable linebreakingRules