Created
October 24, 2020 12:26
-
-
Save korchoon/7e852f44d256d4ba81814db87bba0193 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Linq; | |
using UnityEditor; | |
using UnityEngine.UIElements; | |
class PathApi { | |
public string MonoPath; | |
public string Dir() { | |
return Path.GetDirectoryName(MonoPath).Replace('\\', '/'); | |
} | |
public VisualTreeAsset Uxml(string name) { | |
return Load<VisualTreeAsset>(name, "uxml"); | |
} | |
public StyleSheet Uss(string name) { | |
return Load<StyleSheet>(name, "uss"); | |
} | |
T Load<T>(string name, string ext) where T : UnityEngine.Object { | |
var p = Dir(); | |
if (name.Contains("../")) { | |
var ups = name.Split(new[] {"../"}, StringSplitOptions.RemoveEmptyEntries); | |
var arr = p.Split(new[] {"/"}, StringSplitOptions.RemoveEmptyEntries); | |
p = arr.Take(arr.Length - ups.Length).Aggregate((a, b) => $"{a}/{b}"); | |
p = $"{p}/{ups.Last()}.{ext}"; | |
var res = AssetDatabase.LoadAssetAtPath<T>(p); | |
Asr.IsTrue(res, p); | |
return res; | |
} | |
else { | |
p = $"{p}/{name}.{ext}"; | |
var res = AssetDatabase.LoadAssetAtPath<T>(p); | |
Asr.IsTrue(res, p); | |
return res; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment