Skip to content

Commit 7856c13

Browse files
committed
Added MotionProfile changed event and ensured that TextMotionPro listens to it and reparses.
Renamed TmpTagFilter to TagFilter and added IsBuiltIn() method to automatically validate all built in tags, such as transition. Started laying the ground work for transition system. Extended Motion profile by streamlining caching and adding GetActionAt() method. Began implementing Samples.
1 parent 3deef4c commit 7856c13

26 files changed

+236
-218
lines changed

Editor/TextEffectsProfileEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public override VisualElement CreateInspectorGUI()
5454
private void UpdateEffectsList(VisualElement parent)
5555
{
5656
parent.Clear();
57-
foreach (var effect in profile.textEffects)
57+
foreach (var effect in profile.GetAllTextEffects())
5858
{
5959
if (effect == null) continue;
6060

Editor/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="effectsProfile" type="BP.TextMotion.MotionProfile, BP.TextMotion" />
3-
<engine:Toggle label="Run in Editor" binding-path="runInEditor" />
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" />
44
<engine:Slider label="Frame Rate" value="42" high-value="100" show-input-field="true" binding-path="frameRate" />
55
<engine:Vector2IntField label="Visibility" binding-path="visibilityRange" />
66
</engine:UXML>

LICENSE.meta

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

Runtime/Effects/Built-in/AnimatorTextEffect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public enum AnimatorFlow
2424
[SerializeField] private float angle;
2525
[SerializeField] private AnimatorFlow animatorFlow;
2626

27-
public override string EffectTag => tag;
27+
public override string Tag => tag;
2828
public override bool IsActive() => !string.IsNullOrEmpty(tag);
2929
public override bool ValidateTag(string tag, string attributes) => true;
3030
public override void ApplyEffect(MotionRenderContext context)

Runtime/Effects/Built-in/PopInTextEffect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class PopInTextEffect : TextEffect
88
{
99
[SerializeField] private float popInDuration = 0.5f;
1010

11-
public override string EffectTag => "popin";
11+
public override string Tag => "popin";
1212
public override bool ValidateTag(string tag, string attributes) => true;
1313
public override void ApplyEffect(MotionRenderContext context)
1414
{

Runtime/Effects/Built-in/RainbowTextEffect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public sealed class RainbowTextEffect : TextEffect
99
{
1010
[SerializeField] private float test = 1;
1111

12-
public sealed override string EffectTag => "rainbow";
12+
public sealed override string Tag => "rainbow";
1313

1414
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1515
public sealed override bool ValidateTag(string tag, string attributes) => true;

Runtime/Effects/Built-in/ShakeTextEffect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ShakeTextEffect : TextEffect
99
[SerializeField] private float shakeAmount = 2f;
1010
[SerializeField] private float randomShakeInterval = 0.1f;
1111

12-
public override string EffectTag => "shake";
12+
public override string Tag => "shake";
1313
public override bool ValidateTag(string tag, string attributes) => true;
1414
public override void ApplyEffect(MotionRenderContext context)
1515
{

Runtime/Effects/Built-in/WaveTextEffect.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ public class WaveTextEffect : TextEffect
1212
[SerializeField] private float amplitude = 3f;
1313
[SerializeField] private float offset = 20f;
1414

15-
public override string EffectTag => "wave";
15+
public override string Tag => "wave";
1616
public override bool ValidateTag(string tag, string attributes) => true;
1717

1818
public override void ApplyEffect(MotionRenderContext context)
1919
{
20+
int.TryParse(context.TagData.Value, out int waveStrength);
2021
var text = context.TextMotion.TextComponent;
2122

2223
// Get the current character info
@@ -26,7 +27,7 @@ public override void ApplyEffect(MotionRenderContext context)
2627

2728
// Calculate the sine wave offset based on the animation time
2829
float funcOffset = context.AnimationTime * frequency + context.CharacterIndex * Mathf.Deg2Rad * offset;
29-
float waveOffset = Mathf.Sin(funcOffset) * amplitude; // Sine wave effect
30+
float waveOffset = Mathf.Sin(funcOffset) * (amplitude + waveStrength);
3031

3132
// Modify the character's vertex positions based on the sine wave
3233
Vector3[] vertexPositions = text.textInfo.meshInfo[materialIndex].vertices;
@@ -36,7 +37,7 @@ public override void ApplyEffect(MotionRenderContext context)
3637
vertexPositions[vertexIndex + 3] += new Vector3(0f, waveOffset, 0f);
3738

3839
// Mark the mesh as needing an update
39-
MotionRenderFlags.Add(TMP_VertexDataUpdateFlags.All);
40+
MotionRenderFlags.Add(TMP_VertexDataUpdateFlags.Vertices);
4041
}
4142
}
4243
}

Runtime/Effects/TextEffect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public abstract class TextEffect : ScriptableObject
1515
/// <summary>
1616
/// Gets the unique identifier tag for this text effect.
1717
/// </summary>
18-
public abstract string EffectTag { get; }
18+
public abstract string Tag { get; }
1919

2020
/// <summary>
2121
/// Validates the attributes provided for the text effect.

Runtime/MotionProfile.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,22 @@ namespace BP.TextMotion
1212
[CreateAssetMenu(fileName = "NewMotionProfile", menuName = "TextMotionPro/MotionProfile")]
1313
public class MotionProfile : ScriptableObject
1414
{
15+
[SerializeField] private List<TextEffect> textEffects = new();
16+
private readonly Dictionary<string, TextEffect> cache = new();
17+
1518
/// <summary>
16-
/// List of all text effects in this profile.
19+
/// Invoked whenever the text effects list changes (added, removed, etc).
1720
/// </summary>
18-
[Tooltip("Collection of text effects available in this profile")]
19-
public List<TextEffect> textEffects = new();
20-
21-
private readonly Dictionary<string, TextEffect> tagEffectCache = new();
22-
[NonSerialized] public bool isDirty = false;
21+
public event Action TextEffectsChanged;
2322

23+
/// <summary>
24+
/// Invoked whenever the text effects list changes (added, removed, etc).
25+
/// </summary>
2426
private void OnEnable()
2527
{
26-
tagEffectCache.Clear();
28+
cache.Clear();
2729
textEffects.RemoveAll(x => x == null);
2830
}
29-
public void Reset()
30-
{
31-
isDirty = true;
32-
}
3331

3432
/// <summary>
3533
/// Adds a new text effect of the specified type to the profile.
@@ -62,7 +60,7 @@ public TextEffect AddTextEffect(Type type)
6260

6361
// Add to effects list and mark as dirty
6462
textEffects.Add(component);
65-
isDirty = true;
63+
TextEffectsChanged?.Invoke();
6664
return component;
6765
}
6866

@@ -78,8 +76,17 @@ public TextEffect AddTextEffect(Type type)
7876
/// <param name="type">The type of text effect to remove.</param>
7977
public void RemoveTextEffect(Type type)
8078
{
81-
textEffects.RemoveAll(x => x.GetType().Equals(type));
82-
isDirty = true;
79+
var textEffectsToRemove = textEffects.Where(x => x.GetType().Equals(type)).ToList();
80+
foreach (var effect in textEffectsToRemove)
81+
{
82+
textEffects.Remove(effect);
83+
if (cache.ContainsKey(effect.Tag))
84+
{
85+
cache.Remove(effect.Tag);
86+
}
87+
}
88+
if (textEffectsToRemove.Count > 0)
89+
TextEffectsChanged?.Invoke();
8390
}
8491

8592
/// <summary>
@@ -104,10 +111,10 @@ public void RemoveTextEffect(Type type)
104111
public bool HasTextEffectWithTag(string tag)
105112
{
106113
// Check cache first for performance
107-
if (tagEffectCache.TryGetValue(tag, out var cachedEffect))
114+
if (cache.TryGetValue(tag, out var cachedEffect))
108115
return cachedEffect != null;
109116

110-
return textEffects.Any(x => x.EffectTag == tag);
117+
return textEffects.Any(x => x.Tag == tag);
111118
}
112119

113120
public bool TryGetTextEffectWithTag(string tag, out TextEffect textEffect)
@@ -131,13 +138,13 @@ public bool TryGetTextEffectWithTag(string tag, out TextEffect textEffect)
131138
public TextEffect GetTextEffectWithTag(string tag)
132139
{
133140
// Looks up the tag in cache
134-
if (tagEffectCache.TryGetValue(tag, out var cached))
141+
if (cache.TryGetValue(tag, out var cached))
135142
return cached;
136143

137144
// Find effect and cache it
138-
var effect = textEffects.FirstOrDefault(x => x.EffectTag == tag);
145+
var effect = textEffects.FirstOrDefault(x => x.Tag == tag);
139146
if (effect != null)
140-
tagEffectCache[tag] = effect;
147+
cache[tag] = effect;
141148

142149
return effect;
143150
}

0 commit comments

Comments
 (0)