Skip to content

Commit 0d96290

Browse files
committed
Fixed errors with version 1.3 of TMP. Added RTLTextMeshPro3D.
1 parent 4a34596 commit 0d96290

File tree

7 files changed

+355
-54
lines changed

7 files changed

+355
-54
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using TMPro.EditorUtilities;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace RTLTMPro
6+
{
7+
[CustomEditor(typeof(RTLTextMeshPro3D)), CanEditMultipleObjects]
8+
public class RTLTextMeshPro3DEditor : TMP_UiEditorPanel
9+
{
10+
private SerializedProperty originalTextProp;
11+
private SerializedProperty havePropertiesChangedProp;
12+
private SerializedProperty inputSourceProp;
13+
private SerializedProperty isInputPasingRequiredProp;
14+
private SerializedProperty preserveNumbersProp;
15+
private SerializedProperty farsiProp;
16+
private SerializedProperty fixTagsProp;
17+
private SerializedProperty forceFixProp;
18+
19+
private bool changed;
20+
private bool foldout;
21+
private RTLTextMeshPro3D tmpro;
22+
23+
private new void OnEnable()
24+
{
25+
base.OnEnable();
26+
foldout = true;
27+
preserveNumbersProp = serializedObject.FindProperty("preserveNumbers");
28+
farsiProp = serializedObject.FindProperty("farsi");
29+
fixTagsProp = serializedObject.FindProperty("fixTags");
30+
forceFixProp = serializedObject.FindProperty("forceFix");
31+
originalTextProp = serializedObject.FindProperty("originalText");
32+
havePropertiesChangedProp = serializedObject.FindProperty("m_havePropertiesChanged");
33+
inputSourceProp = serializedObject.FindProperty("m_inputSource");
34+
isInputPasingRequiredProp = serializedObject.FindProperty("m_isInputParsingRequired");
35+
}
36+
37+
public override void OnInspectorGUI()
38+
{
39+
serializedObject.Update();
40+
tmpro = (RTLTextMeshPro3D) target;
41+
42+
EditorGUILayout.Space();
43+
EditorGUI.BeginChangeCheck();
44+
EditorGUILayout.PropertyField(originalTextProp, new GUIContent("RTL Text Input Box"));
45+
46+
ListenForZeroWidthNoJoiner();
47+
48+
if (EditorGUI.EndChangeCheck())
49+
{
50+
inputSourceProp.enumValueIndex = 0;
51+
isInputPasingRequiredProp.boolValue = true;
52+
changed = true;
53+
}
54+
55+
if (changed)
56+
OnChanged();
57+
58+
serializedObject.ApplyModifiedProperties();
59+
60+
base.OnInspectorGUI();
61+
62+
foldout = EditorGUILayout.Foldout(foldout, "RTL Settings", TMP_UIStyleManager.boldFoldout);
63+
if (foldout)
64+
{
65+
DrawOptions();
66+
67+
if (GUILayout.Button("Re-Fix"))
68+
changed = true;
69+
70+
if (EditorGUI.EndChangeCheck())
71+
{
72+
changed = true;
73+
}
74+
}
75+
76+
if(changed)
77+
OnChanged();
78+
}
79+
80+
protected void OnChanged()
81+
{
82+
tmpro.UpdateText();
83+
havePropertiesChangedProp.boolValue = true;
84+
changed = false;
85+
EditorUtility.SetDirty(target);
86+
}
87+
88+
protected virtual void DrawOptions()
89+
{
90+
EditorGUILayout.BeginHorizontal();
91+
EditorGUI.BeginChangeCheck();
92+
farsiProp.boolValue = GUILayout.Toggle(farsiProp.boolValue, new GUIContent("Farsi"));
93+
forceFixProp.boolValue = GUILayout.Toggle(forceFixProp.boolValue, new GUIContent("Force Fix"));
94+
preserveNumbersProp.boolValue = GUILayout.Toggle(preserveNumbersProp.boolValue, new GUIContent("Preserve Numbers"));
95+
96+
if (tmpro.richText)
97+
fixTagsProp.boolValue = GUILayout.Toggle(fixTagsProp.boolValue, new GUIContent("FixTags"));
98+
99+
EditorGUILayout.EndHorizontal();
100+
}
101+
102+
protected virtual void ListenForZeroWidthNoJoiner()
103+
{
104+
var editor = (TextEditor) GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
105+
106+
bool shortcutPressed = (Event.current.modifiers & EventModifiers.Control) != 0 &&
107+
(Event.current.modifiers & EventModifiers.Shift) != 0 &&
108+
Event.current.type == EventType.KeyUp &&
109+
Event.current.keyCode == KeyCode.Alpha2;
110+
111+
if (!shortcutPressed) return;
112+
113+
originalTextProp.stringValue = originalTextProp.stringValue.Insert(editor.cursorIndex, ((char) GeneralLetters.ZeroWidthNoJoiner).ToString());
114+
editor.selectIndex++;
115+
editor.cursorIndex++;
116+
Event.current.Use();
117+
Repaint();
118+
}
119+
}
120+
}

