unity热更新json_unity下 behaviac 如果xml要做热更新该怎么做

我们是一般打包时 仍旧放在Resources下,

思路就是:重载 behaviac.FileManager、先去找热更目录有没有这个xml, 有就加载外部文件,没有就直接按原来方式去Resources目录加载。

public class MyBehaviacFileManager : behaviac.FileManager

{

public override byte[] FileOpen(string filePath, string ext)

{

bool in_out = false; //这个有点鸡肋

//思路:检测热更目录下是否有对应文件,存在则优先读取, 否则仍旧读取Resources

int k0 = filePath.IndexOf("Resources");

if (k0 != -1)

{

//根据传过来的路径,计算出我们在热更目录下的相对路径。

string filePathInResources = filePath.Substring(k0);

string fileOutPath = filePathInResources + ext;

fileOutPath = fileOutPath.ToLower();

if (FileHelper.CheckResInPersistentData(fileOutPath)) //封装的 检查安卓、ios热更外部目录的函数

{

try

{

string file_name = FileHelper.GetResInPersistentDataPath(fileOutPath); //封装的检查安卓、ios热更外部目录的文件全路径函数

byte[] buffer = CUtility.GetBinaryFileBuffer(file_name); //文件读取成字节数组(安卓有些不一样,所以统一封装了一个接口)

in_out = true;

return buffer;

}

catch (System.Exception e)

{

Log.Error("LoadJsonFile ({0}) failed, error({1})", fileOutPath, e.ToString());

}

}

}

if (!in_out)

{

return base.FileOpen(filePath, ext); //外部xml等文件不存在,就走默认基类的加载

}

else

{

return null;

}

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值