public static async Task Load() { #if UNITY_EDITOR string path = $"Assets/Art/Assets/Setting/{typeof(T).Name}.asset"; Instance = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(path); #else //编辑器情况下无法使用await //using (zstring.Block()) //{ Instance = await ResourceManager.LoadAsset($"Assets/Art/Assets/Setting/{typeof(T).Name}.asset") as SettingBaseAsset <T>; //} #endif }
public static async Task Refresh() { #if UNITY_EDITOR string path = $"Assets/Art/Assets/Config/{typeof(T).Name}.asset"; Instance = UnityEditor.AssetDatabase.LoadAssetAtPath <ConfigBaseAsset <T> >(path); #else //编辑器情况下无法使用await //using (zstring.Block()) //{ Instance = await ResourceManager.LoadAsset($"Assets/Art/Assets/Config/{typeof(T).Name}.asset") as ConfigBaseAsset <T>; //} #endif Map.Clear(); if (Instance.Configs != null) { for (int i = 0; i < Instance.Configs.Length; i++) { T t = Instance.Configs[i]; Map.Add(t.ID, t); } } }
public static async Task <SpriteAtlas> TetstAsync(string AtlasName, Action <SpriteAtlas> action) { SpriteAtlas sa; if (!SpriteAtlasMap.TryGetValue(AtlasName, out sa)) { if (!SpriteAltasActions.ContainsKey(AtlasName)) { SpriteAltasActions[AtlasName] = new List <Action <SpriteAtlas> >(); SpriteAltasActions[AtlasName].Add(action); } else { SpriteAltasActions[AtlasName].Add(action); return(sa); } sa = await ResourceManager.LoadAsset(m_RootPath + $"{AtlasName}/{AtlasName}.spriteatlas") as SpriteAtlas; if (sa == null) { Debug.LogError("加载 " + AtlasName + "失败"); return(sa); } SpriteAtlasMap.Add(AtlasName, sa); foreach (var a in SpriteAltasActions[AtlasName]) { a?.Invoke(sa); } SpriteAltasActions.Remove(AtlasName); //action?.Invoke(sa); } else { action?.Invoke(sa); } return(sa); }
public static async void LoadMapInternal(XLua.LuaTable precess, string mapName, Action callback = null) { m_Env = GameObject.Find("Env"); m_Light = GameObject.Find("Sun").GetComponent <Light>(); //1.加载场景信息 string InfoPath = $"Assets/Art/Scenes/{mapName}/{mapName}/sceneenv.asset"; SceneEnvAsset env = await ResourceManager.LoadAsset(InfoPath) as SceneEnvAsset; string ElementPath = $"Assets/Art/Assets/Scene/{mapName}/{mapName}.asset"; //2.加载地形 SceneElementAsset sceneElements = await ResourceManager.LoadAsset(ElementPath) as SceneElementAsset; List <GameObject> list = await MapManager.LoadPreElement(sceneElements); m_CurrentEnv = env; m_CurrentElements = sceneElements; m_LoadedObjectList.AddRange(list); callback?.Invoke(); //4.优先展示出来基本的灯光、草的环境 Show(true); Name = mapName; //5.最后去异步加载出来场景中的元素 AddSceneElements(); ////3.如果是野外场景需要动态生成导航网格,战斗场景和UI场景不需要 //if (env.sceneType == SceneType.Wild) //{ // LocalNavMeshLoading.Instance.UpdateNavMesh(true); // Debug.Log($"[C#] SceneTree.cs ::load({mapName}) 展示基本灯光、草后开启异步加载场景元素并开始异步烘焙导航网格"); //} callback?.Invoke(); //加载完成, 通知lua precess.Set("IsDone", true); precess.Set("proess", 1); }