summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/EditorResourceHelper.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-23 10:08:29 +0800
committerchai <215380520@qq.com>2024-05-23 10:08:29 +0800
commit8722a9920c1f6119bf6e769cba270e63097f8e25 (patch)
tree2eaf9865de7fb1404546de4a4296553d8f68cc3b /Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/EditorResourceHelper.cs
parent3ba4020b69e5971bb0df7ee08b31d10ea4d01937 (diff)
+ astar project
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/EditorResourceHelper.cs')
-rw-r--r--Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/EditorResourceHelper.cs101
1 files changed, 101 insertions, 0 deletions
diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/EditorResourceHelper.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/EditorResourceHelper.cs
new file mode 100644
index 0000000..4dd61d9
--- /dev/null
+++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/PackageTools/EditorResourceHelper.cs
@@ -0,0 +1,101 @@
+namespace Pathfinding {
+#if UNITY_EDITOR
+ using UnityEditor;
+ using UnityEngine;
+ using System.Collections.Generic;
+
+ /// <summary>Internal utility class for looking up editor resources</summary>
+ public static class EditorResourceHelper {
+ /// <summary>
+ /// Path to the editor assets folder for the A* Pathfinding Project. If this path turns out to be incorrect, the script will try to find the correct path
+ /// See: LoadStyles
+ /// </summary>
+ public static string editorAssets;
+
+ static EditorResourceHelper () {
+ // Look up editor assets directory when first accessed
+ LocateEditorAssets();
+ }
+
+ static Material surfaceMat, lineMat;
+ static Texture2D handlesAALineTex;
+ public static Material GizmoSurfaceMaterial {
+ get {
+ if (!surfaceMat) surfaceMat = Resources.Load<Material>("aline_surface");
+ return surfaceMat;
+ }
+ }
+
+ public static Material GizmoLineMaterial {
+ get {
+ if (!lineMat) lineMat = Resources.Load<Material>("aline_outline");
+ return lineMat;
+ }
+ }
+
+ public static Texture2D HandlesAALineTexture {
+ get {
+ if (!handlesAALineTex) handlesAALineTex = Resources.Load<Texture2D>("handles_aaline");
+ return handlesAALineTex;
+ }
+ }
+
+
+ /// <summary>Locates the editor assets folder in case the user has moved it</summary>
+ public static bool LocateEditorAssets () {
+ var package = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(EditorResourceHelper).Assembly);
+
+ if (package != null) {
+ editorAssets = package.assetPath + "/Editor/EditorAssets";
+ if (System.IO.File.Exists(package.resolvedPath + "/Editor/EditorAssets/AstarEditorSkinLight.guiskin")) {
+ return true;
+ } else {
+ Debug.LogError("Could not find editor assets folder in package at " + editorAssets + ". Is the package corrupt?");
+ return false;
+ }
+ }
+
+ string projectPath = Application.dataPath;
+
+ if (projectPath.EndsWith("/Assets")) {
+ projectPath = projectPath.Remove(projectPath.Length-("Assets".Length));
+ }
+
+ editorAssets = "Assets/AstarPathfindingProject/Editor/EditorAssets";
+ if (!System.IO.File.Exists(projectPath + editorAssets + "/AstarEditorSkinLight.guiskin") && !System.IO.File.Exists(projectPath + editorAssets + "/AstarEditorSkin.guiskin")) {
+ //Initiate search
+
+ var sdir = new System.IO.DirectoryInfo(Application.dataPath);
+
+ var dirQueue = new Queue<System.IO.DirectoryInfo>();
+ dirQueue.Enqueue(sdir);
+
+ while (dirQueue.Count > 0) {
+ System.IO.DirectoryInfo dir = dirQueue.Dequeue();
+ if (System.IO.File.Exists(dir.FullName + "/AstarEditorSkinLight.guiskin") || System.IO.File.Exists(dir.FullName + "/AstarEditorSkin.guiskin")) {
+ // Handle windows file paths
+ string path = dir.FullName.Replace('\\', '/');
+ // Remove data path from string to make it relative
+ path = path.Replace(projectPath, "");
+
+ if (path.StartsWith("/")) {
+ path = path.Remove(0, 1);
+ }
+
+ editorAssets = path;
+ return true;
+ }
+ var dirs = dir.GetDirectories();
+ for (int i = 0; i < dirs.Length; i++) {
+ dirQueue.Enqueue(dirs[i]);
+ }
+ }
+
+ Debug.LogWarning("Could not locate editor assets folder. Make sure you have imported the package correctly.\nA* Pathfinding Project");
+ return false;
+ }
+ return true;
+ }
+ }
+#endif
+}