/// <summary> /// 打印AB依赖信息 /// </summary> public void onPrintABDepInfo() { DIYLog.Log("onPrintABDepInfo()"); if (mRMM.CurrentResourceModule is AssetBundleModule) { (mRMM.CurrentResourceModule as AssetBundleModule).printAllResourceDpInfo(); } }
/// <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> /// 加载常驻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> /// 加载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> /// 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> /// 加载窗口预制件 /// </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); }
/// <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; }
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> /// 响应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> /// 预加载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); }
/// <summary> /// 自动设置指定对象AssetBundle名 /// </summary> /// <param name="obj"></param> /// <param name="abname">指定AB名字,为空表示使用Asset自身名字小写作为AB名字</param> public static void AutoSetAssetBundleName(Object obj, string abname = "") { if (obj != null) { var assetpath = AssetDatabase.GetAssetPath(obj); var assetimporter = AssetImporter.GetAtPath(assetpath); if (assetimporter != null) { var newabname = string.IsNullOrEmpty(abname) ? obj.name.ToLower() : abname; assetimporter.assetBundleName = newabname; DIYLog.Log(string.Format("设置资源:{0}的AB名字为:{1}", assetpath, newabname)); } } }
/// <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> /// 设置Image指定图片(单图的时候) /// </summary> /// <param name="img">Image组件</param> /// <param name="spritepath">Sprite路径</param> /// <param name="loadtype">资源加载类型</param> /// <param name="loadmethod">资源加载方式</param> /// <returns></returns> public void setImageSingleSprite(Image img, string spritepath, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync) { DIYLog.Assert(img == null, "setImageSingleSprite!"); ResourceModuleManager.Singleton.requstResource(spritepath, (abi) => { // Sprite统一为小写 var spritename = Path.GetFileNameWithoutExtension(spritepath).ToLower(); var sprite = abi.getAsset <Sprite>(img, spritename); img.sprite = sprite; }, loadtype, loadmethod); }
/// <summary> /// 预加载图集资源 /// </summary> public void onPreloadAtlas() { DIYLog.Log("onPreloadAtlas()"); var param1 = InputParam1.text; DIYLog.Log("Param1 = " + param1); mRMM.requstResource( param1, (abi) => { abi.loadAllAsset <Sprite>(); }, ResourceLoadType.Preload); }
/// <summary> /// 预加载图集资源 /// </summary> public void onPreloadAtlas() { DIYLog.Log("onPreloadAtlas()"); var param1 = InputParam1.text; DIYLog.Log("Param1 = " + param1); AtlasManager.Singleton.loadAtlas(param1, null, ResourceLoadType.Preload); //mRMM.requstResource( //param1, //(abi) => //{ // abi.loadAllAsset<Sprite>(); //}, //ResourceLoadType.Preload); }
private IEnumerator DoAsyncLoadResource() { yield return(new WaitForEndOfFrame()); //测试异步加载后同步加载同一资源 mRMM.requstResource( "pre_zombunny", (abi) => { mActorInstance2 = abi.instantiateAsset("pre_Zombunny"); }, ResourceLoadType.NormalLoad, ResourceLoadMethod.Sync); DIYLog.Log("actorinstance2.transform.name = " + mActorInstance2.transform.name); }
private IEnumerator DoAsyncLoadResource() { yield return(new WaitForEndOfFrame()); //测试异步加载后同步加载同一资源 ResourceManager.Singleton.getPrefabInstance( "Assets/Res/actors/zombunny/pre_Zombunny", (instance) => { mActorInstance2 = instance; }, ResourceLoadType.NormalLoad, ResourceLoadMethod.Sync); DIYLog.Log("actorinstance2.transform.name = " + mActorInstance2.transform.name); }
/// <summary> /// 加载常驻Shader /// </summary> public void onLoadPermanentShaderList() { DIYLog.Log("onLoadPermanentShaderList()"); ResourceManager.Singleton.loadAllShader("shaderlist", () => { }, ResourceLoadType.PermanentLoad); //mRMM.requstResource( //"shaderlist", //(abi) => //{ // abi.loadAllAsset<Shader>(); //}, //ResourceLoadType.PermanentLoad); // Shader常驻 }
/// <summary> /// 强制卸载指定AB /// </summary> public void forceUnloadSpecificAB() { DIYLog.Log("forceUnloadSpecificAB()"); if (ResourceModuleManager.Singleton.CurrentResourceModule.ResLoadMode == ResourceLoadMode.AssetBundle) { var param1 = InputParam1.text; DIYLog.Log("Param1 = " + param1); var assetbundleresourcemodule = ResourceModuleManager.Singleton.CurrentResourceModule as AssetBundleModule; assetbundleresourcemodule.forceUnloadSpecificResource(param1); } else { DIYLog.Log("未处于AB状态,无法卸载指定AB!"); } }
/// <summary> /// 资源热更测试 /// </summary> public void testResourceHotUpdate() { DIYLog.Log("testResourceHotUpdate()"); if (HotUpdateModuleManager.Singleton.ServerVersionConfig != null) { if (HotUpdateModuleManager.Singleton.checkResourceHotUpdate(HotUpdateModuleManager.Singleton.ServerVersionConfig.ResourceVersionCode)) { HotUpdateModuleManager.Singleton.doResourceHotUpdate(HotUpdateModuleManager.Singleton.ServerVersionConfig.ResourceVersionCode, resourceHotUpdateCompleteCallBack); } } else { DIYLog.LogError("资源热更新前,请先获取服务器版本信息!"); } }
/// <summary> /// 版本强更测试 /// </summary> public void testVersionwHotUpdate() { DIYLog.Log("testVersionwHotUpdate()"); if (HotUpdateModuleManager.Singleton.ServerVersionConfig != null) { if (HotUpdateModuleManager.Singleton.checkVersionHotUpdate(HotUpdateModuleManager.Singleton.ServerVersionConfig.VersionCode)) { HotUpdateModuleManager.Singleton.doNewVersionHotUpdate(HotUpdateModuleManager.Singleton.ServerVersionConfig.VersionCode, versionHotUpdateCompleteCallBack); } } else { DIYLog.LogError("版本强更前,请先获取服务器版本信息!"); } }
/// <summary> /// 切换场景 /// </summary> public void onChangeScene() { DIYLog.Log("onChangeScene()"); var param1 = InputParam1.text; DIYLog.Log("Param1 = " + param1); var param2 = InputParam2.text; DIYLog.Log("Param2 = " + param2); //切换场景前关闭所有打开窗口,测试切场景资源卸载功能 onDestroyWindowInstance(); GameSceneManager.Singleton.loadSceneSync(param1); }
/// <summary> /// 加载窗口预制件 /// </summary> public void onLoadWindowPrefab() { DIYLog.Log("onLoadWindowPrefab()"); ResourceManager.Singleton.getPrefabInstance("Assets/Res/windows/MainWindow", (arg) => { mMainWindow = arg; mMainWindow.transform.SetParent(UIRootCanvas.transform, false); }); //mRMM.requstResource( //"mainwindow", //(abi) => //{ // mMainWindow = abi.instantiateAsset("MainWindow"); // mMainWindow.transform.SetParent(UIRootCanvas.transform, false); //}); }
/// <summary> /// 创建AB资源加载对象 /// </summary> /// <param name="abpath">AB路径</param> /// <returns></returns> private AssetBundleLoader createABLoader(string abpath) { var depabnames = getAssetBundleDpInfo(abpath); var loader = AssetBundleLoaderFactory.create(); loader.AssetBundlePath = abpath; loader.DepABPaths = depabnames; if (depabnames != null) { DIYLog.Log($"{abpath}资源依赖的AB资源如下:"); foreach (var depabname in depabnames) { DIYLog.Log($"{depabname}"); } } return(loader); }
/// <summary> /// 加载材质 /// </summary> public void onLoadMaterial() { DIYLog.Log("onLoadMaterial()"); var btnloadmat = UIRoot.transform.Find("SecondUICanvas/ButtonGroups/btnLoadMaterial"); var image = btnloadmat.GetComponent <Image>(); ResourceManager.Singleton.getMaterial(image, "Assets/Res/sharematerials/sharematerial", (arg) => { Material mat = arg; image.material = mat; //延时测试材质回收 CoroutineManager.Singleton.delayedCall(10.0f, () => { Destroy(mat); }); }); }