From 44b8b3a2165743ee956229694dc93919aa33c723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=80=9D=E6=B5=B7?= <1464576565@qq.com> Date: Wed, 12 Mar 2025 20:58:49 +0800 Subject: [PATCH] modify --- Editor/Misc/EditorResourceTool.cs | 37 +++++++++++++------ Runtime/AlicizaX.AnimationFlow.Runtime.asmdef | 4 +- Runtime/AnimationFlow.cs | 28 ++++++++++---- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/Editor/Misc/EditorResourceTool.cs b/Editor/Misc/EditorResourceTool.cs index 098bf11..adcb558 100644 --- a/Editor/Misc/EditorResourceTool.cs +++ b/Editor/Misc/EditorResourceTool.cs @@ -1,43 +1,58 @@ using System.Collections.Generic; using UnityEngine; -namespace AlicizaX.AnimationFlow.Editor { - public static class EditorResourceTool { +namespace AlicizaX.AnimationFlow.Editor +{ + public static class EditorResourceTool + { public static string editorAssets; - public static bool LocateEditorAssets() { + public static bool LocateEditorAssets() + { string projectPath = Application.dataPath; - if (projectPath.EndsWith("/Assets")) { + if (projectPath.EndsWith("/Assets")) + { projectPath = projectPath.Remove(projectPath.Length - ("Assets".Length)); } - editorAssets = "Packages/com.yuliuren.alicizaframework/ThirdParty/AnimationFlow/Editor/Styles"; - if (!System.IO.File.Exists(projectPath + editorAssets + "/AnimationFlowStyles.uss")) { + + editorAssets = "Packages/com.alicizax.unity.animationflow/Editor/Styles"; + if (!System.IO.File.Exists(projectPath + editorAssets + "/AnimationFlowStyles.uss")) + { var sdir = new System.IO.DirectoryInfo(Application.dataPath); var dirQueue = new Queue(); dirQueue.Enqueue(sdir); bool found = false; - while (dirQueue.Count > 0) { + while (dirQueue.Count > 0) + { System.IO.DirectoryInfo dir = dirQueue.Dequeue(); - if (System.IO.File.Exists(dir.FullName + "/AnimationFlowStyles.uss")) { + if (System.IO.File.Exists(dir.FullName + "/AnimationFlowStyles.uss")) + { string path = dir.FullName.Replace('\\', '/'); found = true; path = path.Replace(projectPath, ""); - if (path.StartsWith("/")) { + if (path.StartsWith("/")) + { path = path.Remove(0, 1); } + editorAssets = path; return true; } + var dirs = dir.GetDirectories(); - for (int i = 0; i < dirs.Length; i++) { + for (int i = 0; i < dirs.Length; i++) + { dirQueue.Enqueue(dirs[i]); } } - if (!found) { + + if (!found) + { Debug.LogWarning("Could not locate editor assets folder. Make sure you have imported the package correctly."); return false; } } + return true; } } diff --git a/Runtime/AlicizaX.AnimationFlow.Runtime.asmdef b/Runtime/AlicizaX.AnimationFlow.Runtime.asmdef index 794feed..70643c1 100644 --- a/Runtime/AlicizaX.AnimationFlow.Runtime.asmdef +++ b/Runtime/AlicizaX.AnimationFlow.Runtime.asmdef @@ -1,7 +1,9 @@ { "name": "AlicizaX.AnimationFlow.Runtime", "rootNamespace": "AlicizaX.AnimationFlow.Runtime", - "references": [], + "references": [ + "GUID:f51ebe6a0ceec4240a699833d6309b23" + ], "includePlatforms": [], "excludePlatforms": [], "allowUnsafeCode": false, diff --git a/Runtime/AnimationFlow.cs b/Runtime/AnimationFlow.cs index f60d34b..013a122 100644 --- a/Runtime/AnimationFlow.cs +++ b/Runtime/AnimationFlow.cs @@ -2,17 +2,19 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using Cysharp.Threading.Tasks; using Sirenix.OdinInspector; using UnityEngine; namespace AlicizaX.AnimationFlow.Runtime { + [DisallowMultipleComponent] public class AnimationFlow : MonoBehaviour { #region Editor相关 #if UNITY_EDITOR - IEnumerable GetAllAnimationClips + public List GetAllAnimationClips { get { @@ -33,7 +35,7 @@ namespace AlicizaX.AnimationFlow.Runtime [Button("节点编辑器", ButtonSizes.Large), GUIColor(0, 1, 0)] private void OpenGraphWindow() { - UnityEditor.EditorApplication.ExecuteMenuItem("AlicizaFramework/Window/AnimationGraph"); + UnityEditor.EditorApplication.ExecuteMenuItem("Window/AnimationGraph"); } #endif @@ -223,14 +225,19 @@ namespace AlicizaX.AnimationFlow.Runtime _resetNodes.Add(node); } + public UniTask PlayAsync(string clipName) + { + + var tcs = new UniTaskCompletionSource(); + + Action asyncCallBack = () => tcs.TrySetResult(); + Play(clipName, asyncCallBack); + + return tcs.Task; + } public void Play(string clipName = "", Action actionComplete = null) { - if (_playebleType == EAnimationFlowPlayebleType.Play) - { - Debug.LogWarning($"animation flow is playing!"); - return; - } if (string.IsNullOrEmpty(clipName) || clipName == "None") { @@ -238,6 +245,13 @@ namespace AlicizaX.AnimationFlow.Runtime return; } + if (_playebleType == EAnimationFlowPlayebleType.Play) + { + Debug.LogWarning($"animation flow is playing!"); + StopFlow(true); + } + + _playFinishEvent = actionComplete; EntryNode entryNode = AnimationNodes.Find(a => a.Name == clipName);