Skip to content

Commit d6f4249

Browse files
committed
- Renamed **MotionComponentRegistry** to **MotionComponentCollection** to more align with it's purpose
- Renamed **TextMotionProPlugin** to **MotionComponentCatalog** to more align with it's purpose - Renamed **TextMotionAttribute** to **ComponentDescriptorAttribute** as the previous name was misleading. - Removed Role from **ComponentDescriptorAttribute** because component role is determined from parent during discovery. - Renamed assemblies to follow package standards set by Unity. Subsequently also updated - Changed namespaces to reflect assembly changes - Added Editor tests for MotionComponentCatalog --- Planning to extend tests and work on transitions
1 parent 5799f90 commit d6f4249

File tree

75 files changed

+396
-212
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

+396
-212
lines changed

Editor/BP.TextMotionEditor.asmdef renamed to Editor/BP.TextMotionPro.Editor.asmdef

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

Editor/MotionCollection/MotionComponentRegistryEditor.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
using BP.TextMotion;
2-
using System.Reflection;
1+
using System.Reflection;
32
using UnityEditor;
43
using UnityEditor.UIElements;
54
using UnityEngine;
65
using UnityEngine.UIElements;
76

8-
namespace BP.TextMotionEditor
7+
namespace BP.TextMotionPro.Editor
98
{
10-
[CustomPropertyDrawer(typeof(MotionComponentRegistry<>), true)]
9+
[CustomPropertyDrawer(typeof(MotionComponentCollection<>), true)]
1110
public class MotionComponentRegistryEditor : PropertyDrawer
1211
{
1312
[SerializeField] private VisualTreeAsset listContainerAsset;
@@ -55,7 +54,7 @@ private VisualElement CreateComponentElement(int index)
5554
private void SetupHeader(VisualElement header, MotionComponent component, VisualElement body)
5655
{
5756
var type = component.GetType();
58-
var attr = type.GetCustomAttribute<TextMotionAttribute>();
57+
var attr = type.GetCustomAttribute<ComponentDescriptorAttribute>();
5958
header.Q<Label>("label").text = attr?.DisplayName ?? type.Name;
6059

6160
var foldoutClickable = header.Q("foldout-box");
@@ -116,7 +115,7 @@ private void RemoveComponentAt(int index)
116115

117116
private VisualElement CreateEditorElement(SerializedObject serializedObject)
118117
{
119-
var editor = Editor.CreateEditor(serializedObject.targetObject);
118+
var editor = UnityEditor.Editor.CreateEditor(serializedObject.targetObject);
120119
if (editor == null)
121120
return new Label("No custom editor available");
122121

Editor/MotionComponentCatalog.cs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Runtime.CompilerServices;
6+
using UnityEditor;
7+
8+
[assembly: InternalsVisibleTo("BP.TextMotionPro.Editor.Tests")]
9+
10+
namespace BP.TextMotionPro.Editor
11+
{
12+
public enum ComponentRole
13+
{
14+
Tag = 0,
15+
Transition = 1,
16+
}
17+
public readonly struct ComponentDescriptor
18+
{
19+
public readonly Type Type;
20+
public readonly string DisplayName;
21+
public readonly string Description;
22+
public readonly string Category;
23+
public readonly ComponentRole Role;
24+
25+
public ComponentDescriptor(Type type, string displayName, ComponentRole role, string description, string category = null)
26+
{
27+
Type = type;
28+
DisplayName = displayName;
29+
Description = description;
30+
Role = role;
31+
Category = category;
32+
}
33+
34+
public override string ToString()
35+
{
36+
return
37+
$"Type {Type}" +
38+
$"Display Name {DisplayName}" +
39+
$"Description {Description}" +
40+
$"Category {Category}" +
41+
$"Role {Role}";
42+
}
43+
}
44+
45+
[InitializeOnLoad]
46+
internal static class MotionComponentCatalog
47+
{
48+
private static readonly List<ComponentDescriptor> Components = new();
49+
static MotionComponentCatalog() => Init();
50+
51+
public static void Init()
52+
{
53+
Components.Clear();
54+
CollectComponents();
55+
}
56+
57+
private static void CollectComponents()
58+
{
59+
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
60+
foreach (var assembly in assemblies)
61+
{
62+
// Skip dynamic assemblies and optionally Unity editor-only assemblies
63+
if (assembly.IsDynamic || string.IsNullOrEmpty(assembly.FullName) || assembly.FullName.StartsWith("Unity"))
64+
continue;
65+
66+
Type[] types;
67+
try
68+
{
69+
types = assembly.GetTypes();
70+
}
71+
catch (ReflectionTypeLoadException e)
72+
{
73+
types = e.Types.Where(t => t != null).ToArray();
74+
}
75+
76+
foreach (var type in types)
77+
{
78+
if (!type.IsSubclassOf(typeof(MotionComponent)))
79+
continue;
80+
81+
var attr = type.GetCustomAttribute<ComponentDescriptorAttribute>();
82+
if (attr == null)
83+
continue;
84+
85+
var isTagComponent = type.IsSubclassOf(typeof(TagComponent));
86+
var isTransitionComponent = type.IsSubclassOf(typeof(TransitionComponent));
87+
88+
if (!isTagComponent && !isTransitionComponent)
89+
continue;
90+
91+
var role = isTagComponent ? ComponentRole.Tag : ComponentRole.Transition;
92+
var desc = new ComponentDescriptor(
93+
type,
94+
attr.DisplayName,
95+
role,
96+
attr.Description,
97+
attr.Category
98+
);
99+
100+
Components.Add(desc);
101+
}
102+
}
103+
}
104+
105+
// Utilities
106+
public static bool TryGetComponentOfType<T>(out ComponentDescriptor result) where T : MotionComponent => TryGetComponentOfType(typeof(T), out result);
107+
public static bool TryGetComponentOfType(Type type, out ComponentDescriptor result)
108+
{
109+
foreach (var desc in Components)
110+
{
111+
if (desc.Type == type)
112+
{
113+
result = desc;
114+
return true;
115+
}
116+
}
117+
118+
result = default;
119+
return false;
120+
}
121+
public static ComponentDescriptor[] GetComponents() => Components.ToArray();
122+
}
123+
}

Editor/MotionComponentCatalog.cs.meta

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

Editor/MotionComponentEditor.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using BP.TextMotion;
21
using UnityEditor;
32

4-
namespace BP.TextMotionProEditor
3+
namespace BP.TextMotionPro.Editor
54
{
65
[CustomEditor(typeof(MotionComponent), editorForChildClasses: true, isFallback = true)]
7-
internal class MotionComponentEditor : Editor
6+
internal class MotionComponentEditor : UnityEditor.Editor
87
{
98
public override void OnInspectorGUI()
109
{

Editor/MotionProfile/MotionProfileEditor.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
using BP.TextMotion;
21
using System.Collections.Generic;
32
using UnityEditor;
43
using UnityEngine;
54
using UnityEngine.UIElements;
65

7-
namespace BP.TextMotionProEditor
6+
namespace BP.TextMotionPro.Editor
87
{
98
[CustomEditor(typeof(MotionProfile))]
10-
public class MotionProfileEditor : Editor
9+
public class MotionProfileEditor : UnityEditor.Editor
1110
{
1211
[SerializeField] private VisualTreeAsset mainTreeAsset;
1312
private MotionProfile profile;

Editor/MotionProfile/UXML_MotionProfile.uxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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">
2-
<Style src="project://database/Assets/TextMotion%20Pro/Editor/MotionProfile/USS_MotionProfile.uss?fileID=7433441132597879392&amp;guid=78f264ab9f905c54baea00c777d4582a&amp;type=3#USS_MotionProfile" />
2+
<Style src="project://database/Assets/TextMotionPro%20Pro/Editor/MotionProfile/USS_MotionProfile.uss?fileID=7433441132597879392&amp;guid=78f264ab9f905c54baea00c777d4582a&amp;type=3#USS_MotionProfile" />
33
<engine:VisualElement name="Settings" style="flex-grow: 0; flex-shrink: 0; flex-basis: auto; margin-bottom: 10px;">
44
<engine:Label text="Transition Fallback" name="Label" style="-unity-font-style: bold;" />
55
<engine:DropdownField label="In" />

Editor/TextMotionPro/TextMotionProEditor.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
using BP.TextMotion;
21
using UnityEditor;
32
using UnityEngine;
43
using UnityEngine.UIElements;
54

6-
namespace BP.TextMotionEditor
5+
namespace BP.TextMotionPro.Editor
76
{
87
[CustomEditor(typeof(TextMotionPro)), CanEditMultipleObjects]
9-
public class TextMotionProEditor : Editor
8+
public class TextMotionProEditor : UnityEditor.Editor
109
{
1110
[SerializeField] private VisualTreeAsset treeAsset;
1211
public override VisualElement CreateInspectorGUI()

Editor/TextMotionPro/UXML_TextMotion Pro.uxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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">
2-
<editor:ObjectField label="Profile" binding-path="profile" type="BP.TextMotion.MotionProfile, BP.TextMotion" />
3-
<engine:EnumField label="Update Mode" value="Always" type="BP.TextMotion.MotionUpdateMode, BP.TextMotion" binding-path="updateMode" />
2+
<editor:ObjectField label="Profile" binding-path="profile" type="BP.TextMotionPro.MotionProfile, BP.TextMotionPro" />
3+
<engine:EnumField label="Update Mode" value="Always" type="BP.TextMotionPro.MotionUpdateMode, BP.TextMotionPro" binding-path="updateMode" />
44
<engine:FloatField label="Time Scale" value="1" binding-path="timeScale" />
55
<engine:Slider label="Frame Rate" value="42" high-value="100" show-input-field="true" binding-path="frameRate" />
66
<engine:Vector2IntField label="Visibility" binding-path="visibilityRange" />

0 commit comments

Comments
 (0)