Skip to content

Commit 23ab8c6

Browse files
committed
Refactored most of the systems, renamed the project to TextMotion Pro and also improved README
1 parent c71e0c7 commit 23ab8c6

File tree

99 files changed

+2589
-878
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2589
-878
lines changed

Editor/TMPA.Internal.asmdef renamed to Editor/BP.TextMotionEditor.asmdef

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "TMPA.Internal",
3-
"rootNamespace": "TMPA.Internal",
2+
"name": "BP.TextMotionEditor",
3+
"rootNamespace": "BP.TextMotionEditor",
44
"references": [
55
"GUID:a87b08c5284c4f8448de7afcf0272260"
66
],
File renamed without changes.

Editor/TextEffectEditor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
using BP.TextMotionPro;
12
using UnityEditor;
23

3-
namespace BP.TMPA.Internal
4+
namespace BP.TextMotionProEditor
45
{
5-
[CustomEditor(typeof(TextEffectBase), true)]
6+
[CustomEditor(typeof(TextEffect), true)]
67
internal class TextEffectEditor : Editor
78
{
89
public override void OnInspectorGUI()

Editor/TextEffectsProfileEditor.cs

Lines changed: 101 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,132 @@
1+
using BP.TextMotionPro;
12
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using UnityEditor;
6+
using UnityEditor.UIElements;
57
using UnityEngine;
8+
using UnityEngine.UIElements;
69

7-
namespace BP.TMPA.Internal
10+
namespace BP.TextMotionProEditor
811
{
9-
[CustomEditor(typeof(TextEffectsProfile))]
12+
[CustomEditor(typeof(MotionProfile))]
1013
public class TextEffectsProfileEditor : Editor
1114
{
12-
private TextEffectsProfile profile;
15+
[SerializeField] private VisualTreeAsset mainTreeAsset;
16+
[SerializeField] private VisualTreeAsset effectTreeAsset;
17+
18+
private MotionProfile profile;
1319

1420
private void OnEnable()
1521
{
16-
profile = (TextEffectsProfile)target;
22+
profile = (MotionProfile)target;
1723
}
1824

19-
public override void OnInspectorGUI()
25+
public override VisualElement CreateInspectorGUI()
2026
{
21-
base.OnInspectorGUI();
22-
EditorGUI.BeginChangeCheck();
27+
var root = new VisualElement();
28+
mainTreeAsset.CloneTree(root);
29+
30+
var effectsList = root.Q("effects-list");
31+
UpdateEffectsList(effectsList);
2332

24-
var effects = profile.textEffects;
25-
for (int i = 0; i < effects.Count; i++)
33+
// Setup the add button functionality.
34+
var addButton = root.Q<Button>("add-button");
35+
addButton.clicked += () =>
36+
{
37+
var menu = new GenericMenu();
38+
var availableTypes = GetAvailableEffectTypes();
39+
foreach (var effectTypeName in availableTypes)
40+
{
41+
string menuLabel = Type.GetType(effectTypeName).Name;
42+
menu.AddItem(new GUIContent(menuLabel), false, () =>
43+
{
44+
AddEffect(effectTypeName);
45+
UpdateEffectsList(effectsList);
46+
});
47+
}
48+
menu.ShowAsContext();
49+
};
50+
51+
return root;
52+
}
53+
54+
private void UpdateEffectsList(VisualElement parent)
55+
{
56+
parent.Clear();
57+
foreach (var effect in profile.textEffects)
2658
{
27-
var effect = effects[i];
2859
if (effect == null) continue;
2960

30-
EditorGUI.indentLevel++;
61+
var serObject = new SerializedObject(effect);
62+
var foldedProp = serObject.FindProperty("isFolded");
3163

32-
// Create a custom editor for each component type
33-
var effectEditor = CreateEditor(effect);
34-
if (effectEditor != null)
64+
var entry = effectTreeAsset.CloneTree();
65+
var effectLabel = entry.Q<Label>("label");
66+
effectLabel.text = effect.GetType().Name;
67+
68+
var content = entry.Q("content");
69+
content.style.display = foldedProp.boolValue ? DisplayStyle.None : DisplayStyle.Flex;
70+
content.TrackPropertyValue(foldedProp, (prop) =>
3571
{
36-
effectEditor.OnInspectorGUI();
37-
DestroyImmediate(effectEditor);
38-
}
72+
content.style.display = prop.boolValue ? DisplayStyle.None : DisplayStyle.Flex;
73+
});
3974

40-
// Add remove button for the component
41-
if (GUILayout.Button("Remove Component"))
75+
DrawEditor(content, effect);
76+
77+
// Clicking the label toggles folding.
78+
effectLabel.RegisterCallback<ClickEvent>(evt =>
79+
{
80+
foldedProp.boolValue = !foldedProp.boolValue;
81+
serObject.ApplyModifiedProperties();
82+
});
83+
84+
// Setup the options button to open a context menu with removal.
85+
var optionsButton = entry.Q<ToolbarButton>("options-button");
86+
if (optionsButton != null)
4287
{
43-
RemoveEffect(effect.GetType());
44-
break;
88+
optionsButton.clicked += () =>
89+
{
90+
var menu = new GenericMenu();
91+
menu.AddItem(new GUIContent("Remove"), false, () =>
92+
{
93+
RemoveEffect(effect.GetType());
94+
UpdateEffectsList(parent);
95+
});
96+
menu.ShowAsContext();
97+
};
4598
}
4699

47-
EditorGUI.indentLevel--;
100+
parent.Add(entry);
48101
}
102+
}
49103

50-
EditorGUILayout.Space();
104+
private void DrawEditor(VisualElement root, UnityEngine.Object target)
105+
{
106+
var editor = CreateEditor(target);
107+
if (editor == null) return;
51108

52-
var effectTypes = GetAvailableEffectTypes();
53-
int selectedEffectIndex = EditorGUILayout.Popup("Add Effect", -1, effectTypes);
109+
var editorContentElement = editor.CreateInspectorGUI();
54110

55-
if (selectedEffectIndex >= 0)
111+
if (editorContentElement != null)
56112
{
57-
Type selectedEffectType = Type.GetType(effectTypes[selectedEffectIndex]);
58-
if (selectedEffectType != null)
113+
root.Add(editorContentElement);
114+
}
115+
else
116+
{
117+
var imgui = new IMGUIContainer(() =>
59118
{
60-
AddEffect(selectedEffectType);
61-
}
119+
editor.OnInspectorGUI();
120+
});
121+
root.Add(imgui);
62122
}
123+
DestroyImmediate(editor);
63124
}
64125

65-
private string[] GetAvailableEffectTypes() => TextEffectRegistry.TextEffects.Where(x => !profile.HasTextEffect(x.Type)).Select(x => x.Type.FullName).ToArray();
66-
126+
private string[] GetAvailableEffectTypes() => TextEffectRegistry.TextEffects
127+
.Where(x => !profile.HasTextEffect(x.Type))
128+
.Select(x => x.Type.AssemblyQualifiedName)
129+
.ToArray();
67130

68131
private void RemoveEffect(Type type)
69132
{
@@ -73,8 +136,11 @@ private void RemoveEffect(Type type)
73136
UpdateAssets();
74137
}
75138

76-
private void AddEffect(Type effectType)
139+
private void AddEffect(string effectTypeName)
77140
{
141+
Type effectType = Type.GetType(effectTypeName);
142+
if (effectType == null) return;
143+
78144
Undo.RecordObject(profile, "Added Effect");
79145
profile.AddTextEffect(effectType);
80146
EditorUtility.SetDirty(profile);
@@ -83,10 +149,10 @@ private void AddEffect(Type effectType)
83149

84150
public void UpdateAssets()
85151
{
86-
//Path of the main file
152+
// Path of the main file.
87153
string path = AssetDatabase.GetAssetPath(profile);
88154

89-
//Gets all components
155+
// Gets all components.
90156
var effects = profile.GetAllTextEffects();
91157
var currentSubAssets = AssetDatabase.LoadAllAssetRepresentationsAtPath(path);
92158
var componentsToRemove = new List<UnityEngine.Object>(currentSubAssets);

Editor/TextEffectsProfileEditor.cs.meta

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/TextMotionRendererEditor.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using BP.TextMotionPro;
2+
using UnityEditor;
3+
using UnityEngine;
4+
using UnityEngine.UIElements;
5+
6+
namespace BP.TextMotionEditor
7+
{
8+
[CustomEditor(typeof(TextMotionRenderer)), CanEditMultipleObjects]
9+
public class TextMotionRendererEditor : Editor
10+
{
11+
[SerializeField] private VisualTreeAsset treeAsset;
12+
public override VisualElement CreateInspectorGUI()
13+
{
14+
var root = new VisualElement();
15+
treeAsset.CloneTree(root);
16+
return root;
17+
}
18+
}
19+
}

Editor/TextMotionRendererEditor.cs.meta

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

Editor/USS_MotionAsset.uss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#Span {
2+
background-color: rgba(255, 255, 255, 0.2);
3+
max-width: 4px;
4+
max-height: 4px;
5+
width: 100%;
6+
height: 100%;
7+
margin-top: 1px;
8+
margin-right: 1px;
9+
margin-bottom: 1px;
10+
margin-left: 1px;
11+
}

Editor/USS_MotionAsset.uss.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.

Editor/UXML_EffectEntry.uxml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<engine:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:engine="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
2+
<engine:VisualElement name="effect-element" style="flex-grow: 1; margin-bottom: 5px;">
3+
<editor:Toolbar style="border-top-width: 1px;">
4+
<engine:Label text="Wave Effect" name="label" style="justify-content: flex-start; align-self: auto; -unity-text-align: middle-left;" />
5+
<editor:ToolbarSpacer style="flex-grow: 1;" />
6+
<editor:ToolbarButton text="⋮" name="options-button" style="font-size: 23px; border-right-width: 0; border-left-width: 0;" />
7+
</editor:Toolbar>
8+
<engine:GroupBox name="content" style="margin-top: 0;" />
9+
</engine:VisualElement>
10+
</engine:UXML>

0 commit comments

Comments
 (0)