Recommended reading:
flow chart
First, roughly rendered the execution order for everyone to use the framework of a flow chart. See the code in order to facilitate comparison, the flowchart is a function name of the method used, the method is right next to the corresponding script file name; the implementation of the script on the right side three points of the code sequence of the flowchart.
Project logical analysis
For easy viewing, where the C # scripts and Lua scripts are open, take a look at the logical framework, I chose sublime and VS editor to open the lua and C # code, respectively.
1, first open SimpleFramework_UGUI-0.4.1 \ Assets \ Examples \ Scenes \ Login scene, in addition to travel with camera endures, there is an empty object called GlobalGenerator, and hanging above the amount called GlobalGenerator.cs script, can conceivable GlobalGenerator.cs think our game is the entry function:
by comments can determine the exact game entrance AppFacade.Instance.StartUp ();
2, F12 to enter the StartUp view function specific definition, F12 to enter SendMessageCommand, there are ways to define SendMessageCommand , there are defined RegisterCommand methods.
理解了SendMessageCommand和RegisterCommand方法,从下图中我们就能理解代码的意思了,首先为NotiConst.START_UP注册了一个StartUpCommand类型的命令,然后在StartUp函数中发送了NotiConst.START_UP命令,目的是执行操作。
3、F12进入StartUpCommand中
图中的操作是为GlobalGenerator游戏物体添加AppView脚本组件,然后为其添加一系列的管理器脚本。这里我们主要分析GameManager脚本。
4、OnResourceInited函数的作用。
上面代码首先执行了Network,lua和GameManager.lua脚本。
接着调用了CallMethod,我们使用F12一直追踪,定位到如下函数:
通过这个函数分析发现:object[] panels = CallMethod(“LuaScriptPanel”);这句代码是在执行logic\GameManager.lua中的LuaScriptPanel方法,因此,我们又转到GameManager.lua中,分析LuaScriptPanel方法的作用:
结合GameManager.c和上面的代码可以看出,这里返回的是需要加载的场景面板对应的名字数组,但是统一去掉了面板名字的Panel字段,因为在C#下面的代码中查找时自动添加了该字段。
由上图我们可以看出获取到面板名字后又执行了View下对应名字的lua代码:
执行完所有的View下对应的name+Panel.lua代码,程序又回到了C#代码,此时C#代码又执行了OnInitOK,该方法位于GameManager.lua下
Remove some network connection operation, and performs a two Awake method, the tracked startCtrl.lua:
Here Awake createPanel method performed in PanelManager.cs:
createPanel method of opening a HS to instantiate a panel, and the installation position of the parent node and so on.
When then instantiate the object and set back the completion of lua code callback method OnCreate, add a click event to the panel assembly