Unity热更新专题(七)SimpleFramework

Unity热更新专题(七)SimpleFramework

我们在上一节中已经导入了SimpleFramework_UGUI-master。我们首先看官方bbs上的一点介绍。

/**********************************************************************************************************************************/

拿到框架与插件,有几个点需要知道:(0)SimpleFramework NGUI/UGUI各版本框架都已经自带集成了最新版的ulua,用户无需导入ulua插件,否则就是多此一举,出现错误。(1)ulua插件最新版1.2.1,没有集成框架的自动wrap功能,也就是你添加了一个自定义的c#,生成wrap以后,需要手动的在lua/system/wrap.lua里面添加一行,再运行,下个版本会集成自动wrap功能。(2)拿到框架,有两个步骤一个是生成wrap,另一个是build资源,一前一后,执行顺序不能颠倒,因为生成wrap的时候会修改项目里的wrap.lua,然后build资源的时候把它一起打包出去,才能生效。(3)视频,ULUA提供的视频,没有提供声音,因为我没麦,它使用的版本是Unity4.6.2跟ulua_v1.16,如果还没搞懂前,必须严格照用同版本,直接用后面版本可能会有报错。(4)关于Luastate跟LuaScriptMgr读取的lua文件路径问题:如果你用Luastate l = new Luastate(); l.DoFile("绝对路径"),如果用LuaScriptMgr mgr; mgr.DoFile("相对路径"),至于相对于谁?在Util类的LuaPath函数内设定。(5)关于使用32位版的用户,把Plugins/x86.zip解压出来,因为Unity5不允许有两个相同的ulua.dll存在,所以提供压缩包,用户自解压。(6)关于框架、插件的部分例子直接运行报错的原因,如果例子中涉及到LuaScriptMgr的类,它是wrap去反射模式,也就是说,需要把自带的lua目录下面的脚本解压到指定目录,才能争取读取,那正确的姿势是:(1)打开login测试场景,运行成功后,再运行例子,原因是login场景会把自己包内的lua脚本解压到指定的数据目录,Windows默认是c://simpleframework下面,而例子里面没有任何释放lua脚本资源的代码,因此在LuaScripgMgr.Start()的时候,找不到lua类。(2)或者,在AppConst.cs里面将DebugMode设置位true,让它自己读取工程目录下的lua类。(7)ulua_v1.03 (支持Unity 4.6.1及其老版本) SimpleFramework NGUI/UGUI 和 ulua_v1.03_with_iOS64_x86到最新版 (支持Unity 4.6.2以上版本)(8)ulua/SimpleFramework NGUI/UGUI版本跟用户自编译的底层库有个很重要的区别,现在我们用的底层库在MAC/iOS平台因为用的是lua原始代码,为了目前应对苹果的arm64的问题,自带的底层库是统一字节码的(用自带的luac编码一次lua文件即可,加载时也不需要区分32bit/64bit),而且优化了luac编码出来的尺寸大小,,甚至还带了自加密功能,不区分平台。但是,用户自编译的底层库需要用户区分32bit/64bit的luac编译出来的字节码,没有优化字节码及其加密功能,或者用户有能力可以自己做这部分。原因我们也不是故意不开源,因为目前盗掘猖獗,我们为了保护大家的知识劳动成功别被第三次无耻偷取,所以临时闭源,择时公开。所以是选择自己编译底层库还是直接选用我们自带的功能,需要提前考虑清楚。(9)如果你在Bindlua.cs里面更改、删除了某些不需要注册进lua的类,在Clear完了,ulua会编译一些引用脚本,一定要等编译的菊花转完,再重新生成,否则会有更改无效的情况出现,切记等菊花转完。

(链接:)

/**********************************************************************************************************************************/

挑几段好看的代码看看:

1、HelloWorldusing UnityEngine;using System.Collections;using LuaInterface;public class HelloWorld : MonoBehaviour {// Use this for initializationvoid Start () {LuaState l = new LuaState();string str = "print('hello world 世界')";l.DoString(str);}// Update is called once per framevoid Update () {}}2、CreateGameObjectusing UnityEngine;using System.Collections;using LuaInterface;public class CreateGameObject01 : MonoBehaviour {private string script = @"luanet.load_assembly('UnityEngine')GameObject = luanet.import_type('UnityEngine.GameObject')ParticleSystem = luanet.import_type('UnityEngine.ParticleSystem')local newGameObj = GameObject('NewObj')newGameObj:AddComponent(luanet.ctype(ParticleSystem))";//反射调用void Start () {LuaState lua = new LuaState();lua.DoString(script);}// Update is called once per framevoid Update () {}}using UnityEngine;using System.Collections;using LuaInterface;public class CreateGameObject02 : MonoBehaviour {private string script = @"luanet.load_assembly('UnityEngine')GameObject = UnityEngine.GameObjectParticleSystem = UnityEngine.ParticleSystemlocal newGameObj = GameObject('NewObj')newGameObj:AddComponent(ParticleSystem.GetClassType())";//非反射调用void Start () {LuaScriptMgr lua = new LuaScriptMgr();lua.Start();lua.DoString(script);}// Update is called once per framevoid Update () {}}3、CallLuaFunctionusing UnityEngine;using System.Collections;using LuaInterface;public class CallLuaFunction_01 : MonoBehaviour {private string script = @"function luaFunc(message)print(message)return 42end";// Use this for initializationvoid Start () {LuaState l = new LuaState();// First run the script so the function is createdl.DoString(script);// Get the function objectLuaFunction f = l.GetFunction("luaFunc");// Call it, takes a variable number of object parameters and attempts to interpet them appropriatelyobject[] r = f.Call("I called a lua function!");// Lua functions can have variable returns, so we again store those as a C# object array, and in this case print the first oneprint(r[0]);}// Update is called once per framevoid Update () {}}4、LuaClassusing UnityEngine;using System.Collections;public class LuaClass : MonoBehaviour {const string source = @"Account = { balance = 0 };function Account:new(o)o = o or {};setmetatable(o, { __index = self });return o;endfunction Account.deposit(self, v)self.balance = self.balance + v;endfunction Account:withdraw(v)if (v) > self.balance then error 'insufficient funds'; endself.balance = self.balance – v;endSpecialAccount = Account:new();function SpecialAccount:withdraw(v)if v – self.balance >= self:getLimit() thenerror 'insufficient funds';endself.balance = self.balance – v;endfunction SpecialAccount.getLimit(self)return self.limit or 0;ends = SpecialAccount:new{ limit = 1000 };print(s.balance);s:deposit(100.00);print (s.limit);print (s.getLimit(s))print (s.balance)";// Use this for initializationvoid Start () {LuaScriptMgr mgr = new LuaScriptMgr();mgr.Start();mgr.lua.DoString(source);}// Update is called once per framevoid Update () {}}具体点Demo可以自己慢慢看。

就不多介绍了。

我们下一节就自己动手来做一个UGUI的实例吧。

===================================================================================

结束。

版权声明:本文为博主原创文章,未经博主允许,随便转载。

如果发现错了,一定要止步.

Unity热更新专题(七)SimpleFramework

相关文章:

你感兴趣的文章:

标签云: