[Unity热更新]tolua# & LuaFramework(十二):基础补充

参考:https://www.zhihu.com/people/pyluo/posts


一.在lua中输出信息:

print("hello ") ;
LuaFramework.Util.Log("World");	

其中Util这个类封装了很多实用的方法供lua调用,值得去看一下~


二.重要的常量

1.Util.AppContentPath():游戏包资源目录。

Mac OS或Windows:Application.dataPath + "/StreamingAssets";
IOS: Application.dataPath + "/Raw";
Android:jar:file://" + Application.dataPath + "!/assets/";

2.Util.DataPath:数据目录。外部路径。

Android或IOS:Application.persistentDataPath + "/LuaFramework"    
Mac OS或Windows:c:/LuaFramework/
调试模式下:Application.dataPath + "/StreamingAssets/"

这里注意的是Application.platform这个东西,在Window的unity编辑器中,输出为RuntimePlatform.WindowsEditor,而不是RuntimePlatform.WindowsPlayer!

Debug.Log(Application.platform);
Debug.Log(Application.platform == RuntimePlatform.WindowsEditor);
Debug.Log(Application.platform == RuntimePlatform.WindowsPlayer);
Debug.Log(Util.DataPath);



3.直接执行lua代码

找到AppConst.LuaBundleMode,如果为true,表示读取AB包内的lua文件,这意味着每次修改lua代码,都要重新build;为了提高效率,可以修改为false,表示直接读取lua文件。


4.从服务器下载东西来更新客户端

找到AppConst.UpdateMode,如果为true,表示将通过服务器更新资源。


三.加载AB包

在AB包的加载方面,NGUI没有使用unity5的新打包方式,并没有处理好依赖关系,而UGUI使用的是新打包方式。因此建议将UGUI版本的ResourceManager替换NGUI版本的。至于LuaFramework中AB包的加载流程,可以看一下http://blog.csdn.net/lyh916/article/details/45021703。


四.常用的内置lua文件

1.LuaFramework\Lua\Common\functions.lua
跟Util一样,也是工具类,提供GameObject相关方法等

2.LuaFramework\ToLua\Lua\event.lua
提供每帧执行的方法
--主入口函数。从这里开始lua逻辑
function Main()									
    UpdateBeat:Add(Update, self)
end
 
function Update()
	Util.Log("Update");
end
除此之外,还有LateUpdateBeat、FixedUpdateBeat和CoUpdateBeat(协同)

3.LuaFramework\ToLua\Lua\UnityEngine
有Vector3.lua、Mathf.lua等


五.常用的内置C#类
1.LuaBehaviour
以例子实例化出来的PromptPanel为例,在Awake和Start中会调用PromptPanel.Awake(obj)和PromptPanel.Start()。



猜你喜欢

转载自blog.csdn.net/lyh916/article/details/52062820