-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathFontAssetEditor.cs
More file actions
3052 lines (2393 loc) · 142 KB
/
Copy pathFontAssetEditor.cs
File metadata and controls
3052 lines (2393 loc) · 142 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using UnityEngine;
using UnityEditorInternal;
using System.Collections.Generic;
using UnityEngine.TextCore.Text;
using UnityEngine.TextCore.LowLevel;
using UnityEditor.TextCore.LowLevel;
using Glyph = UnityEngine.TextCore.Glyph;
using GlyphRect = UnityEngine.TextCore.GlyphRect;
using GlyphMetrics = UnityEngine.TextCore.GlyphMetrics;
#pragma warning disable CS0618 // Font feature tables and OTL feature tags; TextCoreShaderGUI, TextCoreShaderGUISDF, TextCoreShaderGUIBitmap, TextShaderUtilities are obsolete; handled natively by ATG
namespace UnityEditor.TextCore.Text
{
[CustomPropertyDrawer(typeof(FontWeightPair))]
internal class FontWeightDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
SerializedProperty prop_regular = property.FindPropertyRelative("regularTypeface");
SerializedProperty prop_italic = property.FindPropertyRelative("italicTypeface");
float width = position.width;
position.width = EditorGUIUtility.labelWidth;
EditorGUI.LabelField(position, label);
int oldIndent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
// NORMAL TYPEFACE
if (label.text[0] == '4') GUI.enabled = false;
position.x += position.width; position.width = (width - position.width) / 2;
EditorGUI.PropertyField(position, prop_regular, GUIContent.none);
// ITALIC TYPEFACE
GUI.enabled = true;
position.x += position.width;
EditorGUI.PropertyField(position, prop_italic, GUIContent.none);
EditorGUI.indentLevel = oldIndent;
}
}
[CustomEditor(typeof(FontAsset))]
internal class FontAssetEditor : Editor
{
internal struct UI_PanelState
{
public static bool generationSettingsPanel = true;
public static bool fontAtlasInfoPanel = true;
public static bool fontWeightPanel = true;
public static bool fallbackFontAssetPanel = true;
public static bool glyphTablePanel = false;
public static bool characterTablePanel = false;
public static bool LigatureSubstitutionTablePanel;
public static bool PairAdjustmentTablePanel = false;
public static bool MarkToBaseTablePanel = false;
public static bool MarkToMarkTablePanel = false;
}
internal struct GenerationSettings
{
public Font sourceFont;
public int faceIndex;
public GlyphRenderMode glyphRenderMode;
public float pointSize;
public int padding;
public int atlasWidth;
public int atlasHeight;
}
/// <summary>
/// Material used to display SDF glyphs in the Character and Glyph tables.
/// </summary>
internal static Material internalSDFMaterial
{
get
{
if (s_InternalSDFMaterial == null)
{
Shader shader = TextShaderUtilities.ShaderRef_MobileSDF;
if (shader != null)
s_InternalSDFMaterial = new Material(shader);
}
return s_InternalSDFMaterial;
}
}
static Material s_InternalSDFMaterial;
/// <summary>
/// Material used to display Bitmap glyphs in the Character and Glyph tables.
/// </summary>
internal static Material internalBitmapMaterial
{
get
{
if (s_InternalBitmapMaterial == null)
{
Shader shader = Shader.Find("Hidden/Internal-GUITextureClipText");
if (shader != null)
s_InternalBitmapMaterial = new Material(shader);
}
return s_InternalBitmapMaterial;
}
}
static Material s_InternalBitmapMaterial;
/// <summary>
/// Material used to display color glyphs in the Character and Glyph tables.
/// </summary>
internal static Material internalRGBABitmapMaterial
{
get
{
if (s_Internal_Bitmap_RGBA_Material == null)
{
Shader shader = Shader.Find("Hidden/Internal-GUITextureClip");
if (shader != null)
s_Internal_Bitmap_RGBA_Material = new Material(shader);
}
return s_Internal_Bitmap_RGBA_Material;
}
}
static Material s_Internal_Bitmap_RGBA_Material;
private static string[] s_UiStateLabel = new string[] { "<i>(Click to collapse)</i> ", "<i>(Click to expand)</i> " };
public static readonly GUIContent getFontFeaturesLabel = new GUIContent("Get Font Features", "Determines if OpenType font features should be retrieved from the source font file as new characters and glyphs are added to the font asset.");
private GUIContent[] m_AtlasResolutionLabels = { new GUIContent("8"), new GUIContent("16"), new GUIContent("32"), new GUIContent("64"), new GUIContent("128"), new GUIContent("256"), new GUIContent("512"), new GUIContent("1024"), new GUIContent("2048"), new GUIContent("4096"), new GUIContent("8192") };
private int[] m_AtlasResolutions = { 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
private struct Warning
{
public bool isEnabled;
public double expirationTime;
}
private int m_CurrentGlyphPage = 0;
private int m_CurrentCharacterPage = 0;
private int m_CurrentLigaturePage = 0;
private int m_CurrentAdjustmentPairPage = 0;
private int m_CurrentMarkToBasePage = 0;
private int m_CurrentMarkToMarkPage = 0;
internal int m_SelectedGlyphRecord = -1;
internal int m_SelectedCharacterRecord = -1;
internal int m_SelectedLigatureRecord = -1;
internal int m_SelectedAdjustmentRecord = -1;
internal int m_SelectedMarkToBaseRecord = -1;
internal int m_SelectedMarkToMarkRecord = -1;
enum RecordSelectionType { CharacterRecord, GlyphRecord, LigatureSubstitutionRecord, AdjustmentPairRecord, MarkToBaseRecord, MarkToMarkRecord }
private string m_dstGlyphID;
private string m_dstUnicode;
private const string k_placeholderUnicodeHex = "<i>New Unicode (Hex)</i>";
private string m_unicodeHexLabel = k_placeholderUnicodeHex;
private const string k_placeholderGlyphID = "<i>New Glyph ID</i>";
private string m_GlyphIDLabel = k_placeholderGlyphID;
private Warning m_AddGlyphWarning;
private Warning m_AddCharacterWarning;
private bool m_DisplayDestructiveChangeWarning;
private GenerationSettings m_GenerationSettings;
private bool m_MaterialPresetsRequireUpdate;
private static readonly string[] k_InvalidFontFaces = { string.Empty };
private string[] m_FontFaces;
private bool m_FaceInfoDirty;
private string m_GlyphSearchPattern;
private List<int> m_GlyphSearchList;
private string m_LigatureTableSearchPattern;
private List<int> m_LigatureTableSearchList;
private string m_CharacterSearchPattern;
private List<int> m_CharacterSearchList;
private string m_KerningTableSearchPattern;
private List<int> m_KerningTableSearchList;
private string m_MarkToBaseTableSearchPattern;
private List<int> m_MarkToBaseTableSearchList;
private string m_MarkToMarkTableSearchPattern;
private List<int> m_MarkToMarkTableSearchList;
private HashSet<uint> m_GlyphsToAdd;
private bool m_isSearchDirty;
private const string k_UndoRedo = "UndoRedoPerformed";
private SerializedProperty m_AtlasPopulationMode_prop;
private SerializedProperty font_atlas_prop;
private SerializedProperty font_material_prop;
private SerializedProperty m_FontFaceIndex_prop;
private SerializedProperty m_AtlasRenderMode_prop;
private SerializedProperty m_SamplingPointSize_prop;
private SerializedProperty m_AtlasPadding_prop;
private SerializedProperty m_AtlasWidth_prop;
private SerializedProperty m_AtlasHeight_prop;
private SerializedProperty m_IsMultiAtlasTexturesEnabled_prop;
private SerializedProperty m_ClearDynamicDataOnBuild_prop;
private SerializedProperty m_GetFontFeatures_prop;
private SerializedProperty fontWeights_prop;
//private SerializedProperty fallbackFontAssets_prop;
private ReorderableList m_FallbackFontAssetList;
private SerializedProperty font_normalStyle_prop;
private SerializedProperty font_normalSpacing_prop;
private SerializedProperty font_boldStyle_prop;
private SerializedProperty font_boldSpacing_prop;
private SerializedProperty font_italicStyle_prop;
private SerializedProperty font_tabSize_prop;
private SerializedProperty m_FaceInfo_prop;
private SerializedProperty m_GlyphTable_prop;
private SerializedProperty m_CharacterTable_prop;
private FontFeatureTable m_FontFeatureTable;
private SerializedProperty m_FontFeatureTable_prop;
private SerializedProperty m_GlyphPairAdjustmentRecords_prop;
private SerializedProperty m_LigatureSubstitutionRecords_prop;
private SerializedProperty m_MarkToBaseAdjustmentRecords_prop;
private SerializedProperty m_MarkToMarkAdjustmentRecords_prop;
private SerializedProperty m_ShowObsoleteProperties_prop;
private SerializedPropertyHolder m_SerializedPropertyHolder;
private SerializedProperty m_EmptyGlyphPairAdjustmentRecord_prop;
private SerializedProperty m_FirstCharacterUnicode_prop;
private SerializedProperty m_SecondCharacterUnicode_prop;
// private string m_SecondCharacter;
// private uint m_SecondGlyphIndex;
private FontAsset m_fontAsset;
private Material[] m_materialPresets;
private bool isAssetDirty = false;
private bool m_IsFallbackGlyphCacheDirty;
private int errorCode;
private System.DateTime timeStamp;
public void OnEnable()
{
m_FaceInfo_prop = serializedObject.FindProperty("m_FaceInfo");
font_atlas_prop = serializedObject.FindProperty("m_AtlasTextures").GetArrayElementAtIndex(0);
font_material_prop = serializedObject.FindProperty("m_Material");
m_FontFaceIndex_prop = m_FaceInfo_prop.FindPropertyRelative("m_FaceIndex");
m_AtlasPopulationMode_prop = serializedObject.FindProperty("m_AtlasPopulationMode");
m_AtlasRenderMode_prop = serializedObject.FindProperty("m_AtlasRenderMode");
m_SamplingPointSize_prop = m_FaceInfo_prop.FindPropertyRelative("m_PointSize");
m_AtlasPadding_prop = serializedObject.FindProperty("m_AtlasPadding");
m_AtlasWidth_prop = serializedObject.FindProperty("m_AtlasWidth");
m_AtlasHeight_prop = serializedObject.FindProperty("m_AtlasHeight");
m_IsMultiAtlasTexturesEnabled_prop = serializedObject.FindProperty("m_IsMultiAtlasTexturesEnabled");
m_ClearDynamicDataOnBuild_prop = serializedObject.FindProperty("m_ClearDynamicDataOnBuild");
m_GetFontFeatures_prop = serializedObject.FindProperty("m_GetFontFeatures");
m_ShowObsoleteProperties_prop = serializedObject.FindProperty("m_ShowObsoleteProperties");
fontWeights_prop = serializedObject.FindProperty("m_FontWeightTable");
m_FallbackFontAssetList = PrepareReorderableList(serializedObject.FindProperty("m_FallbackFontAssetTable"), "Fallback Font Assets");
// Clean up fallback list in the event if contains null elements.
CleanFallbackFontAssetTable();
font_normalStyle_prop = serializedObject.FindProperty("m_RegularStyleWeight");
font_normalSpacing_prop = serializedObject.FindProperty("m_RegularStyleSpacing");
font_boldStyle_prop = serializedObject.FindProperty("m_BoldStyleWeight");
font_boldSpacing_prop = serializedObject.FindProperty("m_BoldStyleSpacing");
font_italicStyle_prop = serializedObject.FindProperty("m_ItalicStyleSlant");
font_tabSize_prop = serializedObject.FindProperty("m_TabMultiple");
m_CharacterTable_prop = serializedObject.FindProperty("m_CharacterTable");
m_GlyphTable_prop = serializedObject.FindProperty("m_GlyphTable");
m_FontFeatureTable_prop = serializedObject.FindProperty("m_FontFeatureTable");
m_LigatureSubstitutionRecords_prop = m_FontFeatureTable_prop.FindPropertyRelative("m_LigatureSubstitutionRecords");
m_GlyphPairAdjustmentRecords_prop = m_FontFeatureTable_prop.FindPropertyRelative("m_GlyphPairAdjustmentRecords");
m_MarkToBaseAdjustmentRecords_prop = m_FontFeatureTable_prop.FindPropertyRelative("m_MarkToBaseAdjustmentRecords");
m_MarkToMarkAdjustmentRecords_prop = m_FontFeatureTable_prop.FindPropertyRelative("m_MarkToMarkAdjustmentRecords");
m_fontAsset = target as FontAsset;
m_FontFeatureTable = m_fontAsset.fontFeatureTable;
// Get Font Faces and Styles
m_FontFaces = GetFontFaces();
// Create serialized object to allow us to use a serialized property of an empty kerning pair.
m_SerializedPropertyHolder = CreateInstance<SerializedPropertyHolder>();
m_SerializedPropertyHolder.fontAsset = m_fontAsset;
SerializedObject internalSerializedObject = new SerializedObject(m_SerializedPropertyHolder);
m_FirstCharacterUnicode_prop = internalSerializedObject.FindProperty("firstCharacter");
m_SecondCharacterUnicode_prop = internalSerializedObject.FindProperty("secondCharacter");
m_EmptyGlyphPairAdjustmentRecord_prop = internalSerializedObject.FindProperty("glyphPairAdjustmentRecord");
m_materialPresets = TextCoreEditorUtilities.FindMaterialReferences(m_fontAsset);
m_GlyphSearchList = new List<int>();
m_KerningTableSearchList = new List<int>();
// Sort Font Asset Tables
m_fontAsset.SortAllTables();
// Clear glyph proxy lookups
TextCorePropertyDrawerUtilities.ClearGlyphProxyLookups();
}
private ReorderableList PrepareReorderableList(SerializedProperty property, string label)
{
SerializedObject so = property.serializedObject;
ReorderableList list = new ReorderableList(so, property, true, true, true, true);
list.drawHeaderCallback = rect =>
{
EditorGUI.LabelField(rect, label);
};
list.drawElementCallback = (rect, index, isActive, isFocused) =>
{
var element = list.serializedProperty.GetArrayElementAtIndex(index);
rect.y += 2;
EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element, GUIContent.none);
};
list.onChangedCallback = itemList => { };
return list;
}
public void OnDisable()
{
// Revert changes if user closes or changes selection without having made a choice.
if (m_DisplayDestructiveChangeWarning)
{
m_DisplayDestructiveChangeWarning = false;
RestoreGenerationSettings();
GUIUtility.keyboardControl = 0;
serializedObject.ApplyModifiedProperties();
}
}
public override void OnInspectorGUI()
{
Event currentEvent = Event.current;
serializedObject.Update();
if (m_ShowObsoleteProperties_prop.boolValue)
{
EditorGUILayout.HelpBox(
"These properties are only available in TextCore and will be removed in a future version. " +
"It is highly recommended to upgrade to ATG (Advanced Text Generator) and disable this option.",
MessageType.Warning, true);
}
EditorGUILayout.Space();
Rect rect = EditorGUILayout.GetControlRect(false, 24);
float labelWidth = EditorGUIUtility.labelWidth;
float fieldWidth = EditorGUIUtility.fieldWidth;
// FACE INFO PANEL
#region Face info
GUI.Label(rect, new GUIContent("<b>Face Info</b> - v" + m_fontAsset.version), TM_EditorStyles.sectionHeader);
// Show/Hide Obsolete Properties button
string obsoleteButtonText = m_ShowObsoleteProperties_prop.boolValue ? "Hide Obsolete Properties" : "Show Obsolete Properties";
Rect obsoleteButtonRect = new Rect(rect.x + rect.width - 300f, rect.y + 2, 160f, 18f);
if (GUI.Button(obsoleteButtonRect, new GUIContent(obsoleteButtonText)))
{
m_ShowObsoleteProperties_prop.boolValue = !m_ShowObsoleteProperties_prop.boolValue;
serializedObject.ApplyModifiedProperties();
}
rect.x += rect.width - 132f;
rect.y += 2;
rect.width = 130f;
rect.height = 18f;
if (GUI.Button(rect, new GUIContent("Update Atlas Texture")))
{
FontAssetCreatorWindow.ShowFontAtlasCreatorWindow(target as FontAsset);
}
EditorGUI.indentLevel = 1;
GUI.enabled = false; // Lock UI
// TODO : Consider creating a property drawer for these.
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_FamilyName"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_StyleName"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_PointSize"));
GUI.enabled = true;
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_Scale"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_LineHeight"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_AscentLine"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_CapLine"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_MeanLine"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_Baseline"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_DescentLine"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_UnderlineOffset"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_UnderlineThickness"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_StrikethroughOffset"));
//EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("strikethroughThickness"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_SuperscriptOffset"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_SuperscriptSize"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_SubscriptOffset"));
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_SubscriptSize"));
if (m_ShowObsoleteProperties_prop.boolValue)
EditorGUILayout.PropertyField(m_FaceInfo_prop.FindPropertyRelative("m_TabWidth"));
// TODO : Add clamping for some of these values.
//subSize_prop.floatValue = Mathf.Clamp(subSize_prop.floatValue, 0.25f, 1f);
EditorGUILayout.Space();
#endregion
// GENERATION SETTINGS
#region Generation Settings
rect = EditorGUILayout.GetControlRect(false, 24);
if (GUI.Button(rect, new GUIContent("<b>Generation Settings</b>"), TM_EditorStyles.sectionHeader))
UI_PanelState.generationSettingsPanel = !UI_PanelState.generationSettingsPanel;
GUI.Label(rect, (UI_PanelState.generationSettingsPanel ? "" : s_UiStateLabel[1]), TM_EditorStyles.rightLabel);
if (UI_PanelState.generationSettingsPanel)
{
EditorGUI.indentLevel = 1;
EditorGUI.BeginChangeCheck();
Font sourceFont = (Font)EditorGUILayout.ObjectField("Source Font File", m_fontAsset.SourceFont_EditorRef, typeof(Font), false);
if (EditorGUI.EndChangeCheck())
{
UpdateSourceFontFile(sourceFont);
}
EditorGUI.BeginDisabledGroup(sourceFont == null);
{
EditorGUI.BeginChangeCheck();
m_FontFaceIndex_prop.intValue = EditorGUILayout.Popup(new GUIContent("Font Face"), m_FontFaceIndex_prop.intValue, m_FontFaces);
if (EditorGUI.EndChangeCheck())
{
UpdateFontFaceIndex(m_FontFaceIndex_prop.intValue);
}
EditorGUI.BeginChangeCheck();
m_AtlasPopulationMode_prop.intValue = EditorGUILayout.IntPopup(
new GUIContent("Atlas Population Mode"),
m_AtlasPopulationMode_prop.intValue,
new[] { new GUIContent("Static (Obsolete)"), new GUIContent("Dynamic"), new GUIContent("Dynamic OS") },
new[] { (int)AtlasPopulationMode.Static, (int)AtlasPopulationMode.Dynamic, (int)AtlasPopulationMode.DynamicOS });
if (EditorGUI.EndChangeCheck())
{
UpdateAtlasPopulationMode(m_AtlasPopulationMode_prop.intValue);
}
// Save state of atlas settings
if (m_DisplayDestructiveChangeWarning == false)
{
SavedGenerationSettings();
//Undo.RegisterCompleteObjectUndo(m_fontAsset, "Font Asset Changes");
}
EditorGUI.BeginDisabledGroup(m_AtlasPopulationMode_prop.intValue == (int)AtlasPopulationMode.Static);
{
EditorGUI.BeginChangeCheck();
// TODO: Switch shaders depending on GlyphRenderMode.
var glyphRenderValues = (GlyphRenderMode[])Enum.GetValues(typeof(GlyphRenderMode));
GlyphRenderMode currentValue = glyphRenderValues[m_AtlasRenderMode_prop.enumValueIndex];
GlyphRenderModeUI selectedUI = (GlyphRenderModeUI)currentValue;
selectedUI = (GlyphRenderModeUI)EditorGUILayout.EnumPopup("Render Mode", selectedUI);
GlyphRenderMode updatedValue = (GlyphRenderMode)selectedUI;
if (updatedValue != currentValue)
{
int updatedIndex = Array.IndexOf(glyphRenderValues, updatedValue);
m_AtlasRenderMode_prop.enumValueIndex = updatedIndex;
m_DisplayDestructiveChangeWarning = true;
}
EditorGUILayout.PropertyField(m_SamplingPointSize_prop, new GUIContent("Sampling Point Size"));
if (EditorGUI.EndChangeCheck())
{
m_DisplayDestructiveChangeWarning = true;
}
// Changes to these properties require updating Material Presets for this font asset.
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_AtlasPadding_prop, new GUIContent("Padding"));
EditorGUILayout.IntPopup(m_AtlasWidth_prop, m_AtlasResolutionLabels, m_AtlasResolutions, new GUIContent("Atlas Width"));
EditorGUILayout.IntPopup(m_AtlasHeight_prop, m_AtlasResolutionLabels, m_AtlasResolutions, new GUIContent("Atlas Height"));
EditorGUILayout.PropertyField(m_IsMultiAtlasTexturesEnabled_prop, new GUIContent("Multi Atlas Textures", "Determines if the font asset will store glyphs in multiple atlas textures."));
if (EditorGUI.EndChangeCheck())
{
if (m_AtlasPadding_prop.intValue < 0)
{
m_AtlasPadding_prop.intValue = 0;
serializedObject.ApplyModifiedProperties();
}
m_MaterialPresetsRequireUpdate = true;
m_DisplayDestructiveChangeWarning = true;
}
EditorGUILayout.PropertyField(m_ClearDynamicDataOnBuild_prop, new GUIContent("Clear Dynamic Data On Build", "Clears all dynamic data restoring the font asset back to its default creation and empty state."));
if (m_ShowObsoleteProperties_prop.boolValue)
{
EditorGUILayout.PropertyField(m_GetFontFeatures_prop, getFontFeaturesLabel);
}
EditorGUILayout.Space();
if (m_DisplayDestructiveChangeWarning)
{
bool guiEnabledState = GUI.enabled;
GUI.enabled = true;
// These changes are destructive on the font asset
rect = EditorGUILayout.GetControlRect(false, 60);
rect.x += 15;
rect.width -= 15;
EditorGUI.HelpBox(rect, "Changing these settings will clear the font asset's character, glyph and texture data.", MessageType.Warning);
if (GUI.Button(new Rect(rect.width - 140, rect.y + 36, 80, 18), new GUIContent("Apply")))
{
ApplyDestructiveChanges();
}
if (GUI.Button(new Rect(rect.width - 56, rect.y + 36, 80, 18), new GUIContent("Revert")))
{
RevertDestructiveChanges();
}
GUI.enabled = guiEnabledState;
}
}
EditorGUI.EndDisabledGroup();
}
EditorGUI.EndDisabledGroup();
EditorGUILayout.Space();
}
#endregion
// ATLAS & MATERIAL PANEL
#region Atlas & Material
rect = EditorGUILayout.GetControlRect(false, 24);
if (GUI.Button(rect, new GUIContent("<b>Atlas & Material</b>"), TM_EditorStyles.sectionHeader))
UI_PanelState.fontAtlasInfoPanel = !UI_PanelState.fontAtlasInfoPanel;
GUI.Label(rect, (UI_PanelState.fontAtlasInfoPanel ? "" : s_UiStateLabel[1]), TM_EditorStyles.rightLabel);
if (UI_PanelState.fontAtlasInfoPanel)
{
EditorGUI.indentLevel = 1;
GUI.enabled = false;
EditorGUILayout.PropertyField(font_atlas_prop, new GUIContent("Font Atlas"));
EditorGUILayout.PropertyField(font_material_prop, new GUIContent("Font Material"));
GUI.enabled = true;
EditorGUILayout.Space();
}
#endregion
string evt_cmd = Event.current.commandName; // Get Current Event CommandName to check for Undo Events
// FONT WEIGHT PANEL
#region Font Weights
rect = EditorGUILayout.GetControlRect(false, 24);
if (GUI.Button(rect, new GUIContent("<b>Font Weights</b>", "The Font Assets that will be used for different font weights and the settings used to simulate a typeface when no asset is available."), TM_EditorStyles.sectionHeader))
UI_PanelState.fontWeightPanel = !UI_PanelState.fontWeightPanel;
GUI.Label(rect, (UI_PanelState.fontWeightPanel ? "" : s_UiStateLabel[1]), TM_EditorStyles.rightLabel);
if (UI_PanelState.fontWeightPanel)
{
EditorGUIUtility.labelWidth *= 0.75f;
EditorGUIUtility.fieldWidth *= 0.25f;
EditorGUILayout.BeginVertical();
EditorGUI.indentLevel = 1;
rect = EditorGUILayout.GetControlRect(true);
rect.x += EditorGUIUtility.labelWidth;
rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f;
GUI.Label(rect, "Regular Typeface", EditorStyles.label);
rect.x += rect.width;
GUI.Label(rect, "Italic Typeface", EditorStyles.label);
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(1), new GUIContent("100 - Thin"));
EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(2), new GUIContent("200 - Extra-Light"));
EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(3), new GUIContent("300 - Light"));
EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(4), new GUIContent("400 - Regular"));
EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(5), new GUIContent("500 - Medium"));
EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(6), new GUIContent("600 - Semi-Bold"));
EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(7), new GUIContent("700 - Bold"));
EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(8), new GUIContent("800 - Heavy"));
EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(9), new GUIContent("900 - Black"));
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
EditorGUILayout.BeginVertical();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(font_normalStyle_prop, new GUIContent("Regular Weight"));
font_normalStyle_prop.floatValue = Mathf.Clamp(font_normalStyle_prop.floatValue, -3.0f, 3.0f);
if (GUI.changed || evt_cmd == k_UndoRedo)
{
GUI.changed = false;
// Modify the material property on matching material presets.
for (int i = 0; i < m_materialPresets.Length; i++)
m_materialPresets[i].SetFloat("_WeightNormal", font_normalStyle_prop.floatValue);
}
EditorGUILayout.PropertyField(font_boldStyle_prop, new GUIContent("Bold Weight"));
font_boldStyle_prop.floatValue = Mathf.Clamp(font_boldStyle_prop.floatValue, -3.0f, 3.0f);
if (GUI.changed || evt_cmd == k_UndoRedo)
{
GUI.changed = false;
// Modify the material property on matching material presets.
for (int i = 0; i < m_materialPresets.Length; i++)
m_materialPresets[i].SetFloat("_WeightBold", font_boldStyle_prop.floatValue);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(font_normalSpacing_prop, new GUIContent("Regular Spacing"));
font_normalSpacing_prop.floatValue = Mathf.Clamp(font_normalSpacing_prop.floatValue, -100, 100);
if (GUI.changed || evt_cmd == k_UndoRedo)
{
GUI.changed = false;
}
EditorGUILayout.PropertyField(font_boldSpacing_prop, new GUIContent("Bold Spacing"));
font_boldSpacing_prop.floatValue = Mathf.Clamp(font_boldSpacing_prop.floatValue, 0, 100);
if (GUI.changed || evt_cmd == k_UndoRedo)
{
GUI.changed = false;
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(font_italicStyle_prop, new GUIContent("Italic Slant"));
font_italicStyle_prop.intValue = Mathf.Clamp(font_italicStyle_prop.intValue, 15, 60);
if (m_ShowObsoleteProperties_prop.boolValue)
EditorGUILayout.PropertyField(font_tabSize_prop, new GUIContent("Tab Multiple"));
else
EditorGUILayout.LabelField("");
EditorGUILayout.EndHorizontal();
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
}
EditorGUIUtility.labelWidth = 0;
EditorGUIUtility.fieldWidth = 0;
#endregion
// FALLBACK FONT ASSETS
#region Fallback Font Asset
rect = EditorGUILayout.GetControlRect(false, 24);
EditorGUI.indentLevel = 0;
if (GUI.Button(rect, new GUIContent("<b>Fallback Font Assets</b>", "Select the Font Assets that will be searched and used as fallback when characters are missing from this font asset."), TM_EditorStyles.sectionHeader))
UI_PanelState.fallbackFontAssetPanel = !UI_PanelState.fallbackFontAssetPanel;
GUI.Label(rect, (UI_PanelState.fallbackFontAssetPanel ? "" : s_UiStateLabel[1]), TM_EditorStyles.rightLabel);
if (UI_PanelState.fallbackFontAssetPanel)
{
EditorGUIUtility.labelWidth = 120;
EditorGUI.indentLevel = 0;
EditorGUI.BeginChangeCheck();
m_FallbackFontAssetList.DoLayoutList();
if (EditorGUI.EndChangeCheck())
{
m_IsFallbackGlyphCacheDirty = true;
}
EditorGUILayout.Space();
}
#endregion
// CHARACTER TABLE TABLE
if (m_ShowObsoleteProperties_prop.boolValue)
{
#region Character Table
EditorGUIUtility.labelWidth = labelWidth;
EditorGUIUtility.fieldWidth = fieldWidth;
EditorGUI.indentLevel = 0;
rect = EditorGUILayout.GetControlRect(false, 24);
int characterCount = m_fontAsset.characterTable.Count;
if (GUI.Button(rect, new GUIContent("<b>Character Table</b> [" + characterCount + "]" + (rect.width > 320 ? " Characters" : ""), "List of characters contained in this font asset."), TM_EditorStyles.sectionHeader))
UI_PanelState.characterTablePanel = !UI_PanelState.characterTablePanel;
GUI.Label(rect, (UI_PanelState.characterTablePanel ? "" : s_UiStateLabel[1]), TM_EditorStyles.rightLabel);
if (UI_PanelState.characterTablePanel)
{
int arraySize = m_CharacterTable_prop.arraySize;
int itemsPerPage = 15;
// Display Glyph Management Tools
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
{
// Search Bar implementation
#region DISPLAY SEARCH BAR
EditorGUILayout.BeginHorizontal();
{
EditorGUIUtility.labelWidth = 130f;
EditorGUI.BeginChangeCheck();
string searchPattern = EditorGUILayout.TextField("Character Search", m_CharacterSearchPattern, "SearchTextField");
if (EditorGUI.EndChangeCheck() || m_isSearchDirty)
{
if (string.IsNullOrEmpty(searchPattern) == false)
{
m_CharacterSearchPattern = searchPattern;
// Search Character Table for potential matches
SearchCharacterTable(m_CharacterSearchPattern, ref m_CharacterSearchList);
}
else
m_CharacterSearchPattern = null;
m_isSearchDirty = false;
}
string styleName = string.IsNullOrEmpty(m_CharacterSearchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton";
if (GUILayout.Button(GUIContent.none, styleName))
{
GUIUtility.keyboardControl = 0;
m_CharacterSearchPattern = string.Empty;
}
}
EditorGUILayout.EndHorizontal();
#endregion
// Display Page Navigation
if (!string.IsNullOrEmpty(m_CharacterSearchPattern))
arraySize = m_CharacterSearchList.Count;
DisplayPageNavigation(ref m_CurrentCharacterPage, arraySize, itemsPerPage);
}
EditorGUILayout.EndVertical();
// Display Character Table Elements
if (arraySize > 0)
{
// Display each character entry using the CharacterPropertyDrawer.
for (int i = itemsPerPage * m_CurrentCharacterPage; i < arraySize && i < itemsPerPage * (m_CurrentCharacterPage + 1); i++)
{
// Define the start of the selection region of the element.
Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true));
int elementIndex = i;
if (!string.IsNullOrEmpty(m_CharacterSearchPattern))
elementIndex = m_CharacterSearchList[i];
SerializedProperty characterProperty = m_CharacterTable_prop.GetArrayElementAtIndex(elementIndex);
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUI.BeginDisabledGroup(i != m_SelectedCharacterRecord);
{
EditorGUILayout.PropertyField(characterProperty);
}
EditorGUI.EndDisabledGroup();
EditorGUILayout.EndVertical();
// Define the end of the selection region of the element.
Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true));
// Check for Item selection
Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y);
if (DoSelectionCheck(selectionArea))
{
if (m_SelectedCharacterRecord == i)
m_SelectedCharacterRecord = -1;
else
{
m_SelectedCharacterRecord = i;
m_AddCharacterWarning.isEnabled = false;
m_unicodeHexLabel = k_placeholderUnicodeHex;
GUIUtility.keyboardControl = 0;
}
}
// Draw Selection Highlight and Glyph Options
if (m_SelectedCharacterRecord == i)
{
// Reset other selections
ResetSelections(RecordSelectionType.CharacterRecord);
TextCoreEditorUtilities.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255));
// Draw Glyph management options
Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f);
float optionAreaWidth = controlRect.width * 0.6f;
float btnWidth = optionAreaWidth / 3;
Rect position = new Rect(controlRect.x + controlRect.width * .4f, controlRect.y, btnWidth, controlRect.height);
// Copy Selected Glyph to Target Glyph ID
GUI.enabled = !string.IsNullOrEmpty(m_dstUnicode);
if (GUI.Button(position, new GUIContent("Copy to")))
{
GUIUtility.keyboardControl = 0;
// Convert Hex Value to Decimal
int dstGlyphID = (int)TextUtilities.StringHexToInt(m_dstUnicode);
//Add new glyph at target Unicode hex id.
if (!AddNewCharacter(elementIndex, dstGlyphID))
{
m_AddCharacterWarning.isEnabled = true;
m_AddCharacterWarning.expirationTime = EditorApplication.timeSinceStartup + 1;
}
m_dstUnicode = string.Empty;
m_isSearchDirty = true;
TextEventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset);
}
// Target Glyph ID
GUI.enabled = true;
position.x += btnWidth;
GUI.SetNextControlName("CharacterID_Input");
m_dstUnicode = EditorGUI.TextField(position, m_dstUnicode);
// Placeholder text
EditorGUI.LabelField(position, new GUIContent(m_unicodeHexLabel, "The Unicode (Hex) ID of the duplicated Character"), TM_EditorStyles.label);
// Only filter the input when the destination glyph ID text field has focus.
if (GUI.GetNameOfFocusedControl() == "CharacterID_Input")
{
m_unicodeHexLabel = string.Empty;
//Filter out unwanted characters.
char chr = Event.current.character;
if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F'))
{
Event.current.character = '\0';
}
}
else
{
m_unicodeHexLabel = k_placeholderUnicodeHex;
//m_dstUnicode = string.Empty;
}
// Remove Glyph
position.x += btnWidth;
if (GUI.Button(position, "Remove"))
{
GUIUtility.keyboardControl = 0;
RemoveCharacterFromList(elementIndex);
isAssetDirty = true;
m_SelectedCharacterRecord = -1;
m_isSearchDirty = true;
break;
}
if (m_AddCharacterWarning.isEnabled && EditorApplication.timeSinceStartup < m_AddCharacterWarning.expirationTime)
{
EditorGUILayout.HelpBox("The Destination Character ID already exists", MessageType.Warning);
}
}
}
}
DisplayPageNavigation(ref m_CurrentCharacterPage, arraySize, itemsPerPage);
EditorGUILayout.Space();
}
#endregion
}
// GLYPH TABLE
if (m_ShowObsoleteProperties_prop.boolValue)
{
#region Glyph Table
EditorGUIUtility.labelWidth = labelWidth;
EditorGUIUtility.fieldWidth = fieldWidth;
EditorGUI.indentLevel = 0;
rect = EditorGUILayout.GetControlRect(false, 24);
GUIStyle glyphPanelStyle = new GUIStyle(EditorStyles.helpBox);
int glyphCount = m_fontAsset.glyphTable.Count;
if (GUI.Button(rect, new GUIContent("<b>Glyph Table</b> [" + glyphCount + "]" + (rect.width > 275 ? " Glyphs" : ""), "List of glyphs contained in this font asset."), TM_EditorStyles.sectionHeader))
UI_PanelState.glyphTablePanel = !UI_PanelState.glyphTablePanel;
GUI.Label(rect, (UI_PanelState.glyphTablePanel ? "" : s_UiStateLabel[1]), TM_EditorStyles.rightLabel);
if (UI_PanelState.glyphTablePanel)
{
int arraySize = m_GlyphTable_prop.arraySize;
int itemsPerPage = 15;
// Display Glyph Management Tools
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
{
// Search Bar implementation
#region DISPLAY SEARCH BAR
EditorGUILayout.BeginHorizontal();
{
EditorGUIUtility.labelWidth = 130f;
EditorGUI.BeginChangeCheck();
string searchPattern = EditorGUILayout.TextField("Glyph Search", m_GlyphSearchPattern, "SearchTextField");
if (EditorGUI.EndChangeCheck() || m_isSearchDirty)
{
if (string.IsNullOrEmpty(searchPattern) == false)
{
m_GlyphSearchPattern = searchPattern;
// Search Glyph Table for potential matches
SearchGlyphTable(m_GlyphSearchPattern, ref m_GlyphSearchList);
}
else
m_GlyphSearchPattern = null;
m_isSearchDirty = false;
}
string styleName = string.IsNullOrEmpty(m_GlyphSearchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton";
if (GUILayout.Button(GUIContent.none, styleName))
{
GUIUtility.keyboardControl = 0;
m_GlyphSearchPattern = string.Empty;
}
}
EditorGUILayout.EndHorizontal();
#endregion
// Display Page Navigation
if (!string.IsNullOrEmpty(m_GlyphSearchPattern))
arraySize = m_GlyphSearchList.Count;
DisplayPageNavigation(ref m_CurrentGlyphPage, arraySize, itemsPerPage);
}
EditorGUILayout.EndVertical();
// Display Glyph Table Elements
if (arraySize > 0)
{
// Display each GlyphInfo entry using the GlyphInfo property drawer.