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; 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); } }