private IEnumerator LoadUIAssetBundle(string name, UILoadState openState, KCallback callback = null) { if (openState.UIResourceLoader != null) { openState.UIResourceLoader.Release(true);// now! Log.Info("Release UI ResourceLoader: {0}", openState.UIResourceLoader.Url); openState.UIResourceLoader = null; } LoadingUICount++; var request = new UILoadRequest(); yield return(KResourceModule.Instance.StartCoroutine(UiBridge.LoadUIAsset(openState, request))); GameObject uiObj = request.Asset as GameObject; if (uiObj != null) { InitUIAsset(uiObj); // 具体加载逻辑结束 var canvas = uiObj.GetComponent <Canvas>(); //设置Canvas的enable,减少SetActive的消耗 if (canvas) { canvas.enabled = false; } uiObj.name = openState.TemplateName; var uiBase = UiBridge.CreateUIController(uiObj, openState.TemplateName); if (openState.UIWindow != null) { Log.Info("Destroy exist UI Window, maybe for reload"); GameObject.Destroy(openState.UIWindow.CachedGameObject); openState.UIWindow = null; } openState.UIWindow = uiBase; openState.WindowAsset = uiObj.GetComponent <UIWindowAsset>(); uiBase.UIName = uiBase.UITemplateName = openState.TemplateName; UiBridge.UIObjectFilter(uiBase, uiObj); openState.IsLoading = false; // Load完 openState.isOnInit = true; InitWindow(openState, uiBase, openState.OpenWhenFinish, openState.OpenArgs); } else { Log.LogError("load ui {0} result.Asset not a gameobject", name); } LoadingUICount--; if (callback != null) { callback(null); } }
private IEnumerator LoadUIAssetBundle(string name, UILoadState openState, KCallback callback = null) { if (openState.UIResourceLoader != null) { openState.UIResourceLoader.Release(true);// now! Log.Info("Release UI ResourceLoader: {0}", openState.UIResourceLoader.Url); openState.UIResourceLoader = null; } LoadingUICount++; var request = new UILoadRequest(); yield return(KResourceModule.Instance.StartCoroutine(UiBridge.LoadUIAsset(openState, request))); GameObject uiObj = (GameObject)request.Asset; if (uiObj != null) { InitUIAsset(uiObj); // 具体加载逻辑结束...这段应该放到Bridge里 uiObj.SetActive(false); uiObj.name = openState.TemplateName; var uiBase = UiBridge.CreateUIController(uiObj, openState.TemplateName); if (openState.UIWindow != null) { Log.Info("Destroy exist UI Window, maybe for reload"); GameObject.Destroy(openState.UIWindow.CachedGameObject); openState.UIWindow = null; } openState.UIWindow = uiBase; uiBase.UIName = uiBase.UITemplateName = openState.TemplateName; UiBridge.UIObjectFilter(uiBase, uiObj); openState.IsLoading = false; // Load完 openState.isOnInit = true; InitWindow(openState, uiBase, openState.OpenWhenFinish, openState.OpenArgs); } LoadingUICount--; if (callback != null) { callback(null); } }
public IEnumerator LoadUIAsset(CUILoadState loadState, UILoadRequest request) { string path = string.Format("UI/{0}_UI{1}", loadState.TemplateName, KEngine.AppEngine.GetConfig("AssetBundleExt")); var assetLoader = KStaticAssetLoader.Load(path); loadState.UIResourceLoader = assetLoader; // 基本不用手工释放的 while (!assetLoader.IsCompleted) { yield return(null); } request.Asset = assetLoader.TheAsset; }
public IEnumerator LoadUIAsset(UILoadState loadState, UILoadRequest request) { #if UNITY_5 string path = string.Format("UI/{0}.prefab", loadState.TemplateName); #else string path = string.Format("UI/{0}_UI", loadState.TemplateName); #endif var assetLoader = StaticAssetLoader.Load(path); loadState.UIResourceLoader = assetLoader; // 基本不用手工释放的 while (!assetLoader.IsCompleted) { yield return(null); } request.Asset = assetLoader.TheAsset; }
public IEnumerator LoadUIAsset(UILoadState loadState, UILoadRequest request) { float beginTime = Time.realtimeSinceStartup; string path = string.Format("ui/{0}.prefab", loadState.TemplateName); var loader = AssetBundleLoader.Load(path); while (!loader.IsCompleted) { yield return(null); } if (AppConfig.IsLogAbLoadCost) { Log.Info("{0} Load AB, cost:{1:0.000}s", loadState.TemplateName, Time.realtimeSinceStartup - beginTime); } if (AppConfig.IsSaveCostToFile) { LogFileRecorder.WriteUILog(loadState.TemplateName, LogFileRecorder.UIState.LoadAB, Time.realtimeSinceStartup - beginTime); } if (loader.Bundle == null) { yield break; } beginTime = Time.realtimeSinceStartup; var req = loader.Bundle.LoadAssetAsync <GameObject>(loadState.TemplateName); while (!req.isDone) { yield return(null); } request.Asset = GameObject.Instantiate(req.asset); loadState.UIResourceLoader = loader; if (AppConfig.IsLogAbLoadCost) { var cost = Time.realtimeSinceStartup - beginTime; Log.Info($"Load Asset from {0}, cost:{1:0.###} s", loadState.TemplateName, cost); LogFileRecorder.WriteUILog(loadState.TemplateName, LogFileRecorder.UIState.LoadAsset, cost); } }
private IEnumerator PreLoadUIAssetBundle(string windowTemplateName, UILoadState uiState) { if (uiState.UIResourceLoader != null) { uiState.UIResourceLoader.Release(true);// now! if (AppConfig.IsLogAbInfo) { Log.Info("Release UI ResourceLoader: {0}", uiState.UIResourceLoader.Url); } uiState.UIResourceLoader = null; } var request = new UILoadRequest(); yield return(KResourceModule.Instance.StartCoroutine(UiBridge.LoadUIAsset(uiState, request))); GameObject uiObj = (GameObject)request.Asset; if (uiObj != null) { InitUIAsset(uiObj); uiObj.transform.localRotation = Quaternion.identity; uiObj.transform.localScale = Vector3.one; // 具体加载逻辑结束...这段应该放到Bridge里 var canvas = uiObj.GetComponent <Canvas>(); if (canvas) { canvas.enabled = false; } else { uiObj.SetActiveX(false); } uiObj.name = uiState.TemplateName; var uiBase = UiBridge.CreateUIController(uiObj, uiState.TemplateName); if (uiState.UIWindow != null) { Log.Info("Destroy exist UI Window, maybe for reload"); GameObject.Destroy(uiState.UIWindow.CachedGameObject); uiState.UIWindow = null; } uiState.UIWindow = uiBase; uiState.WindowAsset = uiObj.GetComponent <UIWindowAsset>(); uiBase.UIName = uiBase.UITemplateName = uiState.TemplateName; UiBridge.UIObjectFilter(uiBase, uiObj); uiState.IsLoading = false; // Load完 uiState.OnUIWindowLoadedCallbacks(uiState, uiBase); if (uiState.OpenWhenFinish) { InitWindow(uiState, uiBase, true, uiState.OpenArgs); } else { if (OnInitEvent != null) { OnInitEvent(uiBase); } } } LoadingUICount--; }
private IEnumerator PreLoadUIAssetBundle(string windowTemplateName, UILoadState uiState) { if (uiState.UIResourceLoader != null) { uiState.UIResourceLoader.Release(true);// now! Log.Info("Release UI ResourceLoader: {0}", uiState.UIResourceLoader.Url); uiState.UIResourceLoader = null; } var request = new UILoadRequest(); yield return(KResourceModule.Instance.StartCoroutine(UiBridge.LoadUIAsset(uiState, request))); GameObject uiObj = (GameObject)request.Asset; GameObject uiRoot = GameObject.Find("UIRoot"); if (uiRoot == null) { uiRoot = new GameObject("UIRoot"); if (!SceneLoader.isLoadSceneAdditive) { GameObject.DontDestroyOnLoad(uiRoot); } } if (uiObj != null) { uiObj.transform.SetParent(uiRoot.transform); uiObj.transform.localRotation = Quaternion.identity; uiObj.transform.localScale = Vector3.one; // 具体加载逻辑结束...这段应该放到Bridge里 uiObj.SetActive(false); uiObj.name = uiState.TemplateName; var uiBase = UiBridge.CreateUIController(uiObj, uiState.TemplateName); if (uiState.UIWindow != null) { Log.Info("Destroy exist UI Window, maybe for reload"); GameObject.Destroy(uiState.UIWindow.CachedGameObject); uiState.UIWindow = null; } uiState.UIWindow = uiBase; uiBase.UIName = uiBase.UITemplateName = uiState.TemplateName; UiBridge.UIObjectFilter(uiBase, uiObj); uiState.IsLoading = false; // Load完 uiBase.gameObject.SetActive(false); uiState.OnUIWindowLoadedCallbacks(uiState, uiBase); if (uiState.OpenWhenFinish) { InitWindow(uiState, uiBase, true, uiState.OpenArgs); } else { if (OnInitEvent != null) { OnInitEvent(uiBase); } } } LoadingUICount--; }
public IEnumerator LoadUIAsset(UILoadState loadState, UILoadRequest request) { float beginTime = Time.realtimeSinceStartup; string path = string.Format("ui/{0}", loadState.TemplateName); var loader = AssetBundleLoader.Load(path); while (!loader.IsCompleted) { yield return(null); } #if UNITY_EDITOR if (KResourceModule.IsEditorLoadAsset) { var go = GameObject.Instantiate(loader.ResultObject as GameObject); request.Asset = go; var windowAsset = go.GetComponent <UIWindowAsset>(); if (windowAsset) { //TODO unity2019.3.7f1 图片已设置上去了,但无法显示,勾选atlas中的Include In Build就可以正常显示,但打包AB时需要强制去掉勾选 windowAsset.IsUIEditor = true; windowAsset.InitEvent();//监听atlasRequested事件 if (!string.IsNullOrEmpty(windowAsset.atals_arr)) { string[] arr = windowAsset.atals_arr.Split(','); int sprite_count = 0; for (int i = 0; i < arr.Length; i++) { string atlas_name = arr[i].ToLower(); if (!UIModule.Instance.CommonAtlases.Contains(atlas_name)) { sprite_count++; } } if (sprite_count >= 2) { Log.LogError($"UI:{loadState.TemplateName}包括多个图集({windowAsset.atals_arr}),请处理"); } } } } else #endif { if (AppConfig.IsLogAbLoadCost) { Log.Info("{0} Load AB, cost:{1:0.000}s", loadState.TemplateName, Time.realtimeSinceStartup - beginTime); } if (AppConfig.IsSaveCostToFile) { LogFileRecorder.WriteUILog(loadState.TemplateName, LogFileRecorder.UIState.LoadAB, Time.realtimeSinceStartup - beginTime); } if (loader.Bundle == null) { yield break; } beginTime = Time.realtimeSinceStartup; var req = loader.Bundle.LoadAssetAsync <GameObject>(loadState.TemplateName); while (!req.isDone) { yield return(null); } request.Asset = GameObject.Instantiate(req.asset); //管理图集 var go = req.asset as GameObject; if (go) { var windowAsset = go.GetComponent <UIWindowAsset>(); if (windowAsset && !string.IsNullOrEmpty(windowAsset.atals_arr)) { string[] arr = windowAsset.atals_arr.Split(','); int sprite_count = 0; for (int i = 0; i < arr.Length; i++) { string atlas_name = arr[i].ToLower(); if (!UIModule.Instance.CommonAtlases.Contains(atlas_name)) { sprite_count++; } var atlas = loader.Bundle.LoadAsset <SpriteAtlas>(atlas_name); if (atlas != null) { ABManager.SpriteAtlases[atlas_name] = atlas; } } if (sprite_count >= 2) { Log.LogError($"UI:{loadState.TemplateName}包括多个图集({windowAsset.atals_arr}),请处理"); } } } } loadState.UIResourceLoader = loader; if (AppConfig.IsLogAbLoadCost) { var cost = Time.realtimeSinceStartup - beginTime; Log.Info($"Load Asset from {0}, cost:{1:0.###} s", loadState.TemplateName, cost); LogFileRecorder.WriteUILog(loadState.TemplateName, LogFileRecorder.UIState.LoadAsset, cost); } }