最后添加一下Addressable资源服务器ip 地址的动态修改,以及xluahotFix 的使用:
分享一下个人Demo工程:https://github.com/IsaWinding/AddressableXluaFramework.git
希望大家多多点赞,谢谢
有些包可能涉及到母包出很多渠道包,有些渠道可能会布置和维护自己的资源服务器,那么就必修动态修改自己的资源服务器地址了
建议新的ip 地址通过其他信息后台获取后设置更改
- 动态修改Addressable资源服务器地址:
private bool useNewIp = false;
private string resServerOriIp = "192.168.1.126";//资源服务器的初始测试地址
private string resServerNewIp = "192.168.1.27";//不同分包设置的不同资源服务器地址
void Start()
{
Addressables.InternalIdTransformFunc = InternalIdTransformFunc;
UpdateCatalog();
}
private string InternalIdTransformFunc(UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation location)
{
//判定是否是一个AB包的请求
if (location.Data is AssetBundleRequestOptions)
{
//PrimaryKey是AB包的名字
//path就是StreamingAssets/Bundles/AB包名.bundle,其中Bundles是自定义文件夹名字,发布应用程序时,复制的目录
string InternalId_ = location.InternalId;
if (useNewIp && InternalId_.Contains(resServerOriIp))
{
//Debug.LogError("InternalId_" + InternalId_);
InternalId_ = InternalId_.Replace(resServerOriIp, resServerNewIp);
}
//Debug.LogError("InternalId_"+ InternalId_);
return InternalId_;
}
else
{
string InternalId_ = location.InternalId;
if (useNewIp && InternalId_.Contains(resServerOriIp))
{
//Debug.LogError("InternalId_" + InternalId_);
InternalId_ = InternalId_.Replace(resServerOriIp,resServerNewIp);
}
return InternalId_;
}
}
- xlua 的hotfixMap
hotFixMap 设计在lua启动的时候,立即进行hofFix列表修复
GameStartUp.Lua
require("Core")
hofFixMap.StartLoadFix()
Core .lua
print("core>>")
Vector3 = CS.UnityEngine.Vector3
require("Core.class")
require("Core.hofFixMap")
hofFixMap.lua
---@class hofFixMap
hofFixMap = {}
hofFixMap.StartLoadFix = function()
xlua.hotfix(CS.LuaHelper, 'Test', function(a)
print("HotFix cs LuaHelper Test function")
end)
xlua.hotfix(CS.LoginPanel, 'OnForward', function(self)
self.gameObject.transform.localPosition = Vector3(7,8,9)
print("HotFix cs LoginPanel OnInit function")
end)
end
修复后运行正常的游戏逻辑
GameStartUp.Lua
require("Core")
hofFixMap.StartLoadFix()
CS.LuaHelper.Test(function()
print("CS.LuaHelper.UpdateNes ???? 2021_12_06 01:12:12")
end)
CS.UICtrlManager.OpenLoginPanel()
其中的两处修复都被正常执行:
1.修复了静态方法CS 的LuaHelper静态方法Test
using XLua;
[LuaCallCSharp]
[Hotfix]
public static class LuaHelper
{
[Hotfix]
public static void Test(System.Action pAc)
{
//Debug.LogError("LuaHelper Test");
pAc.Invoke();
}
}
修复为:
xlua.hotfix(CS.LuaHelper, 'Test', function(a)
print("HotFix cs LuaHelper Test function")
end)
- 还有是热修复登录界面的界面位置:
xlua.hotfix(CS.LoginPanel, 'OnForward', function(self)
self.gameObject.transform.localPosition = Vector3(7,8,9)
print("HotFix cs LoginPanel OnInit function")
end)
上面就是这次热修复和资源服务器地址动态修改的内容