Unity 3D Gaming Client Base Framework Tolua Framework Access

Source: Internet
Author: User

Tags: blog direct ACL master property ATI Auto Generate notification inheritance

How do I access the Tolua framework to the Unity project, where we already have a project and have implemented some infrastructure or projects that are already complete, and how do I access the Tolua this hot update framework without affecting the structure of the original project? Tolua introduced:1. Resource download: Since you are introducing Tolua into the project, the first step must be to first download the Tolua resource bundle to the Tolua GitHub repository: Tolua-Master.zip2. Resource ingestion: Unzip the downloaded resource to see the approximate directory structure as follows:|--Luajit64tolua-Master|--Assets|--Luajit|--Luajit64|--projectsettings|--unity5.x So many folders, that's what we really need, copy all the files under the Assets folder to the Assets directory of our project, because I'm using Unity5.5.1f1, so you'll need to unity5.x/assets/The Plugins folder is also copied to the Assets directory of our project and merged with the replacement. 3. Other: After the Unity editor imports the new resources in the directory, a pop-up window prompts "Click OK to automatically generate common type registration files, or through the menu to complete this function", here directly click "OK". Lua starting point: There are many practical examples in the Tolua\examples directory, which is very helpful for newcomers who are just getting started, and we will go directly into the application practice of the formal project. A LuaClient.cs is provided in the Tolua\misc, this is Tolua provides us with a packaged boot interface that can be inherited by this class to write our project's Tolua Manager, where I create a LuaEngine.cs, inherited from Luaclie NT and rewrite two interfaces: Initloader and Loadluafiles: Modify directories to search LUA files///</summary>    protected Override voidLoadluafiles () {usingSystem.Collections;usingSystem.Collections.Generic;usingLuainterface;usingUnityengine;///<summary>///Tolua starts the portal, dynamically binds the script to a gameobject that is not destroyed, and is usually tied to the same object as the Gamemanagr of the game.///</summary> Public classluaengine:luaclient {protected Overrideluafileutils Initloader () {return NewLuaresloader (); }    ///<summary> ///directories to search for LUA files can be added or modified///</summary>    protected Override voidLoadluafiles () {#ifUnity_editor//to get the path to the Lua script in an editor environment (Assets/lua)Luastate.addsearchpath (Application.datapath"/lua");#endifonloadfinished (); This script is started in the awake method of the Game Control Center script Gamemanager (which is bound to a gameobject in the game start scene, usually an Empty gameobject):usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine; Public classGamemanager:monobehaviour {Private StaticGamemanager _instance =NULL; PrivateLuaengine _luaengine;  Public StaticGamemanager Instance {Get{return_instance;} }    voidAwake () {_instance= This; //set to toggle the properties of the scene not being destroyedgameobject.dontdestroyonload (Gameobject);    Init (); }    ///<summary> ///initialization steps for the game manager///</summary>    voidInit () {_luaengine= gameobject.addcomponent< luaengine> (); }} to execute the boot scenario, you can see the final output: [Main.lua:3]:logic StartUnityEngine.Debug:Log (Object) This is Assets ./lua/Main.lua Print, this script is the starting point for all LUA logic:--The main entry function. Starting from here, the LUA logic function Main () print ("Logic Start") End--scene Toggle notification function onlevelwasloaded (level) CollectGarbage ("Collect") Time.timesincelevelload=0End directory structure optimization: After importing Tolua resources, the resources in the Assets directory are somewhat cluttered and miscellaneous, so it is necessary to optimize some of the directory structures of Tolua based on the original structure of the project:1.*Wrap.cs directory: Assets/source/generate is the binding class used to hold Tolua generated C # classes that can be called by Lua, but in my project, I habitually put the script in the Assets/scripts directory, so here we just need to open the assets/editor/ custom/CustomSettings.cs, modify the content: Public Static stringSavedir = Application.datapath"/scripts/generate/"; Then the Source/luaconst.cs move to the Assets/scripts/framework/tolua directory, create a Generate directory in Scripts, turn off Unity on reboot, and then pop up a window prompt like the one that just introduced Tolua "click Determine the automatic generation of common types of registration files, you can also step through the menu to complete the function ", this is also directly click" OK ". At this point, the assets/scripts/generate will generate a heap of *Wrap.cs script file that indicates that the directory modification was successful. But at this time there will be duplicate files, the entire Source directory must be deleted. 2. Tolua Directory: Assets/tolua directory is the core of the Tolua framework of some of the library, of course, according to the rules of our project; externally introduced third-party plug-in resources are mainly placed in assets/ThirdParty directory, here we move the entire Tolua directory directly to the third-party plug-in directory, and then need to modify several places: LuaConst.cs in Toluadir: Public Static stringToluadir = Application.datapath"/thirdparty/tolua/lua";//tolua Lua file directoryCustomSettings.cs in the Toluabasetype: Public Static stringToluabasetype = Application.datapath"/thirdparty/tolua/basetype/", completed the above two settings and completed the modification of the directory. 

Unity 3D Gaming Client Base Framework Tolua Framework Access

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: