unity Addressable系统及其Xlua脚本热更新全过程详细解析(三)

21 篇文章 1 订阅
17 篇文章 0 订阅

最后添加一下Addressable资源服务器ip 地址的动态修改,以及xluahotFix 的使用:
分享一下个人Demo工程:https://github.com/IsaWinding/AddressableXluaFramework.git
希望大家多多点赞,谢谢
有些包可能涉及到母包出很多渠道包,有些渠道可能会布置和维护自己的资源服务器,那么就必修动态修改自己的资源服务器地址了
建议新的ip 地址通过其他信息后台获取后设置更改

  1. 动态修改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_;
        }
    }
  1. 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)
  1. 还有是热修复登录界面的界面位置:
 xlua.hotfix(CS.LoginPanel, 'OnForward', function(self)
        self.gameObject.transform.localPosition =  Vector3(7,8,9)
        print("HotFix cs LoginPanel  OnInit function")
    end)

上面就是这次热修复和资源服务器地址动态修改的内容

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值