IEnumerator LoadUIAssetBundle(string path, string name, CUILoadState openState) { var assetLoader = CStaticAssetLoader.Load(path); openState.UIResourceLoader = assetLoader; // 基本不用手工释放的 while (!assetLoader.IsFinished) { yield return(null); } GameObject uiObj = (GameObject)assetLoader.TheAsset; openState.IsLoading = false; // Load完 uiObj.SetActive(false); uiObj.name = openState.TemplateName; CUIController uiBase = (CUIController)uiObj.AddComponent(openState.UIType); UiBridge.UIObjectFilter(uiBase, uiObj); openState.UIWindow = uiBase; uiBase.UIName = uiBase.UITemplateName = openState.TemplateName; InitWindow(openState, uiBase, openState.OpenWhenFinish, openState.OpenArgs); }
IEnumerator LoadUIAssetBundle(string path, string name, CUILoadState openState) { CAssetLoader assetLoader = new CAssetLoader(path); while (!assetLoader.IsFinished) { yield return(null); } GameObject uiObj = (GameObject)assetLoader.Asset; openState.IsLoading = false; uiObj.SetActive(false); uiObj.name = openState.Name; UiBridge.UIObjectFilter(uiObj); CUIController uiBase = (CUIController)uiObj.AddComponent(openState.UIType); openState.UIWindow = uiBase; uiBase.UIName = uiBase.UITemplateName = openState.Name; InitWindow(openState, uiBase, openState.OpenWhenFinish, openState.OpenArgs); OnUIWindowLoaded(openState, uiBase); }
void OnDynamicWindowCallback(CUIController _ui, object[] _args) { string template = (string)_args[0]; string name = (string)_args[1]; GameObject uiObj = (GameObject)UnityEngine.Object.Instantiate(_ui.gameObject); uiObj.name = name; UiBridge.UIObjectFilter(uiObj); CUIController uiBase = uiObj.GetComponent <CUIController>(); uiBase.UITemplateName = template; uiBase.UIName = name; CUILoadState _instanceUIState = UIWindows[name]; _instanceUIState.IsLoading = false; _instanceUIState.UIWindow = uiBase; object[] originArgs = new object[_args.Length - 2]; // 去除前2个参数 for (int i = 2; i < _args.Length; i++) { originArgs[i - 2] = _args[i]; } InitWindow(_instanceUIState, uiBase, true, originArgs); OnUIWindowLoaded(_instanceUIState, uiBase); }
void InitWindow(CUILoadState uiState, CUIController uiBase, bool open, params object[] args) { uiBase.OnInit(); if (OnInitEvent != null) { OnInitEvent(uiBase); } if (open) { OnOpen(uiState, args); uiBase.gameObject.SetActive(true); } else { if (!uiState.IsStaticUI) { CloseWindow(uiBase.UIName); // Destroy } else { uiBase.gameObject.SetActive(false); } } OnUIWindowLoadedCallbacks(uiState, uiBase); }
void OnOpen(CUILoadState uiState, params object[] args) { if (uiState.IsLoading) { uiState.OpenWhenFinish = true; uiState.OpenArgs = args; return; } CUIController uiBase = uiState.UIWindow; Action doOpenAction = () => { if (uiBase.gameObject.activeSelf) { uiBase.OnClose(); } uiBase.gameObject.SetActive(true); uiBase.OnOpen(args); if (OnOpenEvent != null) { OnOpenEvent(uiBase); } }; doOpenAction(); }
/// <summary> /// // Dynamic动态窗口,复制基准面板 /// </summary> public void OpenDynamicWindow(string template, string name, params object[] args) { CUILoadState uiState = _GetUIState(name); if (uiState != null) { OnOpen(uiState, args); return; } CallUI(template, (_ui, _args) => { // _args useless CUILoadState uiInstanceState; CUILoadState uiTemplateState = _GetUIState(template); if (!UIWindows.TryGetValue(name, out uiInstanceState)) // 实例创建 { uiInstanceState = new CUILoadState(template); uiInstanceState.IsStaticUI = false; uiInstanceState.IsLoading = true; uiInstanceState.UIWindow = null; UIWindows[name] = uiInstanceState; } // 组合template和name的参数 和args外部参数 object[] totalArgs = new object[args.Length + 2]; totalArgs[0] = template; totalArgs[1] = name; args.CopyTo(totalArgs, 2); OnDynamicWindowCallback(uiTemplateState.UIWindow, totalArgs); }); }
void InitWindow(CUILoadState uiState, CUIController uiBase, bool open, params object[] args) { uiBase.OnInit(); if (open) { OnOpen(uiState, args); uiBase.gameObject.SetActive(true); } }
public IEnumerator LoadUIAsset(CUILoadState loadState, UILoadRequest request) { string path = string.Format("ui/{0}.prefab{1}", loadState.TemplateName, KEngine.AppEngine.GetConfig("KEngine", "AssetBundleExt")); var assetLoader = KStaticAssetLoader.Load(path); loadState.UIResourceLoader = assetLoader; // 基本不用手工释放的 while (!assetLoader.IsCompleted) yield return null; request.Asset = assetLoader.TheAsset; }
void OnUIWindowLoaded(CUILoadState uiState, CUIController uiBase) { //if (openState.OpenWhenFinish) // 加载完打开 模式下,打开时执行回调 { while (uiState.CallbacksWhenFinish.Count > 0) { Action <CUIController, object[]> callback = uiState.CallbacksWhenFinish.Dequeue(); object[] _args = uiState.CallbacksArgsWhenFinish.Dequeue(); callback(uiBase, _args); } } }
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; }
/// <summary> /// 等待并获取UI实例,执行callback /// 源起Loadindg UI, 在加载过程中,进度条设置方法会失效 /// /// 如果是DynamicWindow,,使用前务必先要Open! /// </summary> /// <param name="uiTemplateName"></param> /// <param name="callback"></param> /// <param name="args"></param> public void CallUI(string uiTemplateName, Action <CUIController, object[]> callback, params object[] args) { CDebug.Assert(callback); CUILoadState uiState; if (!UIWindows.TryGetValue(uiTemplateName, out uiState)) { uiState = LoadWindow(uiTemplateName, false); // 加载,这样就有UIState了, 但注意因为没参数,不要随意执行OnOpen } CUILoadState openState = UIWindows[uiTemplateName]; openState.DoCallback(callback, args); }
/// <summary> /// DynamicWindow专用, 不会自动加载,会提示报错 /// </summary> /// <param name="uiName"></param> /// <param name="callback"></param> /// <param name="args"></param> public void CallDynamicUI(string uiName, Action <CUIController, object[]> callback, params object[] args) { CDebug.Assert(callback); CUILoadState uiState; if (!UIWindows.TryGetValue(uiName, out uiState)) { CDebug.LogError("找不到UIState: {0}", uiName); return; } CUILoadState openState = UIWindows[uiName]; openState.DoCallback(callback, args); }
void OnOpen(CUILoadState uiState, params object[] args) { if (OpenWindowEvent != null) { OpenWindowEvent(uiState.UIType); } CUIController uiBase = uiState.UIWindow; uiBase.OnPreOpen(); if (uiBase.gameObject.activeSelf) { uiBase.OnClose(); } else { uiBase.gameObject.SetActive(true); } uiBase.OnOpen(args); }
/// <summary> /// 等待并获取UI实例,执行callback /// 源起Loadindg UI, 在加载过程中,进度条设置方法会失效 /// </summary> /// <param name="uiName"></param> /// <param name="callback"></param> /// <param name="args"></param> public void CallUI(string uiName, Action <CUIController, object[]> callback, params object[] args) { CBase.Assert(callback); CUILoadState uiState; if (!UIWindows.TryGetValue(uiName, out uiState)) { uiState = LoadWindow(uiName, false); // 加载,这样就有UIState了 } if (uiState.IsLoading) // Loading { CUILoadState openState = UIWindows[uiName]; openState.CallbacksWhenFinish.Enqueue(callback); openState.CallbacksArgsWhenFinish.Enqueue(args); return; } callback(uiState.UIWindow, args); }
public CUILoadState LoadWindow(string name, bool openWhenFinish, params object[] args) { if (UIWindows.ContainsKey(name)) { CBase.LogError("[LoadWindow]多次重复LoadWindow: {0}", name); } CBase.Assert(!UIWindows.ContainsKey(name)); string path = string.Format("UI/{0}_UI{1}", name, CCosmosEngine.GetConfig("AssetBundleExt")); CUILoadState openState = new CUILoadState(name); openState.IsStaticUI = true; openState.OpenArgs = args; openState.OpenWhenFinish = openWhenFinish; CResourceManager.Instance.StartCoroutine(LoadUIAssetBundle(path, name, openState)); UIWindows.Add(name, openState); return(openState); }
public IEnumerator LoadUIAsset(CUILoadState openState, UILoadRequest request) { var name = openState.TemplateName; // 具体加载逻辑 // manifest string manifestPath = ResourceDepUtils.GetBuildPath(string.Format("BundleResources/NGUI/{0}.prefab.manifest{1}", name, AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt))); var manifestLoader = KBytesLoader.Load(manifestPath, KResourceInAppPathType.PersistentAssetsPath, KAssetBundleLoaderMode.PersitentDataPathSync); while (!manifestLoader.IsCompleted) { yield return(null); } var manifestBytes = manifestLoader.Bytes; manifestLoader.Release(); // 释放掉文本字节 var utf8NoBom = new UTF8Encoding(false); var manifestList = utf8NoBom.GetString(manifestBytes).Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < manifestList.Length; i++) { var depPath = manifestList[i] + AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt); var depLoader = KAssetFileLoader.Load(depPath); while (!depLoader.IsCompleted) { yield return(null); } } string path = ResourceDepUtils.GetBuildPath(string.Format("BundleResources/NGUI/{0}.prefab{1}", name, KEngine.AppEngine.GetConfig("AssetBundleExt"))); var assetLoader = KStaticAssetLoader.Load(path); openState.UIResourceLoader = assetLoader; // 基本不用手工释放的 while (!assetLoader.IsCompleted) { yield return(null); } request.Asset = assetLoader.TheAsset; }
public CUILoadState LoadWindow(string windowTemplateName, bool openWhenFinish, params object[] args) { if (UIWindows.ContainsKey(windowTemplateName)) { Logger.LogError("[LoadWindow]多次重复LoadWindow: {0}", windowTemplateName); } Logger.Assert(!UIWindows.ContainsKey(windowTemplateName)); string path = string.Format("UI/{0}_UI{1}", windowTemplateName, KEngine.AppEngine.GetConfig("AssetBundleExt")); CUILoadState openState = new CUILoadState(windowTemplateName, windowTemplateName); openState.IsStaticUI = true; openState.OpenArgs = args; //if (openState.IsLoading) openState.OpenWhenFinish = openWhenFinish; KResourceModule.Instance.StartCoroutine(LoadUIAssetBundle(path, windowTemplateName, openState)); UIWindows.Add(windowTemplateName, openState); return(openState); }
public IEnumerator LoadUIAsset(CUILoadState openState, UILoadRequest request) { var name = openState.TemplateName; // 具体加载逻辑 // manifest string manifestPath = ResourceDepUtils.GetBuildPath(string.Format("BundleResources/NGUI/{0}.prefab.manifest{1}", name, AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt))); var manifestLoader = KBytesLoader.Load(manifestPath, KResourceInAppPathType.PersistentAssetsPath, KAssetBundleLoaderMode.PersitentDataPathSync); while (!manifestLoader.IsCompleted) yield return null; var manifestBytes = manifestLoader.Bytes; manifestLoader.Release(); // 释放掉文本字节 var utf8NoBom = new UTF8Encoding(false); var manifestList = utf8NoBom.GetString(manifestBytes).Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < manifestList.Length; i++) { var depPath = manifestList[i] + AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt); var depLoader = KAssetFileLoader.Load(depPath); while (!depLoader.IsCompleted) { yield return null; } } string path = ResourceDepUtils.GetBuildPath(string.Format("BundleResources/NGUI/{0}.prefab{1}", name, KEngine.AppEngine.GetConfig("AssetBundleExt"))); var assetLoader = KStaticAssetLoader.Load(path); openState.UIResourceLoader = assetLoader; // 基本不用手工释放的 while (!assetLoader.IsCompleted) yield return null; request.Asset = assetLoader.TheAsset; }