implementation: Create a UI panel using Simpleframework to implement hot update
Note: The article uses the Ugui frame 1. Download Frame
Ulua Official Address: http://www.ulua.org/
Simpleframework Ugui GitHub Address: https://github.com/jarjin/SimpleFramework_UGUI/
After the download is completed for the project file, can be directly used by the Unity Open, directory structure as shown below:
Examples/scenes file decentralized for hot Update sample project, Ulua/examples folder for Ulua Syntax Tutorial Example 2. New Scene Create a new scene that you want to test creating a panel that requires hot updates prefab Create a new gameobject Add Global Generator Script Component
Hierarchy Panel directory structure:
Note: The UI panel that requires a hot update ends with the "panel" name 3. Packaging Files
Package the Textframepanel preform into the Textframe.assetbundle
Click Lua/gen Lua Wrap files in the menu bar, and if the build succeeds in seeing many of the parcel files under the Ulua/source/luawrap folder, the files are not there originally.
If you modify the C # class registered in Lua, you need to clear the file cache and regenerate it. Click Lua/clear luabinder File + Wrap files and then take the second step
Click the game/build XXX Resources Packaging Resource file in the menu bar
Successful packaging generates the Streamingassets folder in the project folder, and the directory structure is as follows:
Note: For my packaged files in the red box, other resource files packaged for the sample project if Android is the target platform, you need to switch the platform in build settings to Android and then regenerate the package
If the following error occurs after the package file is generated:
Assets/source/luawrap/xxxwrap.cs (218,21): Error Cs1061:type unityengine.xxx ' does not contain a definition forxxx ' and no Extension method xxx ' of typeunityengine.xxx ' could is found (are you missing a using directive or a assembly? )
The official solution: because unity different platform version API is not the same, so not particularly unified, encountered this problem directly delete the error code. 4. Modify C # script 1.panelmanager.cs
Transform Parent {Get
{
if (Parent = null) {
Gameobject go = Gameobject.findwithtag ("Canvas");//The original label is " Guicamera "
If" (Go!= null) parent = Go.transform;
}
return parent;
}
Because my textframepanel is placed directly under the Canvas, and the original frame is placed under the Guicamera, so I added Canvas a "Canvas" label as the parent object of the panel. 2.appview.cs
void Ongui () {
GUI. Label (New Rect (x, 960, M), message);
Gui. Label (New Rect (10, 0, 500, 50), (1) click \ lua/gen Lua Wrap files\. ");
Gui. Label (New Rect (10, 20, 500, 50), "(2) Running Unity Game");
Gui. Label (new Rect), PS: Clear cache, click \ lua/clear luabinder File + Wrap files\. ");
Gui. Label (new Rect, 900,), PS: If you run to the real machine, please set the const.debugmode=false, local debugging please set Const.debugmode=true ");
Gui. Label (New Rect, "PS: Add Unity+ulua Technical Discussion Group: >>341746602");
}
These are information about the framework, which can be modified or deleted by itself 3.appconst.cs
Public const BOOL DebugMode = FALSE; Debug mode-For internal testing, default to TRUE public
const BOOL UpdateMode = TRUE; Update mode-default to False public
const string weburl = "http://192.168.3.9:6688/"; Test update address, default to localhost
192.168.3.9-bit native IP address 4.httpserver.cs
Modify the server-side host address from the frame, that is, the HttpServer.cs in Server/server.sln
public httpserver (int port) {
host = ' http://192.168.3.9:6688/';
}
5. Modify LUA Scripts
1. Open the project folder
Here you can use sublime Text File/open folder to open the Lua folders in the frame to see the folder structure clearly.
But the first time you open it will also display all the. meta file, which is more chaotic, you can refer to this to screen specific file types 2. Function call Order
GameManager.cs
///<summary>///resource initialization end///</summary> public void
Onresourceinited () {Luamanager.start (); Luamanager.dofile ("Logic/network"); Load game luamanager.dofile ("Logic/gamemanager");
Load Network Initialize = TRUE; Netmanager.oninit ();
Initialize network object[] panels = Callmethod ("Luascriptpanel"); ---------------------Lua Panel---------------------------foreach (Object o in panels) {string Name = O.tostring ().
Trim (); if (string.
IsNullOrEmpty (name)) continue; name = = "Panel";
Add Luamanager.dofile ("view/" + name);
Debug.logwarning ("Loadlua---->>>>" + name + ". Lua"); }//------------------------------------------------------------Callmethod ("Oninitok"); Initialization complete}
You can see from the above that the sequence of calls to the LUA function is
Gamemanager.luascriptpanel ()-->view/textframepanel.lua-->gamemanager.oninitok ()
Here is the control over to the Lua file 3.logic/gamemanger.lua
Require "Common/define"
require "Controller/textframectrl"
gamemanager={} Local This
= Gamemanager
function Gamemanager.luascriptpanel () return
' TextFrame '
end
function Gamemanager.oninitok ()
Appconst.socketport =
appconst.socketaddress = "127.0.0.1"
netmanager:sendconnect ()
Textframectrl.awake ()
warn ("Simpleframework start!");
End
4.view/textframepanel.lua
Local Transform local
gameobject
textframepanel = {};
Local this = Textframepanel;
function Textframepanel.awake (obj)-
-body
gameobject = obj
transform = obj.transform this
. Initpanel ()
end
function Textframepanel.initpanel ()
--Test hot update text
this.textshow = transform: Findchild ("Bg/text"). Gameobject;
End
5.controller/textframectrl.lua
Require "Common/define" local
label local TextFrame local transform local
gameobject
Textframectrl = {} Local this
= Textframectrl
function textframectrl.new ()
End
function textframectrl.awake ()
--The body
panelmanager:createpanel ("TextFrame", this. OnCreate);--Create panel, call callback function end
--Start Event--
function textframectrl.oncreate (obj)-
-
body Gameobject = obj
transform = obj.transform
label = TextFramePanel.textshow:GetComponent ("Text")
Label.text = "Oh, come on man!"
End
6. Start Server Test
1.Build android apk
When the server is not open, open apk the following figure:
2. Start the server
Administrator-initiated server\server\bin\debug under SuperSocket.SocketService.exe
Show diagram after startup:
Restart apk at this point:
Ok.
If the update fails you can test whether the phone can connect to the computer's host port, that is, enter the native IP in the browser: port number
For example: 192.168.3.9:6688 input can show the following figure is connected successfully
If you are not connected, try the following methods:
http://jingyan.baidu.com/article/67508eb4dc85e79cca1ce48f.html 7. Thermal Update Test
Update: Modify the text in the textbox to "update Complete" and delete the picture in the middle of the panel
1. Modify Controller/textframectrl.lua
--Start Event-
function textframectrl.oncreate (obj)-
-body
gameobject = obj
transform = obj.transform
label = TextFramePanel.textshow:GetComponent ("Text")
Label.text = "Update Complete" End
2. Modification of Textframepanel prefabricated bodies
Delete the pictures in the preform as follows:
Then rebuild Android Resource, reboot the Android client:
Finish.