/// <summary> /// 加载窗口 /// </summary> /// <param name="uiIndexs">窗口枚举</param> public void LoadWindows(params int[] uiIndexs) { foreach (var index in uiIndexs) { if (windowMap.ContainsKey(index)) { var uvalue = windowMap[index]; if (uvalue.IsLoad) { BDebug.Log("已经加载过并未卸载" + index, "red"); } } else { //创建ui var window = CreateWindow(index); if (window == null) { BDebug.Log("不存在UI:" + index, "red"); } else { windowMap[index] = window; System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); window.Load(); window.Transform.SetParent(this.Bottom, false); watch.Stop(); BDebug.LogFormat("加载{0},耗时: {1}ms", index, watch.ElapsedMilliseconds); PushCaheData(index); } } } }
/// <summary> /// 异步加载窗口 /// </summary> /// <param name="indexes"></param> /// <param name="loadProcessAction"></param> public void AsyncLoadWindows(List <int> indexes, Action <int, int> loadProcessAction) { int allCount = indexes.Count; int curTaskCount = 0; foreach (var i in indexes) { var index = i.GetHashCode(); if (windowMap.ContainsKey(index)) { var uvalue = windowMap[index]; if (uvalue.IsLoad) { Debug.LogError("已经加载过并未卸载" + index); //任务直接完成 { curTaskCount++; loadProcessAction(allCount, curTaskCount); } continue; } } else { //创建窗口 var win = CreateWindow(index); if (win == null) { Debug.LogErrorFormat("不存在UI:{0}", index); } else { windowMap[index] = win; //开始窗口加载 System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); win.AsyncLoad(() => { watch.Stop(); BDebug.LogFormat("加载{0},耗时: {1}ms", index, watch.ElapsedMilliseconds); curTaskCount++; loadProcessAction(allCount, curTaskCount); win.Transform.SetParent(this.Bottom, false); //推送缓存的数据 PushCaheData(index); }); } } } }
private void btn_04() { //测试多个接口 var list = new List <int>() { (int)WinEnum.Win_UFlux }; UIManager.Inst.AsyncLoadWindows(list, (i, j) => { //log BDebug.LogFormat("加载进度:{0}-{1}", i, j); UIManager.Inst.ShowWindow(WinEnum.Win_UFlux); }); }
/// <summary> /// 技能攻击 /// </summary> /// <param name="_params"></param> private void OnUseSkill(List <object> _params) { if (IsPlaySkill) { BDebug.LogError("正在播放技能,操作无效!"); return; } IsPlaySkill = true; //0 : 攻击者下标 //1 : 作用者下标 //2 : 技能id skillTargetId = (int)_params[1]; CurSkillId = (int)_params[2]; BDebug.LogFormat("{0}对{1}释放技能{2}", (int)_params[0], (int)_params[1], (int)_params[2]); var skill = this.HeroLogic.UseSkill(CurSkillId); CurSkillBlockState = -1; curPlaySkillBlocks = SqliteHelper.DB.GetTable <Skillblock>().Where((sb) => skill.SkillBlocks.Contains(sb.Id)).ToList(); if (curPlaySkillBlocks.Count == 0) { BDebug.LogError("当前skill无block , skill id:" + CurSkillId); } /******注册渲染层事件*****/ //渲染层通知:播放block this.HeroGraphic.SkillPlayer.State.RegAction("DoBlockEvent", o => { BDebug.Log("执行事件"); DoBlockEvent((List <SkillEvent>)o); }); //渲染层通知: this.HeroGraphic.SkillPlayer.State.RegAction("CurBlockEnd", o => { BDebug.Log(string.Format("播放block:{0} 结束", CurSkillBlockState)); DoPlayNextBlock(); }); // this.HeroGraphic.SkillPlayer.State.RegAction("AllBlockEnd", o => { BDebug.Log("当前所有block播放完毕~"); AllBlockEnd(); }); DoPlayNextBlock(); }
static StackObject *LogFormat_3(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Object[] @args = (System.Object[]) typeof(System.Object[]).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.String @format = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); BDebug.LogFormat(@format, @args); return(__ret); }
private void PushCaheData(int uiIndex) { // return; //检查ui数据缓存 List <WindowData> cacheList = null; uiDataCacheMap.TryGetValue(uiIndex, out cacheList); if (cacheList != null) { for (int i = 0; i < cacheList.Count; i++) { var data = cacheList[i]; windowMap[uiIndex].SendMessage(data); BDebug.Log("push cache data " + uiIndex); } cacheList.Clear(); BDebug.LogFormat("推送数据:{0} ,{1}条", uiIndex, cacheList.Count); } }
/// <summary> /// 核心功能,所有任务靠这个推进度 /// 执行下个任务 /// </summary> void DoNextTask() { if (this.allTaskGroupList.Count == 0) { return; } //当前任务组执行完毕,执行下一个 if ((curDoTask == null || curDoTask.IsComplete) && this.allTaskGroupList.Count > 0) { curDoTask = this.allTaskGroupList[0]; this.allTaskGroupList.RemoveAt(0); var item = config.Manifest.GetManifestItemByHash(curDoTask.MainAsset); BDebug.LogFormat(">>>>任务组|id:{0} 任务数:{1} - {2}", curDoTask.Id, curDoTask.TaskQueueNum, item.Name); //开始task curDoTask.DoNextTask(); //注册完成回调 curDoTask.onTaskCompleteCallback += (a, b) => { DoNextTask(); }; } }
/// <summary> /// 核心功能,所有任务靠这个推进度 /// 执行下个任务 /// </summary> void DoNextTask() { if (this.allTaskGroupList.Count == 0) { return; } //当前任务组执行完毕,执行下一个 if ((curDoTask == null || curDoTask.IsComplete) && this.allTaskGroupList.Count > 0) { curDoTask = this.allTaskGroupList[0]; this.allTaskGroupList.RemoveAt(0); BDebug.LogFormat(">>>>任务组|id:{1} count:{0} mainasset:{2}", curDoTask.TaskQueueNum, curDoTask.Id, curDoTask.MainAsset); //开始task curDoTask.DoNextTask(); //注册完成回调 curDoTask.onTaskCompleteCallback += (a, b) => { DoNextTask(); }; } }
public override void Init() { base.Init(); //增加覆盖测试 var service = DataListenerServer.Create(nameof(DataListenerEnum)); service.AddListener(DataListenerEnum.test, (o) => { Debug.Log(o.ToString()); }); //demo1: screenview 切换 //代码: //Game@hotfix/demo1 this.btn_01.onClick.AddListener(() => { ScreenViewManager.Inst.MainLayer.BeginNavTo(ScreenViewEnum.Demo1); }); //demo4 : uflux窗口 //代码: this.btn_04.onClick.AddListener(() => { //测试多个接口 var list = new List <int>() { (int)WinEnum.Win_Demo6 }; UIManager.Inst.AsyncLoadWindows(list, (i, j) => { //log BDebug.LogFormat("加载进度:{0}-{1}", i, j); }); UIManager.Inst.ShowWindow(WinEnum.Win_Demo6); BDebug.Log("加载成功!"); // }); //demo5: sqlite 查询 this.btn_05.onClick.AddListener(() => { //单条件查询 Debug.Log("普通查询:"); var ds = SqliteHelper.DB.GetTableRuntime().Where("id = 1").ToSearch <Hero>(); ds = SqliteHelper.DB.GetTableRuntime().Where("id = {0}", 1).ToSearch <Hero>(); foreach (var d in ds) { Debug.Log(JsonMapper.ToJson(d)); } //多条件查询 Debug.Log("OR And查询:"); ds = SqliteHelper.DB.GetTableRuntime().Where("id > 1").And.Where("id < 3").ToSearch <Hero>(); foreach (var d in ds) { Debug.Log(JsonMapper.ToJson(d)); } ds = SqliteHelper.DB.GetTableRuntime().Where("id = 1").Or.Where("id = 3").ToSearch <Hero>(); foreach (var d in ds) { Debug.Log(JsonMapper.ToJson(d)); } //批量查询 Debug.Log("Where or 批量查询:"); ds = SqliteHelper.DB.GetTableRuntime().WhereAnd("id", "=", 1, 2).ToSearch <Hero>(); foreach (var d in ds) { Debug.Log(JsonMapper.ToJson(d)); } //批量查询 Debug.Log("Where and 批量查询:"); ds = SqliteHelper.DB.GetTableRuntime().WhereOr("id", "=", 2, 3).ToSearch <Hero>(); foreach (var d in ds) { Debug.Log(JsonMapper.ToJson(d)); } }); //demo6:资源加载 this.btn_06.onClick.AddListener(() => { List <GameObject> golist = new List <GameObject>(); //1.同步加载 var go = BResources.Load <GameObject>("AssetTest/Cube"); var load1 = GameObject.Instantiate(go); go = BResources.Load <GameObject>("Test/Cube"); var load2 = GameObject.Instantiate(go); go = BResources.Load <GameObject>("AssetTest/Particle"); var load3 = GameObject.Instantiate(go); golist.Add(load1); golist.Add(load2); golist.Add(load3); //2.异步加载单个 var id = BResources.AsyncLoad <GameObject>("Test/Cube", (o) => { var load4 = GameObject.Instantiate(o); golist.Add(load4); }); //3.异步加载多个 var list = new List <string>() { "AssetTest/Cube", "Test/Cube" }; BResources.AsyncLoad(list, (i, i2) => { Debug.Log(string.Format("进度 {0} / {1}", i, i2)); }, (map) => { BDebug.Log("加载全部完成,资源列表:"); foreach (var r in map) { BDebug.Log(string.Format("--> {0} : {1}", r.Key, r.Value.name)); var _go = GameObject.Instantiate(r.Value) as GameObject; golist.Add(_go); } }); IEnumeratorTool.WaitingForExec(5, () => { foreach (var _go in golist) { GameObject.Destroy(_go); } }); }); //代码: //Game@hotfix/demo_Manager_AutoRegister_And_Event this.btn_07.onClick.AddListener(() => { var path = Application.persistentDataPath; VersionContorller.Start(UpdateMode.Repair, "http://127.0.0.1", path, (i, j) => { Debug.LogFormat("资源更新进度:{0}/{1}", i, j); }, (error) => { Debug.LogError("错误:" + error); }); }); //发送消息机制 this.btn_08.onClick.AddListener(() => { DemoEventManager.Inst.Do(DemoEventEnum.TestEvent2); }); //图集 this.btn_09.onClick.AddListener(() => { UIManager.Inst.CloseWindow(WinEnum.Win_Main); UIManager.Inst.LoadWindow(WinEnum.Win_Demo5_Atlas); UIManager.Inst.ShowWindow(WinEnum.Win_Demo5_Atlas); }); //数据监听 this.btn_10.onClick.AddListener(() => { UIManager.Inst.LoadWindow(WinEnum.Win_Demo_Datalistener); UIManager.Inst.ShowWindow(WinEnum.Win_Demo_Datalistener); }); }
/// <summary> /// 加载接口 /// </summary> /// <param name="configPath"></param> /// <param name="onLoaded"></param> public void Load(string configPath, string assetTypePath) { //资源类型配置 if (!string.IsNullOrEmpty(assetTypePath) && File.Exists(assetTypePath)) { var content = File.ReadAllText(assetTypePath); // var list = CsvSerializer.DeserializeFromString<List<string>>(content); // var wlist = new List<AssetTypes>() // { // new AssetTypes() // { // AssetTypeList = list, // } // }; // var str = CsvSerializer.SerializeToCsv(wlist); // File.WriteAllText(assetTypePath, str); // // // content = File.ReadAllText(assetTypePath); var records = CsvSerializer.DeserializeFromString <List <AssetTypeConfig> >(content); this.AssetTypes = records[0]; //创建不同类型的映射表 foreach (var assetType in this.AssetTypes.AssetTypeList) { this.assetTypeIdxMap[assetType] = new LoadPathIdxMap(); } } else { BDebug.LogError("配置文件不存在:" + configPath); } //资源配置 if (!string.IsNullOrEmpty(configPath) && File.Exists(configPath)) { this.configPath = configPath; #if UNITY_EDITOR Stopwatch sw = new Stopwatch(); sw.Start(); #endif var content = File.ReadAllText(configPath); this.AssetbundleItemList = CsvSerializer.DeserializeFromString <List <AssetBundleItem> >(content); #if UNITY_EDITOR sw.Stop(); BDebug.LogFormat("【AssetbundleV2】加载Config耗时{0}ms!", sw.ElapsedTicks / 10000L); #endif foreach (var abItem in this.AssetbundleItemList) { //可以被加载的资源 if (!string.IsNullOrEmpty(abItem.LoadPath) && this.AssetTypes != null) { var assettype = this.AssetTypes.AssetTypeList[abItem.AssetType]; var map = this.assetTypeIdxMap[assettype]; map[abItem.LoadPath] = abItem.Id; } } } else { BDebug.LogError("配置文件不存在:" + configPath); } //初始化常用资源类型 // if (this.AssetTypes != null) // { // //Prefab // var clsName = typeof(GameObject).FullName; // AssetType.VALID_TYPE_PREFAB = this.AssetTypes.AssetTypeList.FindIndex((at) => at.Equals(clsName, StringComparison.OrdinalIgnoreCase)); // //图集 // clsName = typeof(SpriteAtlas).FullName; // AssetType.VALID_TYPE_SPRITE_ATLAS = this.AssetTypes.AssetTypeList.FindIndex((at) => at.Equals(clsName, StringComparison.OrdinalIgnoreCase)); // //... // //其他省略,需要时候再加 // } BDebug.Log("【AssetbundleV2】资源加载初始化完成,资源总量:" + this.AssetbundleItemList?.Count); }
/// <summary> /// 执行加载 Assetbundle /// </summary> /// <returns>是否继续执行</returns> private bool DoLoadAssetBundle() { //有加载任务或者任务未完成 if (loaderHandleList.Count > 0 || taskQueue.Count > 0) { //1.循环添加任务 while (taskQueue.Count > 0 && loaderHandleList.Count < ASYNC_TASK_NUM) { var task = taskQueue.Dequeue(); //没有被加载过 if (!loder.AssetbundleMap.ContainsKey(task.AssetBundleItem.AssetBundlePath)) { //判断是否在加载中 var loderHandle = AssetBundleMgrV2.GetLoaderHandle(task.AssetBundleItem.AssetBundlePath); // AB_LOAD_LOCK_MAP.TryGetValue(, out var exsitLoadingStatus); if (loderHandle != null) { loaderHandleList.Add(new KeyValuePair <string, AssetBundleCreateRequest>(task.AssetBundleItem.AssetBundlePath, loderHandle)); } else { //开始加载逻辑 var filePath = loder.FindMultiAddressAsset(task.AssetBundleItem.AssetBundlePath); //加载偏移 var abcr = AssetBundle.LoadFromFileAsync(filePath, 0, (ulong)task.AssetBundleItem.Mix); //添加到loding表 AssetBundleMgrV2.LockLoadAssetBundle(task.AssetBundleItem.AssetBundlePath, abcr); //添加到状态表 loaderHandleList.Add(new KeyValuePair <string, AssetBundleCreateRequest>(task.AssetBundleItem.AssetBundlePath, abcr)); } } else { BDebug.Log("【AsyncLoadTaskGroup】--> 已存在depend:" + task.AssetBundleItem); } } //2.检测加载状态 for (int i = loaderHandleList.Count - 1; i >= 0; i--) { var item = loaderHandleList[i]; var assetbundlePath = item.Key; var abcr = item.Value; //判断是否成功 if (abcr.isDone) { //添加到返回列表 if (abcr.assetBundle != null) { loder.AddAssetBundle(assetbundlePath, abcr.assetBundle); } else { BDebug.LogError("【LoadGroup】ab资源为空:" + assetbundlePath); } //移除列表 loaderHandleList.RemoveAt(i); //解锁 AssetBundleMgrV2.UnLockLoadAssetBundle(assetbundlePath); BDebug.Log("【AsyncLoadTaskGroup】--> depend:" + assetbundlePath); } } BDebug.LogFormat("【AsyncLoadTaskGroup】剩余未完成任务:{0} - frame: {1}", loaderHandleList.Count + taskQueue.Count, Time.renderedFrameCount); } else { this.isCompleteLoad = true; //加载完成,主资源只要保证在 实例化之前加载完毕即可 if (!isCancel) { this.OnAllTaskCompleteCallback?.Invoke(this.AssetBundleItem.LoadPath); } } //是否继续执行 return(!this.IsSuccess); }