Skip to content

Commit 5799f90

Browse files
committed
- Added more tests
- Renamed TagEffect to TagComponent - Renamedd TransitionEffect to TransitionComponent - Added isActive boolean to MotionComponent - Improved MotionComponentRegistry - Cleaned up comments - Simplified syntax - Improved TextMotionProPlugin - Refactored some names to improve readability - Added helper method to prevent direct access to component registry - Added helper method to find ComponentDescriptor based on type - Mergerd transition and tag contexts together - Moved Standard components to /Runtime/Components/Standard - Removed redundant folders
1 parent fa4c61d commit 5799f90

File tree

75 files changed

+711
-552
lines changed

Some content is hidden

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

75 files changed

+711
-552
lines changed

.github/workflows/test.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ jobs:
1414
with:
1515
lfs: true
1616

17-
#Cache
18-
- uses: actions/cache@v4
19-
with:
20-
path: Library
21-
key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
22-
restore-keys: |
23-
Library-
24-
2517
# Move the package to a subdirectory
2618
- name: Move package to subdirectory
2719
run: |

Editor/MotionCollection/ElementContainer.uxml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<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">
22
<engine:VisualElement name="element" style="margin-bottom: 0;">
3-
<editor:Toolbar name="header" style="border-top-width: 1px; border-bottom-width: 0; background-color: rgba(255, 255, 255, 0.05); align-items: center; justify-content: space-between; margin-top: 0; -unity-font-style: bold;">
4-
<engine:Label text="Wave Effect" name="label" style="justify-content: flex-start; align-self: auto; -unity-text-align: middle-left;" />
5-
<editor:ToolbarButton text="⋮" name="options-button" style="font-size: 23px; border-right-width: 0; border-left-width: 0; background-color: rgba(60, 60, 60, 0);" />
3+
<editor:Toolbar name="header" style="border-top-width: 1px; border-bottom-width: 0; background-color: rgba(255, 255, 255, 0.05); align-items: center; justify-content: flex-start; margin-top: 0; -unity-font-style: bold;">
4+
<engine:Toggle name="active-toggle" binding-path="isActive" value="false" style="margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-right: 4px; padding-left: 4px;" />
5+
<engine:VisualElement name="foldout-box" style="flex-grow: 1; flex-direction: row;">
6+
<engine:Label text="Wave Effect" name="label" style="justify-content: flex-start; align-self: auto; -unity-text-align: middle-left;" />
7+
<editor:ToolbarButton text="⋮" name="options-button" style="font-size: 23px; border-right-width: 0; border-left-width: 0; background-color: rgba(60, 60, 60, 0); margin-left: auto;" />
8+
</engine:VisualElement>
69
</editor:Toolbar>
710
<engine:GroupBox name="body" style="margin-top: 0; display: none;" />
811
</engine:VisualElement>

Editor/MotionCollection/MotionCollectionEditor.cs

