/// <summary> /// 打印当前TImage图集使用信息 /// </summary> public void printTImageInfo() { DIYLog.Log($"AtlasName = {AtlasName} SpriteName = {SpriteName}"); var refcount = ABI != null?ABI.RefCount.ToString() : "无"; DIYLog.Log($"AtlasName引用计数 = {refcount}"); }
/// <summary> /// 播放背景音乐 /// </summary> public void onPlayBGM() { DIYLog.Log("onPlayBGM()"); if (mBGMAudioSource != null) { //背景音效是挂载GameLaucher上会导致永远无法满足卸载条件,所以需要手动移除对象绑定 if (mCurrentBGMARI != null) { mCurrentBGMARI.releaseOwner(mBGMAudioSource); } mRMM.requstResource("backgroundmusic", (ari) => { mCurrentBGMARI = ari; var clip = ari.getAsset <AudioClip>(mBGMAudioSource, "backgroundmusic"); mBGMAudioSource.clip = clip; mBGMAudioSource.loop = true; mBGMAudioSource.Play(); }); } else { DIYLog.LogError("背景音乐组件为空,无法播放!"); } }
private void resourceHotUpdate() { //不需要强更走后判定资源热更流程 if (HotUpdateModuleManager.Singleton.checkResourceHotUpdate(HotUpdateModuleManager.Singleton.ServerVersionConfig.ResourceVersionCode)) { //单独开启一个携程打印强更进度 StartCoroutine(printVersionHotUpdateProgressCoroutine()); HotUpdateModuleManager.Singleton.doResourceHotUpdate( HotUpdateModuleManager.Singleton.ServerVersionConfig.ResourceVersionCode, (resourcehotupdateresult) => { if (resourcehotupdateresult) { DIYLog.Log("资源热更完成!请重进或重新触发热更流程!"); return; } else { DIYLog.Log("资源热更出错!"); return; } } ); } else { DIYLog.Log("无需资源热更,可以直接进入游戏!"); } }
/// <summary> /// 存储最新版本信息 /// </summary> public void saveNewVersionInfo() { DIYLog.Log("saveNewVersionInfo()"); var param1 = InputParam1.text; DIYLog.Log("Param1 = " + param1); var param2 = InputParam2.text; DIYLog.Log("Param2 = " + param2); double newversioncode = 0.0f; int newresourceversioncode = 0; if (double.TryParse(param1, out newversioncode)) { if (int.TryParse(param2, out newresourceversioncode)) { VersionConfigModuleManager.Singleton.saveNewVersionCodeOuterConfig(newversioncode); VersionConfigModuleManager.Singleton.saveNewResoueceCodeOuterConfig(newresourceversioncode); } else { DIYLog.LogError("新资源版本号解析出错!"); } } else { DIYLog.LogError("新版本号解析出错!"); } }
/// <summary> /// 播放背景音乐 /// </summary> public void onPlayBGM() { DIYLog.Log("onPlayBGM()"); AudioManager.Singleton.playBGM("Assets/Res/audios/music/backgroundmusic"); //if (mBGMAudioSource != null) //{ // //背景音效是挂载GameLaucher上会导致永远无法满足卸载条件,所以需要手动移除对象绑定 // if (mCurrentBGMARI != null) // { // mCurrentBGMARI.releaseOwner(mBGMAudioSource); // } // mRMM.requstResource("backgroundmusic", // (ari) => // { // mCurrentBGMARI = ari; // var clip = ari.getAsset<AudioClip>(mBGMAudioSource, "backgroundmusic"); // mBGMAudioSource.clip = clip; // mBGMAudioSource.loop = true; // mBGMAudioSource.Play(); // }); //} //else //{ // DIYLog.LogError("背景音乐组件为空,无法播放!"); //} }
/// <summary> /// 打印所有表格数据 /// </summary> public void printAllExcellData() { DIYLog.Log("printAllExcellData()"); var languagelist = GameDataManager.Singleton.t_languagecontainer.getList(); foreach (var language in languagelist) { DIYLog.Log("----------------------------------------------"); DIYLog.Log(string.Format("language id : {0}", language.id)); DIYLog.Log(string.Format("language content : {0}", language.content)); } var authorlist = GameDataManager.Singleton.t_author_Infocontainer.getList(); foreach (var author in authorlist) { DIYLog.Log("----------------------------------------------"); DIYLog.Log(string.Format("author id : {0}", author.id)); DIYLog.Log(string.Format("author author : {0}", author.author)); DIYLog.Log(string.Format("author age : {0}", author.age)); DIYLog.Log(string.Format("author national : {0}", author.national)); DIYLog.Log(string.Format("author sex : {0}", author.sex)); } var globallist = GameDataManager.Singleton.t_globalcontainer.getList(); foreach (var global in globallist) { DIYLog.Log("----------------------------------------------"); DIYLog.Log(string.Format("global id : {0}", global.id)); DIYLog.Log(string.Format("global intvalue : {0}", global.intvalue)); DIYLog.Log(string.Format("global stringvalue : {0}", global.stringvalue)); DIYLog.Log(string.Format("global floatvalue : {0}", global.floatvalue)); DIYLog.Log(string.Format("global intarrayvalue : {0}", global.intarrayvalue.ToString())); DIYLog.Log(string.Format("global stringarrayvalue : {0}", global.stringarrayvalue.ToString())); } }
/// <summary> /// 任务请求携程 /// </summary> /// <returns></returns> private IEnumerator requestCoroutine() { mIsInProgress = true; while (mWebRequestTaskQueue.Count > 0) { var task = mWebRequestTaskQueue.Dequeue(); DIYLog.Log(string.Format("下载资源 : {0}", task.URL)); var webrequest = UnityWebRequest.Get(task.URL); webrequest.timeout = task.TimeOut; yield return(webrequest.SendWebRequest()); if (webrequest.isNetworkError) { DIYLog.LogError(string.Format("{0}资源下载出错!", task.URL)); DIYLog.LogError(webrequest.error); if (webrequest.isHttpError) { DIYLog.LogError(string.Format("responseCode : ", webrequest.responseCode)); } task.CompleteCallback(task.URL, WebRequestStatus.WRP_Faield); } else { DIYLog.Log(string.Format("{0} webrequest.isDone:{1}!", task.URL, webrequest.isDone)); DIYLog.Log(string.Format("{0}资源下载完成!", task.URL)); task.CompleteCallback(task.URL, WebRequestStatus.WRP_Faield); } } }
/// <summary> /// Editor模式下,找回MeshRender & SkinMeshRender的Shader显示 /// </summary> /// <param name="go"></param> public static void FindMeshRenderShaderBack(GameObject go) { #if UNITY_EDITOR var skinmeshrenders = go.GetComponentsInChildren <SkinnedMeshRenderer>(); foreach (var skr in skinmeshrenders) { var mts = skr.materials; foreach (var mt in mts) { if (mt.shader != null) { mt.shader = Shader.Find(mt.shader.name); } } } var meshrenders = go.GetComponentsInChildren <MeshRenderer>(); foreach (var mr in meshrenders) { var mts = mr.materials; foreach (var mt in mts) { if (mt.shader != null) { mt.shader = Shader.Find(mt.shader.name); DIYLog.Log(string.Format("{0}对象找回Shader:{1}显示!", go.name, mt.shader.name)); } } } #endif }
/// <summary> /// 测试热更新完整流程 /// </summary> public void testHotUpdateFullWorkFlow() { DIYLog.Log("testHotUpdateFullWorkFlow()"); VersionConfigModuleManager.Singleton.initVerisonConfigData(); //检测是否强更过版本 HotUpdateModuleManager.Singleton.checkHasVersionHotUpdate(); //TODO: //拉去服务器列表信息(网络那一套待开发,暂时用本地默认数值测试) if (HotUpdateModuleManager.Singleton.checkVersionHotUpdate(HotUpdateModuleManager.Singleton.ServerVersionConfig.VersionCode)) { HotUpdateModuleManager.Singleton.doNewVersionHotUpdate( HotUpdateModuleManager.Singleton.ServerVersionConfig.VersionCode, (versionhotupdateresult) => { if (versionhotupdateresult) { DIYLog.Log("版本强更完成!触发自动安装!"); #if UNITY_ANDROID (NativeManager.Singleton as AndroidNativeManager).installAPK(HotUpdateModuleManager.Singleton.VersionHotUpdateCacheFilePath); #endif return; } else { resourceHotUpdate(); } } ); } else { resourceHotUpdate(); } }
/// <summary> /// 尝试进游戏(验证版本强更以及资源热更相关判定) /// </summary> public void tryEnterGame() { DIYLog.Log("tryEnterGame()"); VersionConfigModuleManager.Singleton.initVerisonConfigData(); if (HotUpdateModuleManager.Singleton.HotUpdateSwitch) { if (VersionConfigModuleManager.Singleton.needVersionHotUpdate(HotUpdateModuleManager.Singleton.ServerVersionConfig.VersionCode)) { DIYLog.Log(string.Format("服务器版本号 : {0}高于本地版本号 : {1},需要强更!", HotUpdateModuleManager.Singleton.ServerVersionConfig.VersionCode, VersionConfigModuleManager.Singleton.GameVersionConfig.VersionCode)); DIYLog.Log("不允许进游戏!"); } else { DIYLog.Log(string.Format("服务器版本号 : {0}小于或等于本地版本号 : {1},不需要强更!", HotUpdateModuleManager.Singleton.ServerVersionConfig.VersionCode, VersionConfigModuleManager.Singleton.GameVersionConfig.VersionCode)); if (VersionConfigModuleManager.Singleton.needResourceHotUpdate(HotUpdateModuleManager.Singleton.ServerVersionConfig.ResourceVersionCode)) { DIYLog.Log(string.Format("服务器资源版本号 : {0}大于本地资源版本号 : {1},需要资源热更!", HotUpdateModuleManager.Singleton.ServerVersionConfig.ResourceVersionCode, VersionConfigModuleManager.Singleton.GameVersionConfig.ResourceVersionCode)); DIYLog.Log("不允许进游戏!"); } else { DIYLog.Log(string.Format("服务器资源版本号 : {0}小于或等于本地资源版本号 : {1},不需要资源热更!", HotUpdateModuleManager.Singleton.ServerVersionConfig.ResourceVersionCode, VersionConfigModuleManager.Singleton.GameVersionConfig.ResourceVersionCode)); DIYLog.Log("可以进游戏!"); } } } else { DIYLog.Log("热更开关未打开,不允许热更!"); DIYLog.Log("可以进游戏!"); } }
/// <summary> /// 执行变体搜集 /// </summary> private async Task doShaderVariantsCollectAsync() { Debug.Log("doShaderVariantsCollect()"); ShaderVariantOuputFolderPath = Application.dataPath + ShaderVariantsAssetPath; var outputassetsindex = ShaderVariantOuputFolderPath.IndexOf("Assets"); var outputrelativepath = ShaderVariantOuputFolderPath.Substring(outputassetsindex, ShaderVariantOuputFolderPath.Length - outputassetsindex); var svcoutputfilepath = outputrelativepath + ShaderVariantsAssetFileName; Debug.Log(string.Format("Shader变体文件输出目录:{0}", ShaderVariantOuputFolderPath)); Debug.Log(string.Format("Shader变体文件输出相对路径:{0}", svcoutputfilepath)); if (!Directory.Exists(ShaderVariantOuputFolderPath)) { Debug.Log(string.Format("Shader变体文件输出目录:{0}不存在,重新创建一个!", ShaderVariantOuputFolderPath)); Directory.CreateDirectory(ShaderVariantOuputFolderPath); } EditorSceneManager.SaveOpenScenes(); MethodInfo savecurrentsvc = typeof(ShaderUtil).GetMethod("SaveCurrentShaderVariantCollection", BindingFlags.NonPublic | BindingFlags.Static); savecurrentsvc.Invoke(null, new object[] { svcoutputfilepath }); // 直接设置AB名字和Shader打包到一起 var svcassetimporter = AssetImporter.GetAtPath(svcoutputfilepath); if (svcassetimporter != null) { svcassetimporter.assetBundleName = "shaderlist"; DIYLog.Log(string.Format("设置资源:{0}的AB名字为:shaderlist", svcoutputfilepath)); AssetDatabase.SaveAssets(); } GameObject.DestroyImmediate(SVCCubeParentGo); EditorSceneManager.SaveOpenScenes(); Debug.Log("保存完Shader变体文件!"); await Task.Delay(1000); }
/// <summary> /// 打印当前TImage图集使用信息 /// </summary> public void printTRawImageInfo() { DIYLog.Log($"TextureName = {TextureName}"); var refcount = ABI != null?ABI.RefCount.ToString() : "无"; DIYLog.Log($"TextureName引用计数 = {refcount}"); }
/// <summary> /// 打印所有路径信息 /// </summary> public static void PrintAllPathInfo() { DIYLog.Log(string.Format("ABBuildinPath : {0}", ABBuildinPath)); DIYLog.Log(string.Format("ABHotUpdatePath : {0}", ABHotUpdatePath)); DIYLog.Log(string.Format("DependencyFileName : {0}", DependencyFileName)); DIYLog.Log(string.Format("DependencyAssetName : {0}", DependencyAssetName)); }
/// <summary> /// 设置Image指定图片(从Sprite Atlas里) /// </summary> /// <param name="timg">Image组件</param> /// <param name="atlasname">图集名</param> /// <param name="spritename">图片名</param> /// <param name="loadtype">资源加载类型</param> /// <param name="loadmethod">资源加载方式</param> /// <returns></returns> public void setImageSpriteAtlas(TImage timg, string atlasname, string spritename, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync) { DIYLog.Assert(timg == null, "setImageSpriteAtlas不允许传空TImage!"); ResourceModuleManager.Singleton.requstResource(atlasname, (abi) => { DIYLog.Log("加载SpriteAtlas AB完成!"); // 清除老的资源引用 if (timg.ABI != null) { timg.ABI.releaseOwner(timg); } if (abi != null) { DIYLog.Log("加载SpriteAtlas之前!"); var spriteatlas = abi.getAsset <SpriteAtlas>(timg, atlasname); DIYLog.Log("加载SpriteAtlas之后!"); timg.sprite = spriteatlas.GetSprite(spritename); DIYLog.Log("SpriteAtlas.GetSprite()之后!"); } timg.ABI = abi; timg.AtlasName = atlasname; timg.SpriteName = spritename; }, loadtype, loadmethod); }
/// <summary> /// 资源热更测试 /// </summary> public void testResourceHotUpdate() { DIYLog.Log("testResourceHotUpdate()"); if (HotUpdateModuleManager.Singleton.checkResourceHotUpdate(HotUpdateModuleManager.NewHotUpdateResourceCode)) { HotUpdateModuleManager.Singleton.doResourceHotUpdate(HotUpdateModuleManager.NewHotUpdateResourceCode, resourceHotUpdateCompleteCallBack); } }
/// <summary> /// 版本强更测试 /// </summary> public void testVersionwHotUpdate() { DIYLog.Log("testVersionwHotUpdate()"); if (HotUpdateModuleManager.Singleton.checkVersionHotUpdate(HotUpdateModuleManager.NewHotUpdateVersionCode)) { HotUpdateModuleManager.Singleton.doNewVersionHotUpdate(HotUpdateModuleManager.NewHotUpdateVersionCode, versionHotUpdateCompleteCallBack); } }
/// <summary> /// 打印AB依赖信息 /// </summary> public void onPrintABDepInfo() { DIYLog.Log("onPrintABDepInfo()"); if (mRMM.CurrentResourceModule is AssetBundleModule) { (mRMM.CurrentResourceModule as AssetBundleModule).printAllResourceDpInfo(); } }
/// <summary> /// 加载常驻Shader /// </summary> public void onLoadPermanentShaderList() { DIYLog.Log("onLoadPermanentShaderList()"); mRMM.requstResource( "shaderlist", (abi) => { }, ResourceLoadType.PermanentLoad); // Shader常驻 }
/// <summary> /// 加载角色 /// </summary> public void onLoadActorPrefab() { DIYLog.Log("onLoadActorPrefab()"); mRMM.requstResource( "pre_zombunny", (abi) => { mActorInstance = abi.instantiateAsset("pre_Zombunny"); }); }
/// <summary> /// Editor模式下,找回材质Shader显示 /// </summary> /// <param name="go"></param> public static void FindMaterialShaderBack(Material mt) { #if UNITY_EDITOR if (mt.shader != null) { mt.shader = Shader.Find(mt.shader.name); DIYLog.Log(string.Format("{0}材质找回Shader:{1}显示!", mt.name, mt.shader.name)); } #endif }
/// <summary> /// 加载TRawImage /// </summary> public void onLoadTRawImageSprite() { DIYLog.Log("onLoadTRawImageSprite()"); var param1 = InputParam1.text; DIYLog.Log("Param1 = " + param1); TRawImgBG.printTRawImageInfo(); AtlasManager.Singleton.setRawImage(TRawImgBG, param1); TRawImgBG.printTRawImageInfo(); }
/// <summary> /// 加载窗口预制件 /// </summary> public void onLoadWindowPrefab() { DIYLog.Log("onLoadWindowPrefab()"); mRMM.requstResource( "mainwindow", (abi) => { mMainWindow = abi.instantiateAsset("MainWindow"); mMainWindow.transform.SetParent(UIRootCanvas.transform, false); }); }
/// <summary> /// 加载背景TImage Sprite Atlas /// </summary> public void onLoadTImageBGSpriteAtlas() { DIYLog.Log("onLoadTImageBGSpriteAtlas()"); var param1 = InputParam1.text; DIYLog.Log("Param1 = " + param1); var param2 = InputParam2.text; DIYLog.Log("Param2 = " + param2); AtlasManager.Singleton.setImageSpriteAtlas(TImgBG, param1, param2); }
public static void QuickSetABName() { var assetpath = AssetDatabase.GetAssetPath(Selection.activeObject); var assetimporter = AssetImporter.GetAtPath(assetpath); if (assetimporter != null) { assetimporter.assetBundleName = Selection.activeObject.name.ToLower(); DIYLog.Log(string.Format("设置资源:{0}的AB名字为:{1}", assetpath, Selection.activeObject.name.ToLower())); AssetDatabase.SaveAssets(); } }
/// <summary> /// 销毁异步和同步加载 /// </summary> public void onDestroyAsynAndSyncLoad() { DIYLog.Log("onDestroyAsynAndSyncLoad()"); GameObject.Destroy(mMainWindow); mMainWindow = null; GameObject.Destroy(mActorInstance); mActorInstance = null; GameObject.Destroy(mActorInstance2); mActorInstance2 = null; GameObject.Destroy(mSFXInstance); mSFXInstance = null; }
/// <summary> /// 响应SpriteAtlas图集加载回调 /// </summary> /// <param name="atlasname"></param> /// <param name="callback"></param> private void onAtlasRequested(string atlasname, Action <SpriteAtlas> callback) { DIYLog.Log($"加载SpriteAtlas:{atlasname}"); // Later Bind -- 依赖使用SpriteAtlas的加载都会触发这里 ResourceModuleManager.Singleton.requstResource( atlasname, (abi) => { DIYLog.Log($"Later Bind加载SpriteAtlas:{atlasname}"); var sa = abi.loadAsset <SpriteAtlas>(atlasname); callback(sa); }); }
/// <summary> /// 加载Image Sprite /// </summary> public void onLoadImageSprite() { DIYLog.Log("onLoadImageSprite()"); var param1 = InputParam1.text; DIYLog.Log("Param1 = " + param1); var param2 = InputParam2.text; DIYLog.Log("Param2 = " + param2); var image = mMainWindow.transform.Find("imgBG").GetComponent <Image>(); AtlasManager.Singleton.setImageSingleSprite(image, param1); }
/// <summary> /// 打印版本信息 /// </summary> public void printVersionInfo() { DIYLog.Log("printVersionInfo()"); VersionConfigModuleManager.Singleton.initVerisonConfigData(); if (HotUpdateModuleManager.Singleton.ServerVersionConfig != null) { DIYLog.Log($"服务器版本信息:VersionCode:{HotUpdateModuleManager.Singleton.ServerVersionConfig.VersionCode} ResourceVersionCode : {HotUpdateModuleManager.Singleton.ServerVersionConfig.ResourceVersionCode}"); } else { DIYLog.LogError("未获取服务器的版本信息!"); } }
/// <summary> /// 加载角色 /// </summary> public void onLoadActorPrefab() { DIYLog.Log("onLoadActorPrefab()"); ModelManager.Singleton.getModelInstance("Assets/Res/actors/zombunny/pre_Zombunny", (instance) => { mActorInstance = instance; }); //mRMM.requstResource( //"pre_zombunny", //(abi) => //{ // mActorInstance = abi.instantiateAsset("pre_Zombunny"); //}); }
/// <summary> /// 预加载Shader变体 /// </summary> public void onPreloadShaderVariants() { DIYLog.Log("onPreloadShaderVariants()"); // Shader通过预加载ShaderVariantsCollection里指定的Shader来进行预编译 ResourceModuleManager.Singleton.requstResource( "shaderlist", (abi) => { var svc = abi.loadAsset <ShaderVariantCollection>("DIYShaderVariantsCollection"); // Shader通过预加载ShaderVariantsCollection里指定的Shader来进行预编译 svc.WarmUp(); }, ResourceLoadType.PermanentLoad); }