/// <summary> /// 加载UI影射,需要指定UI预制的根目录 /// </summary> public static void LoadUIManifest(string uiRootPath) { string resIndicator = "Resources/"; var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var files = Directory.GetFiles(uiRootPath, "*.prefab", System.IO.SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { //统一目录分隔符 string fullpath = files[i].Replace("\\", "/"); //以Resources.Load方式来加载 int resIx = fullpath.IndexOf(resIndicator); fullpath = fullpath.Substring(resIx + resIndicator.Length); var fileInfo = new FileInfo(fullpath); string key = fileInfo.Name.Replace(".prefab", ""); string value = fullpath.Replace(".prefab", ""); uiMap.Add(key, value); //KLogger.Log("file|i|" + i + "|key|" + key + "|value|" + value); } sw.Stop(); KLogger.Log("KUI|加载Map时间|" + sw.ElapsedMilliseconds); }
public static void LoadByPath(string path, System.Action <AssetBundle> cb) { //总是先尝试初始化 Init(); path = fixedPath(path); if (abMap.ContainsKey(path) && null != abMap[path]) { KLogger.Log("使用缓存的AB|" + path); cb(abMap[path]); return; } self.StartCoroutine(_loadAB(path, cb)); }
private static void Init() { //已经初始化则不处理了 if (null != self) { return; } self = GameObject.FindObjectOfType <KAssetBundle>(); if (self == null) { KLogger.Log("开始初始化|KAssetBundle"); GameObject go = new GameObject(); go.name = "__KAssetBundle__"; DontDestroyOnLoad(go); //场景切换也保留 self = go.AddComponent <KAssetBundle>(); } }