Assets/RTLTMPro/Editor/RTLTextMeshPro3DEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/RTLTMPro/Editor/RTLTextMeshProEditor.cs

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ namespace RTLTMPro
77
[CustomEditor(typeof(RTLTextMeshPro)), CanEditMultipleObjects]
88
public class RTLTextMeshProEditor : TMP_UiEditorPanel
99
{
10-
private static readonly string[] UIStateLabel = {"\t- <i>Click to expand</i> -", "\t- <i>Click to collapse</i> -"};
1110
private SerializedProperty originalTextProp;
1211
private SerializedProperty havePropertiesChangedProp;
1312
private SerializedProperty inputSourceProp;
@@ -19,7 +18,6 @@ public class RTLTextMeshProEditor : TMP_UiEditorPanel
1918

2019
private bool changed;
2120
private bool foldout;
22-
private GUIStyle fixNumberStyle;
2321
private RTLTextMeshPro tmpro;
2422

2523
private new void OnEnable()
@@ -40,65 +38,51 @@ public override void OnInspectorGUI()
4038
{
4139
serializedObject.Update();
4240
tmpro = (RTLTextMeshPro) target;
41+
42+
EditorGUILayout.Space();
43+
EditorGUI.BeginChangeCheck();
44+
EditorGUILayout.PropertyField(originalTextProp, new GUIContent("RTL Text Input Box"));
4345

44-
// Copy Default GUI Toggle Style
45-
if (fixNumberStyle == null)
46-
{
47-
fixNumberStyle = new GUIStyle(GUI.skin.label)
48-
{
49-
fontSize = 12,
50-
normal = {textColor = TMP_UIStyleManager.Section_Label.normal.textColor},
51-
richText = true
52-
};
53-
}
46+
ListenForZeroWidthNoJoiner();
5447

55-
EditorGUILayout.BeginVertical(GUI.skin.box);
56-
DrawOptions();
57-
if (GUILayout.Button("Re-Fix"))
58-
changed = true;
59-
EditorGUILayout.EndVertical();
60-
6148
if (EditorGUI.EndChangeCheck())
6249
{
50+
inputSourceProp.enumValueIndex = 0;
51+
isInputPasingRequiredProp.boolValue = true;
6352
changed = true;
6453
}
6554

66-
Rect rect = EditorGUILayout.GetControlRect(false, 25);
67-
rect.y += 2;
55+
if (changed)
56+
OnChanged();
57+
58+
serializedObject.ApplyModifiedProperties();
6859

69-
GUI.Label(rect, "<b>RTL TEXT INPUT BOX</b>" + (foldout ? UIStateLabel[1] : UIStateLabel[0]), TMP_UIStyleManager.Section_Label);
70-
if (GUI.Button(new Rect(rect.x, rect.y, rect.width - 150, rect.height), GUIContent.none, GUI.skin.label))
71-
foldout = !foldout;
60+
base.OnInspectorGUI();
7261

62+
foldout = EditorGUILayout.Foldout(foldout, "RTL Settings", TMP_UIStyleManager.boldFoldout);
7363
if (foldout)
7464
{
75-
EditorGUI.BeginChangeCheck();
76-
originalTextProp.stringValue = GUILayout.TextArea(originalTextProp.stringValue, TMP_UIStyleManager.TextAreaBoxEditor, GUILayout.Height(125), GUILayout.ExpandWidth(true));
65+
DrawOptions();
7766

78-
ListenForZeroWidthNoJoiner();
67+
if (GUILayout.Button("Re-Fix"))
68+
changed = true;
7969

8070
if (EditorGUI.EndChangeCheck())
8171
{
82-
inputSourceProp.enumValueIndex = 0;
83-
isInputPasingRequiredProp.boolValue = true;
8472
changed = true;
8573
}
8674
}
8775

88-
serializedObject.ApplyModifiedProperties();
89-
90-
if (changed)
91-
{
92-
tmpro.UpdateText();
93-
94-
havePropertiesChangedProp.boolValue = true;
95-
changed = false;
96-
EditorUtility.SetDirty(target);
97-
}
98-
99-
serializedObject.ApplyModifiedProperties();
76+
if(changed)
77+
OnChanged();
78+
}
10079

101-
base.OnInspectorGUI();
80+
protected void OnChanged()
81+
{
82+
tmpro.UpdateText();
83+
havePropertiesChangedProp.boolValue = true;
84+
changed = false;
85+
EditorUtility.SetDirty(target);
10286
}
10387

10488
protected virtual void DrawOptions()
@@ -118,12 +102,12 @@ protected virtual void DrawOptions()
118102
protected virtual void ListenForZeroWidthNoJoiner()
119103
{
120104
var editor = (TextEditor) GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
121-
105+
122106
bool shortcutPressed = (Event.current.modifiers & EventModifiers.Control) != 0 &&
123-
(Event.current.modifiers & EventModifiers.Shift) != 0 &&
124-
Event.current.type == EventType.KeyUp &&
125-
Event.current.keyCode == KeyCode.Alpha2;
126-
107+
(Event.current.modifiers & EventModifiers.Shift) != 0 &&
108+
Event.current.type == EventType.KeyUp &&
109+
Event.current.keyCode == KeyCode.Alpha2;
110+
127111
if (!shortcutPressed) return;
128112

129113
originalTextProp.stringValue = originalTextProp.stringValue.Insert(editor.cursorIndex, ((char) GeneralLetters.ZeroWidthNoJoiner).ToString());

Assets/RTLTMPro/RTLTextMeshPro.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,21 @@ protected bool ForceFix
8080
}
8181
}
8282

83-
[SerializeField] protected bool preserveNumbers;
84-
[SerializeField] protected bool farsi = true;
85-
[SerializeField] protected string originalText;
86-
[SerializeField] protected bool fixTags = true;
87-
[SerializeField] protected bool forceFix;
83+
[SerializeField]
84+
protected bool preserveNumbers;
85+
86+
[SerializeField]
87+
protected bool farsi = true;
88+
89+
[SerializeField]
90+
[TextArea(3, 10)]
91+
protected string originalText;
92+
93+
[SerializeField]
94+
protected bool fixTags = true;
95+
96+
[SerializeField]
97+
protected bool forceFix;
8898

8999
protected RTLSupport support;
90100

@@ -109,7 +119,7 @@ protected virtual void Update()
109119

110120
public virtual void UpdateText()
111121
{
112-
if(support == null)
122+
if (support == null)
113123
support = new RTLSupport();
114124

115125
if (originalText == null)
@@ -152,6 +162,5 @@ public virtual string GetFixedText(string input)
152162

153163
return input;
154164
}
155-
156165
}
157166
}

0 commit comments

Comments
 (0)