TMP_EditorPanel.cs
6.72 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
using UnityEngine;
using UnityEditor;
using UnityEditor.Presets;
namespace TMPro.EditorUtilities
{
[CustomEditor(typeof(TextMeshPro), true), CanEditMultipleObjects]
public class TMP_EditorPanel : TMP_BaseEditorPanel
{
static readonly GUIContent k_SortingLayerLabel = new GUIContent("Sorting Layer", "Name of the Renderer's sorting layer.");
static readonly GUIContent k_OrderInLayerLabel = new GUIContent("Order in Layer", "Renderer's order within a sorting layer.");
static readonly GUIContent k_OrthographicLabel = new GUIContent("Orthographic Mode", "Should be enabled when using an orthographic camera. Instructs the shader to not perform any perspective correction.");
static readonly GUIContent k_VolumetricLabel = new GUIContent("Volumetric Setup", "Use cubes rather than quads to render the text. Allows for volumetric rendering when combined with a compatible shader.");
private static string[] k_SortingLayerNames;
bool IsPreset;
SerializedProperty m_IsVolumetricTextProp;
SerializedProperty m_IsOrthographicProp;
Renderer m_Renderer;
protected override void OnEnable()
{
base.OnEnable();
// Determine if the inspected object is a Preset
IsPreset = (int)(target as Component).gameObject.hideFlags == 93;
m_IsOrthographicProp = serializedObject.FindProperty("m_isOrthographic");
m_IsVolumetricTextProp = serializedObject.FindProperty("m_isVolumetricText");
m_Renderer = m_TextComponent.GetComponent<Renderer>();
// Populate Sorting Layer Names
k_SortingLayerNames = SortingLayerHelper.sortingLayerNames;
}
protected override void DrawExtraSettings()
{
Rect rect = EditorGUILayout.GetControlRect(false, 24);
if (GUI.Button(rect, new GUIContent("<b>Extra Settings</b>"), TMP_UIStyleManager.sectionHeader))
Foldout.extraSettings = !Foldout.extraSettings;
GUI.Label(rect, (Foldout.extraSettings ? "" : k_UiStateLabel[1]), TMP_UIStyleManager.rightLabel);
if (Foldout.extraSettings)
{
//EditorGUI.indentLevel += 1;
DrawMargins();
DrawSortingLayer();
DrawGeometrySorting();
DrawIsTextObjectScaleStatic();
DrawOrthographicMode();
DrawRichText();
DrawParsing();
DrawSpriteAsset();
DrawStyleSheet();
//DrawVolumetricSetup();
DrawKerning();
DrawPadding();
//EditorGUI.indentLevel -= 1;
}
}
protected void DrawSortingLayer()
{
Undo.RecordObject(m_Renderer, "Sorting Layer Change");
EditorGUI.BeginChangeCheck();
TextMeshPro textComponent = (TextMeshPro)m_TextComponent;
// Look up the layer name using the current layer ID
string oldName = IsPreset ? SortingLayer.IDToName(textComponent._SortingLayerID) : SortingLayer.IDToName(textComponent.sortingLayerID);
// Use the name to look up our array index into the names list
int oldLayerIndex = System.Array.IndexOf(k_SortingLayerNames, oldName);
// Show the pop-up for the names
EditorGUIUtility.fieldWidth = 0f;
int newLayerIndex = EditorGUILayout.Popup(k_SortingLayerLabel, oldLayerIndex, k_SortingLayerNames);
// If the index changes, look up the ID for the new index to store as the new ID
if (newLayerIndex != oldLayerIndex)
UpdateTargetsSortingLayerID(SortingLayer.NameToID(k_SortingLayerNames[newLayerIndex]));
// Get value from internal property if target is a Preset otherwise from the public property
int oldSortingOrder = IsPreset ? textComponent._SortingOrder : textComponent.sortingOrder;
int newSortingLayerOrder = EditorGUILayout.IntField(k_OrderInLayerLabel, oldSortingOrder);
if (newSortingLayerOrder != textComponent.sortingOrder)
UpdateTargetsSortingOrder(newSortingLayerOrder);
if (EditorGUI.EndChangeCheck())
m_HavePropertiesChanged = true;
EditorGUILayout.Space();
}
protected void DrawOrthographicMode()
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_IsOrthographicProp, k_OrthographicLabel);
if (EditorGUI.EndChangeCheck())
m_HavePropertiesChanged = true;
}
protected void DrawVolumetricSetup()
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_IsVolumetricTextProp, k_VolumetricLabel);
if (EditorGUI.EndChangeCheck())
{
m_HavePropertiesChanged = true;
m_TextComponent.textInfo.ResetVertexLayout(m_IsVolumetricTextProp.boolValue);
}
EditorGUILayout.Space();
}
// Method to handle multi object selection
protected override bool IsMixSelectionTypes()
{
GameObject[] objects = Selection.gameObjects;
if (objects.Length > 1)
{
for (int i = 0; i < objects.Length; i++)
{
if (objects[i].GetComponent<TextMeshPro>() == null)
return true;
}
}
return false;
}
protected override void OnUndoRedo()
{
int undoEventId = Undo.GetCurrentGroup();
int lastUndoEventId = s_EventId;
if (undoEventId != lastUndoEventId)
{
for (int i = 0; i < targets.Length; i++)
{
//Debug.Log("Undo & Redo Performed detected in Editor Panel. Event ID:" + Undo.GetCurrentGroup());
TMPro_EventManager.ON_TEXTMESHPRO_PROPERTY_CHANGED(true, targets[i] as TextMeshPro);
s_EventId = undoEventId;
}
}
}
void UpdateTargetsSortingLayerID(int sortingLayerID)
{
for (int i = 0; i < targets.Length; i++)
{
var textComponent = (TextMeshPro)targets[i];
if (textComponent != null)
textComponent.sortingLayerID = sortingLayerID;
}
}
void UpdateTargetsSortingOrder(int sortingOrder)
{
for (int i = 0; i < targets.Length; i++)
{
var textComponent = (TextMeshPro)targets[i];
if (textComponent != null)
textComponent.sortingOrder = sortingOrder;
}
}
}
}