Experience the hot update under the ToLua framework (Phpstudy)

one. Detailed process of hot update

  1. First we need to open the local computer as a server, this is the first step

1.1.1 How to determine that our computer is turned on as a server.

We open a browser and enter 127.0.0.1 in the address bar. Or localhost if it is not a link and cannot be linked

As shown below:                                  

 

                                  Figure 1

1.1.2 If the link fails unfortunately, download the IIS installation and enable the related services. But here is another method. We download PHPStudy (software) and install it until the last run and start up. The following figure shows Apache and MySQL both showing green.

 

 

         At this point, when we link 127.0.0.1 again, the interface shown in Figure 1 will appear. At this time, our server is set up.

  1. The second step is to download our ToLua framework. The download address is as follows: https://github.com/jarjin/LuaFramework_UGUI 

   We download the framework of ToLua here. It is a project (compressed package). We can see its file structure in the project as shown in the figure:

 

Here we open the main scene in the Scenes folder and run it, as shown in the figure:

 

  Figure 2 The author has made a small change here, and the script on the empty object can be hung up

The picture shows the result of our operation. Note that the name of the empty object GameManager in this scene cannot be changed. When running the scene, there is only one script on the space-time object, and the code in this Main script is also extremely simple.

 public class Main : MonoBehaviour {

 

        void Start() {

            AppFacade.Instance.StartUp(); //Start the game

        }

}

There is only a simple sentence, we will not do further research here. The AppFacade class is a singleton, which encapsulates some methods. StartUp is to automatically hang some scripts on our GameManager empty object after opening our framework. We will not discuss it here.

  1. Some special classes in the ToLua framework

The LuaManager class is very important, and the InitStart method in it is to start the Lua virtual machine (which can be considered as a startup

move Lua)

 

In the LuaState class to control the state of Lua, we can use this class to run a piece of Lua code (DoString method) in C# or execute the specified Lua code (Dofile (this is the path to a Lua file))

Lualooper controls the loop of the entire Lua framework

GameManager: Here are some controls as shown in the figure

Here I enter the initialization of the project. At the beginning, we only need to enter InitStart and set initialize to true

Unnecessary is not executed and loaded here

      Appconst: The control class of the entire framework configures the framework here

 

 UpdateMode is set to False when the server is not updated (you can set it to False when testing). After the game is online, it must be set to true. If it is changed to true, the following url will be used to update it. If it is false, it will be used locally. renew

      LuaBundleMode: Controls whether Lua code needs to be packaged Lua code needs to be packaged every time it is modified

      

Remember these classes

  1. Hot update (preparation):

After installing PhpStudy, we will have such a discovery. There is such a folder WWW folder in our PhpStudy installation folder. The resources to be updated in our project are placed here (server). Then we open our project ( A copy of the packaged) StreamingAssets folder is placed here: as shown in the figure (please pay attention to this path)

Open the browser and enter the address http://127.0.0.1/StreamingAssets/files.txt, then we can see the result of this operation: Please remember this access path

 

   Figure 3

The content in Figure 3 is the content in our files.txt. When using the framework for hot update, the system will download the files.txt on the server and compare it with the local one, and the inconsistent content will be downloaded (UpdateMode is set to true)

After that, we open the main.lua in the server and take a look (this information is saved in the www folder)

--The main entry function. start lua logic from here

function Main()

print("logic start")

 

print("This is a new Lua statement")

print("I'm new here")  

--print("I'm really new here") these two sentences will not be executed

--print("I'm also new here") These two sentences will not be executed

end

 

--Scene switch notification

function OnLevelWasLoaded(level)

collectgarbage("collect")

Time.timeSinceLevelLoad = 0

end

 

function OnApplicationQuit()

end

 

Then we compare our local ones ( the information in the StreamingAssets file of the www file is version 1.0, and the following is version 2.0)

--The main entry function. start lua logic from here

function Main()

print("logic start")

 

print("This is a new Lua statement")

print("I'm new here")  

print("I'm really new") -- will execute

print("I'm also new here")--will execute

end

 

--Scene switch notification

function OnLevelWasLoaded(level)

collectgarbage("collect")

Time.timeSinceLevelLoad = 0

end

 

function OnApplicationQuit()

end

     This is the difference between a resource on a local and a server

5. Hot Update (Running)

Let's run the results of the local update first ( UpdateMode set to false)

Remember the content packaging of version 2.0

The running result is shown in the figure. All four statements are output. At this time, this is a local update (the server can only output two statements)

 

 

            Figure 4

After that, we will do the server-side update. We open the APPConst file as shown in the figure:

 

At this time, the UpdateMode in the figure is set to true (updated from the server) and the webUrl (update path) below is changed to the path in red before everyone remembers (slightly different, see the picture), save and run. The result is shown in the figure:

 

The resources on the server only output two sentences (different from the local running results of the above programmers)

                                                               ------- Baixiaolinghu

Phpstudy download address: http://rj.baidu.com/soft/detail/17836.html?ald

This thing can be searched on Baidu

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324938016&siteId=291194637
Recommended