This commit is contained in:
陈思海 2025-03-12 20:58:49 +08:00
parent 11e5744b46
commit 44b8b3a216
3 changed files with 50 additions and 19 deletions

View File

@ -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<System.IO.DirectoryInfo>();
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;
}
}

View File

@ -1,7 +1,9 @@
{
"name": "AlicizaX.AnimationFlow.Runtime",
"rootNamespace": "AlicizaX.AnimationFlow.Runtime",
"references": [],
"references": [
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,

View File

@ -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<string> 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);