一.在lua中输出信息:
[csharp] view plain copy
1. print("hello ") ;
2. LuaFramework.Util.Log("World");
其中Util这个类封装了很多实用的方法供lua调用,值得去看一下~
二.重要的常量
1.Util.AppContentPath():游戏包资源目录。
[csharp] view plain copy
1. Mac OS或Windows:Application.dataPath + "/StreamingAssets";
2. IOS: Application.dataPath + "/Raw";
3. Android:jar:file://" + Application.dataPath + "!/assets/";
2.Util.DataPath:数据目录。外部路径。
[csharp] view plain copy
1. Android或IOS:Application.persistentDataPath + "/LuaFramework"
2. Mac OS或Windows:c:/LuaFramework/
3. 调试模式下:Application.dataPath + "/StreamingAssets/"
这里注意的是Application.platform这个东西,在Window的unity编辑器中,输出为RuntimePlatform.WindowsEditor,而不是RuntimePlatform.WindowsPlayer!
[csharp] view plain copy
1. Debug.Log(Application.platform);
2. Debug.Log(Application.platform == RuntimePlatform.WindowsEditor);
3. Debug.Log(Application.platform == RuntimePlatform.WindowsPlayer);
4. 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
提供每帧执行的方法
[csharp] view plain copy
1. --主入口函数。从这里开始lua逻辑
2. function Main()
3. UpdateBeat:Add(Update, self)
4. end
5.
6. function Update()
7. Util.Log("Update");
8. end
除此之外,还有LateUpdateBeat、FixedUpdateBeat和CoUpdateBeat(协同)
3.LuaFramework\ToLua\Lua\UnityEngine
有Vector3.lua、Mathf.lua等
五.常用的内置C#类
1.LuaBehaviour
以例子实例化出来的PromptPanel为例,在Awake和Start中会调用PromptPanel.Awake(obj)和PromptPanel.Start()。