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..a34163b5 100644 --- a/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs +++ b/src/LitMotion/Assets/LitMotion.Animation/Runtime/LitMotionAnimation.cs @@ -16,15 +16,26 @@ 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 List playingLitMotionAnimations = new(); public IReadOnlyList Components => components; + void Awake() + { + if (groupIdSource != null) + GroupId += groupIdSource.GetInstanceID(); + } + void Start() { if (playOnAwake) Play(); @@ -79,6 +90,17 @@ public void Play() if (isPlaying) return; playingComponents.Clear(); + if (solo) + { + for (int i = playingLitMotionAnimations.Count - 1; 0 <= i; --i) + { + var anim = playingLitMotionAnimations[i]; + if (anim == null || anim.StopByGroupId(GroupId)) + playingLitMotionAnimations.RemoveAt(i); + } + } + if (!playingLitMotionAnimations.Contains(this)) + playingLitMotionAnimations.Add(this); switch (animationMode) { @@ -148,6 +170,16 @@ public void Stop() queue.Clear(); } + public bool StopByGroupId(string id) + { + if (GroupId == id || string.IsNullOrEmpty(id)) + { + Stop(); + return true; + } + return false; + } + public void Restart() { Stop(); @@ -190,5 +222,12 @@ void OnDestroy() { Stop(); } + + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] + static void OnDomainReload() + { + playingLitMotionAnimations = new(); + } + } } \ No newline at end of file