/// <summary> /// 这个方法要做成适合Editor与各个平台公用 /// </summary> private static IEnumerator _loadAB(string path, System.Action <AssetBundle> cb) { path = fixedPath(path); WWW www = WWW.LoadFromCacheOrDownload(path, 1); yield return(www); if (string.IsNullOrEmpty(www.error)) { AssetBundle assetBundle = www.assetBundle; abMap.Add(path, assetBundle); if (null != cb) { cb(assetBundle); } } else { KLogger.LogError(www.error); } }
/// <summary> /// 加载Window /// </summary> /// <typeparam name="T"></typeparam> /// <param name="data"></param> /// <example> /// var win = KUI.LoadWindow<MainWindow>(null); /// </example> /// <returns></returns> public static T LoadWindow <T>(object data) where T : KUIWindow { var sw = new System.Diagnostics.Stopwatch(); sw.Start(); string uiName = typeof(T).Name; if (!uiMap.ContainsKey(uiName)) { KLogger.LogError("KUI|没有找到对应的UI|" + uiName); return(default(T)); } string uiPath = uiMap[uiName]; var swResLoad = new System.Diagnostics.Stopwatch(); swResLoad.Start(); var prefab = Resources.Load <T>(uiPath); swResLoad.Stop(); KLogger.LogError("KUI|Resources.Load|时间|" + swResLoad.ElapsedMilliseconds); var swInst = new System.Diagnostics.Stopwatch(); swInst.Start(); T go = GameObject.Instantiate <T>(prefab); swInst.Stop(); KLogger.LogError("KUI|GameObject.Instantiate|时间|" + swInst.ElapsedMilliseconds); sw.Stop(); KLogger.LogError("KUI|LoadWindow|时间|" + sw.ElapsedMilliseconds); return(go); }