From 651d216057ca5853e40e90366c2f8bee1e9414fc Mon Sep 17 00:00:00 2001 From: {} Date: Wed, 25 Jun 2025 15:18:14 +0900 Subject: [PATCH 1/3] Add feature solo-playing --- .../Editor/LitMotionAnimationEditor.cs | 17 +++++++++++ .../Runtime/LitMotionAnimation.cs | 28 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/LitMotion/Assets/LitMotion.Animation/Editor/LitMotionAnimationEditor.cs b/src/LitMotion/Assets/LitMotion.Animation/Editor/LitMotionAnimationEditor.cs index e9bcd1cd..ba82b397 100644 --- a/src/LitMotion/Assets/LitMotion.Animation/Editor/LitMotionAnimationEditor.cs +++ b/src/LitMotion/Assets/LitMotion.Animation/Editor/LitMotionAnimationEditor.cs @@ -95,6 +95,23 @@ VisualElement CreateSettingsPanel() var box = CreateBox("Settings"); box.Add(new PropertyField(serializedObject.FindProperty("playOnAwake"))); box.Add(new PropertyField(serializedObject.FindProperty("animationMode"))); + box.Add(new PropertyField(serializedObject.FindProperty("solo"))); + var row = new VisualElement(); + row.style.flexDirection = FlexDirection.Row; + row.Add(new PropertyField(serializedObject.FindProperty("GroupId"), "Group ID, Source") + { + style = { + flexGrow = 1, + marginRight = 4 + } + }); + row.Add(new PropertyField(serializedObject.FindProperty("groupIdSource")) + { + style = { + flexGrow = 1, + } + }); + box.Add(row); return box; } diff --git a/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs b/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs index 4351b75a..caf53892 100644 --- a/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs +++ b/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs @@ -16,17 +16,24 @@ enum AnimationMode [SerializeField] bool playOnAwake = true; [SerializeField] AnimationMode animationMode; + [SerializeField] bool solo; + public string GroupId; + [SerializeField] GameObject groupIdSource; + [SerializeReference] LitMotionAnimationComponent[] components; Queue queue = new(); FastListCore playingComponents; + static HashSet playingLitMotionAnimations = new(); public IReadOnlyList Components => components; void Start() { + if (groupIdSource != null) + GroupId += groupIdSource.GetInstanceID(); if (playOnAwake) Play(); } @@ -79,6 +86,14 @@ public void Play() if (isPlaying) return; playingComponents.Clear(); + if (solo) + { + foreach (var i in playingLitMotionAnimations) + if (i != null) + i.StopByGroupId(GroupId); + playingLitMotionAnimations.RemoveWhere(e => e == null || !e.IsPlaying); + } + playingLitMotionAnimations.Add(this); switch (animationMode) { @@ -148,6 +163,12 @@ public void Stop() queue.Clear(); } + public void StopByGroupId(string id) + { + if (GroupId == id || string.IsNullOrEmpty(id)) + Stop(); + } + public void Restart() { Stop(); @@ -190,5 +211,12 @@ void OnDestroy() { Stop(); } + + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] + static void OnDomainReload() + { + playingLitMotionAnimations = new(); + } + } } \ No newline at end of file From d713b92636b16ae5975dea4c14addbed47408151 Mon Sep 17 00:00:00 2001 From: {} Date: Thu, 26 Jun 2025 13:40:11 +0900 Subject: [PATCH 2/3] Changed the timing of GroupID calculation to Awake --- .../LitMotion.Animation/Runtime/LitMotionAnimation.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs b/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs index caf53892..e62fc5f6 100644 --- a/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs +++ b/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs @@ -30,10 +30,14 @@ enum AnimationMode public IReadOnlyList Components => components; - void Start() + void Awake() { if (groupIdSource != null) GroupId += groupIdSource.GetInstanceID(); + } + + void Start() + { if (playOnAwake) Play(); } From 43df1ba98730b303ad573c08edbb6f8ed162ec4a Mon Sep 17 00:00:00 2001 From: {} Date: Thu, 26 Jun 2025 22:45:09 +0900 Subject: [PATCH 3/3] bugfix --- .../Runtime/LitMotionAnimation.cs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs b/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs index e62fc5f6..a34163b5 100644 --- a/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs +++ b/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs @@ -26,7 +26,7 @@ enum AnimationMode Queue queue = new(); FastListCore playingComponents; - static HashSet playingLitMotionAnimations = new(); + static List playingLitMotionAnimations = new(); public IReadOnlyList Components => components; @@ -92,12 +92,15 @@ public void Play() playingComponents.Clear(); if (solo) { - foreach (var i in playingLitMotionAnimations) - if (i != null) - i.StopByGroupId(GroupId); - playingLitMotionAnimations.RemoveWhere(e => e == null || !e.IsPlaying); + for (int i = playingLitMotionAnimations.Count - 1; 0 <= i; --i) + { + var anim = playingLitMotionAnimations[i]; + if (anim == null || anim.StopByGroupId(GroupId)) + playingLitMotionAnimations.RemoveAt(i); + } } - playingLitMotionAnimations.Add(this); + if (!playingLitMotionAnimations.Contains(this)) + playingLitMotionAnimations.Add(this); switch (animationMode) { @@ -167,10 +170,14 @@ public void Stop() queue.Clear(); } - public void StopByGroupId(string id) + public bool StopByGroupId(string id) { if (GroupId == id || string.IsNullOrEmpty(id)) + { Stop(); + return true; + } + return false; } public void Restart()