com.alicizax.unity.animatio.../Editor/Misc/EditorResourceTool.cs

60 lines
2.0 KiB
C#
Raw Normal View History

2025-02-07 16:05:13 +08:00
using System.Collections.Generic;
using UnityEngine;
2025-03-12 20:58:49 +08:00
namespace AlicizaX.AnimationFlow.Editor
{
public static class EditorResourceTool
{
2025-02-07 16:05:13 +08:00
public static string editorAssets;
2025-03-12 20:58:49 +08:00
public static bool LocateEditorAssets()
{
2025-02-07 16:05:13 +08:00
string projectPath = Application.dataPath;
2025-03-12 20:58:49 +08:00
if (projectPath.EndsWith("/Assets"))
{
2025-02-07 16:05:13 +08:00
projectPath = projectPath.Remove(projectPath.Length - ("Assets".Length));
}
2025-03-12 20:58:49 +08:00
editorAssets = "Packages/com.alicizax.unity.animationflow/Editor/Styles";
if (!System.IO.File.Exists(projectPath + editorAssets + "/AnimationFlowStyles.uss"))
{
2025-02-07 16:05:13 +08:00
var sdir = new System.IO.DirectoryInfo(Application.dataPath);
var dirQueue = new Queue<System.IO.DirectoryInfo>();
dirQueue.Enqueue(sdir);
bool found = false;
2025-03-12 20:58:49 +08:00
while (dirQueue.Count > 0)
{
2025-02-07 16:05:13 +08:00
System.IO.DirectoryInfo dir = dirQueue.Dequeue();
2025-03-12 20:58:49 +08:00
if (System.IO.File.Exists(dir.FullName + "/AnimationFlowStyles.uss"))
{
2025-02-07 16:05:13 +08:00
string path = dir.FullName.Replace('\\', '/');
found = true;
path = path.Replace(projectPath, "");
2025-03-12 20:58:49 +08:00
if (path.StartsWith("/"))
{
2025-02-07 16:05:13 +08:00
path = path.Remove(0, 1);
}
2025-03-12 20:58:49 +08:00
2025-02-07 16:05:13 +08:00
editorAssets = path;
return true;
}
2025-03-12 20:58:49 +08:00
2025-02-07 16:05:13 +08:00
var dirs = dir.GetDirectories();
2025-03-12 20:58:49 +08:00
for (int i = 0; i < dirs.Length; i++)
{
2025-02-07 16:05:13 +08:00
dirQueue.Enqueue(dirs[i]);
}
}
2025-03-12 20:58:49 +08:00
if (!found)
{
2025-02-07 16:05:13 +08:00
Debug.LogWarning("Could not locate editor assets folder. Make sure you have imported the package correctly.");
return false;
}
}
2025-03-12 20:58:49 +08:00
2025-02-07 16:05:13 +08:00
return true;
}
}
}