| | |
| | | using UnityEngine.Video; |
| | | using Spine.Unity; |
| | | using UnityEngine.UI; |
| | | using Cysharp.Threading.Tasks; |
| | | |
| | | |
| | | |
| | | |
| | |
| | | //needExt 是否需要函数内部添加后缀 |
| | | public T LoadAsset<T>(string directory, string name, bool needExt = true) where T : UnityEngine.Object |
| | | { |
| | | directory = directory.Replace("\\", "/"); |
| | | name = name.Replace("\\", "/"); |
| | | T asset = null; |
| | | // 特殊处理 因为有一层图集的关系 directory要传入的应该是atlas的名字 |
| | | if (typeof(T) == typeof(Sprite)) |
| | |
| | | name = name.Substring(name.LastIndexOf("/") + 1); |
| | | } |
| | | |
| | | directory = directory.Replace("\\", "/"); |
| | | } |
| | | |
| | | return LoadAssetInternal<T>(directory, name, needExt); |
| | |
| | | return LoadAssetInternal<Sprite>(atlasName, spriteName); |
| | | } |
| | | |
| | | //needExt 是否需要函数内部添加后缀 |
| | | public void LoadAssetAsync<T>(string directory, string name, Action<bool, UnityEngine.Object> callBack, bool needExt = true) where T : UnityEngine.Object |
| | | { |
| | | directory = directory.Replace("\\", "/"); |
| | | name = name.Replace("\\", "/"); |
| | | |
| | | // 特殊处理 因为有一层图集的关系 directory要传入的应该是atlas的名字 |
| | | if (typeof(T) == typeof(Sprite)) |
| | | { |
| | | LoadSpriteAsync<T>(directory, name, callBack); |
| | | return; |
| | | } |
| | | else if (typeof(T) == typeof(SkeletonDataAsset)) |
| | | { |
| | | //文件目录调整,name中包含了路径 |
| | | if (name.Contains("/")) |
| | | { |
| | | directory += name.Substring(0, name.LastIndexOf("/")); |
| | | name = name.Substring(name.LastIndexOf("/") + 1); |
| | | } |
| | | |
| | | } |
| | | |
| | | LoadAssetAsyncInternal<T>(directory, name, callBack, needExt); |
| | | } |
| | | |
| | | public async UniTask<T> LoadAssetAsync<T>(string directory, string name, bool needExt = true) where T : UnityEngine.Object |
| | | { |
| | | var tcs = new UniTaskCompletionSource<T>(); |
| | | LoadAssetAsync<T>(directory, name, (isLoaded, asset) => { |
| | | if (isLoaded) |
| | | { |
| | | tcs.TrySetResult(asset as T); |
| | | } |
| | | else |
| | | { |
| | | tcs.TrySetException(new Exception($"Failed to load asset: {directory}/{name}")); |
| | | } |
| | | }, needExt); |
| | | return await tcs.Task; |
| | | } |
| | | |
| | | private void LoadSpriteAsync<T>(string atlasName, string spriteName, Action<bool, UnityEngine.Object> callBack) where T : UnityEngine.Object |
| | | { |
| | | #if !UNITY_EDITOR |