Lines changed: 0 additions & 109 deletions
This file was deleted.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
using BP.TextMotion;
2+
using System.Reflection;
3+
using UnityEditor;
4+
using UnityEditor.UIElements;
5+
using UnityEngine;
6+
using UnityEngine.UIElements;
7+
8+
namespace BP.TextMotionEditor
9+
{
10+
[CustomPropertyDrawer(typeof(MotionComponentRegistry<>), true)]
11+
public class MotionComponentRegistryEditor : PropertyDrawer
12+
{
13+
[SerializeField] private VisualTreeAsset listContainerAsset;
14+
[SerializeField] private VisualTreeAsset elementContainerAsset;
15+
16+
private VisualElement listRoot;
17+
private SerializedProperty listProperty;
18+
19+
public override VisualElement CreatePropertyGUI(SerializedProperty property)
20+
{
21+
var root = listContainerAsset.CloneTree();
22+
listRoot = root.Q<VisualElement>("elements-list");
23+
listProperty = property.FindPropertyRelative("components");
24+
25+
RefreshList();
26+
return root;
27+
}
28+
29+
private void RefreshList()
30+
{
31+
listRoot.Clear();
32+
for (int i = 0; i < listProperty.arraySize; i++)
33+
{
34+
listRoot.Add(CreateComponentElement(i));
35+
}
36+
}
37+
38+
private VisualElement CreateComponentElement(int index)
39+
{
40+
var elementProp = listProperty.GetArrayElementAtIndex(index);
41+
var motionComponent = elementProp.objectReferenceValue as MotionComponent;
42+
if (motionComponent == null) return new Label("Missing component");
43+
44+
var container = elementContainerAsset.CloneTree();
45+
var header = container.Q<VisualElement>("header");
46+
var body = container.Q<VisualElement>("body");
47+
var optionsButton = container.Q<ToolbarButton>("options-button");
48+
49+
SetupHeader(header, motionComponent, body);
50+
SetupOptionsMenu(optionsButton, index);
51+
52+
return container;
53+
}
54+
55+
private void SetupHeader(VisualElement header, MotionComponent component, VisualElement body)
56+
{
57+
var type = component.GetType();
58+
var attr = type.GetCustomAttribute<TextMotionAttribute>();
59+
header.Q<Label>("label").text = attr?.DisplayName ?? type.Name;
60+
61+
var foldoutClickable = header.Q("foldout-box");
62+
var activeToggle = header.Q<Toggle>("active-toggle");
63+
64+
var so = new SerializedObject(component);
65+
var isFoldedProp = so.FindProperty("isFolded");
66+
var isActiveProp = so.FindProperty("isActive");
67+
68+
activeToggle.BindProperty(isActiveProp);
69+
70+
body.Add(CreateEditorElement(so));
71+
UpdateBodyVisibility(body, isFoldedProp.boolValue);
72+
73+
foldoutClickable.RegisterCallback<ClickEvent>(_ =>
74+
{
75+
isFoldedProp.boolValue = !isFoldedProp.boolValue;
76+
so.ApplyModifiedProperties();
77+
UpdateBodyVisibility(body, isFoldedProp.boolValue);
78+
});
79+
80+
foldoutClickable.TrackPropertyValue(isFoldedProp, prop =>
81+
{
82+
UpdateBodyVisibility(body, prop.boolValue);
83+
});
84+
}
85+
86+
private void UpdateBodyVisibility(VisualElement body, bool isFolded)
87+
{
88+
body.style.display = isFolded ? DisplayStyle.Flex : DisplayStyle.None;
89+
}
90+
91+
private void SetupOptionsMenu(ToolbarButton button, int index)
92+
{
93+
button.clicked += () =>
94+
{
95+
var menu = new GenericMenu();
96+
97+
// Remove option
98+
menu.AddItem(new GUIContent("Remove"), false, () =>
99+
{
100+
RemoveComponentAt(index);
101+
});
102+
menu.DropDown(button.worldBound);
103+
};
104+
}
105+
106+
private void RemoveComponentAt(int index)
107+
{
108+
var targetObj = listProperty.serializedObject.targetObject;
109+
Undo.RecordObject(targetObj, "Remove Motion Component");
110+
111+
listProperty.DeleteArrayElementAtIndex(index);
112+
listProperty.serializedObject.ApplyModifiedProperties();
113+
114+
RefreshList();
115+
}
116+
117+
private VisualElement CreateEditorElement(SerializedObject serializedObject)
118+
{
119+
var editor = Editor.CreateEditor(serializedObject.targetObject);
120+
if (editor == null)
121+
return new Label("No custom editor available");
122+
123+
var inspectorGUI = editor.CreateInspectorGUI();
124+
if (inspectorGUI != null)
125+
return inspectorGUI;
126+
127+
return new IMGUIContainer(() =>
128+
{
129+
serializedObject.Update();
130+
editor.OnInspectorGUI();
131+
serializedObject.ApplyModifiedProperties();
132+
});
133+
}
134+
}
135+
}

Editor/MotionComponentRegistry.cs renamed to Editor/TextMotionProPlugin.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
namespace BP.TextMotionEditor
99
{
10-
public readonly struct MotionComponentDescriptor
10+
public readonly struct ComponentDescriptor
1111
{
1212
public readonly Type Type;
1313
public readonly string DisplayName;
1414
public readonly string Description;
1515
public readonly string Category;
1616
public readonly TextMotionRole Role;
1717

18-
public MotionComponentDescriptor(Type type, string displayName, TextMotionRole role, string description, string category = null)
18+
public ComponentDescriptor(Type type, string displayName, TextMotionRole role, string description, string category = null)
1919
{
2020
Type = type;
2121
DisplayName = displayName;
@@ -26,17 +26,18 @@ public MotionComponentDescriptor(Type type, string displayName, TextMotionRole r
2626
}
2727

2828
[InitializeOnLoad]
29-
internal static class MotionComponentRegistry
29+
internal static class TextMotionProPlugin
3030
{
31-
public static readonly List<MotionComponentDescriptor> Components = new();
32-
static MotionComponentRegistry() => Init();
31+
private static readonly List<ComponentDescriptor> Components = new();
32+
static TextMotionProPlugin() => Init();
3333

3434
public static void Init()
3535
{
3636
Components.Clear();
37-
DiscoverComponents<TagEffect, TextMotionAttribute>();
37+
DiscoverComponents<TagComponent, TextMotionAttribute>();
3838
}
3939

40+
// Discovery process
4041
private static void DiscoverComponents<TBase, TAttr>() where TBase : MotionComponent where TAttr : Attribute
4142
{
4243
foreach (var type in GetTypesWithAttribute<TAttr>())
@@ -47,12 +48,11 @@ private static void DiscoverComponents<TBase, TAttr>() where TBase : MotionCompo
4748

4849
string name = (string)typeof(TAttr).GetProperty("DisplayName")?.GetValue(attr) ?? type.Name;
4950
string desc = (string)typeof(TAttr).GetProperty("Description")?.GetValue(attr);
50-
string category = (string)typeof(TAttr).GetProperty("Category").GetValue(attr);
51+
string category = (string)typeof(TAttr).GetProperty("Category")?.GetValue(attr);
5152
TextMotionRole role = (TextMotionRole)typeof(TAttr).GetProperty("Role").GetValue(attr);
52-
Components.Add(new MotionComponentDescriptor(type, name, role, desc, category));
53+
Components.Add(new ComponentDescriptor(type, name, role, desc, category));
5354
}
5455
}
55-
5656
private static IEnumerable<Type> GetTypesWithAttribute<T>() where T : Attribute
5757
{
5858
return AppDomain.CurrentDomain.GetAssemblies()
@@ -64,5 +64,22 @@ private static IEnumerable<Type> GetTypesWithAttribute<T>() where T : Attribute
6464
})
6565
.Where(t => t.GetCustomAttribute<T>() != null);
6666
}
67+
68+
// Utilities
69+
public static bool TryGetComponentOfType(Type type, out ComponentDescriptor result)
70+
{
71+
foreach (var desc in Components)
72+
{
73+
if (desc.Type == type)
74+
{
75+
result = desc;
76+
return true;
77+
}
78+
}
79+
80+
result = default;
81+
return false;
82+
}
83+
public static ComponentDescriptor[] GetComponents() => Components.ToArray();
6784
}
6885
}
File renamed without changes.
File renamed without changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using UnityEngine;
2+
3+
namespace BP.TextMotion
4+
{
5+
public abstract class MotionComponent : ScriptableObject
6+
{
7+
[SerializeField, HideInInspector] private bool isFolded = false;
8+
[SerializeField, HideInInspector] protected bool isActive = false;
9+
10+
public abstract string Key { get; }
11+
public virtual bool IsActive() => isActive;
12+
public virtual void ResetContext(TextMotionPro renderer) { }
13+
public virtual void Release() { }
14+
}
15+
}

0 commit comments

Comments
 (0)