Unity3d hot update book-script (iv) use C # lightedevil to build the script framework used for actual development

Source: Internet
Author: User

C # lightedevil provides many examples of integration with unity, all of which use the method of placing script files in streamingassets.

In this way, the CS files in this directory can be compiled by the compiler, and we will use the C # compiler to verify our scripts.

At the same time, files in streamingassets are directly released with the project, so these script files can be taken out directly for compilation and execution as files.

This is a clever method, but there are some problems in actual projects:

I. It may confuse programmers, where is scripts and where is programs.

2. There will be an unused code in the main program

Iii. directly compiling script files is a little slow, which is obvious on mobile phones, especially when there are many script files.

 

In the face of these three problems, we can solve them all at once.

Our mode is as follows:

1. Create an independent C # project with only script code.

2. When this project is compiled, the script code is precompiled and saved as a binary file.

3. Load the binary file initialization script directly in the main program to continue with the subsequent tasks.

The new example of cslightstudio \ unity \ frameworkmaster on GitHub (https://github.com/lightszero/CSLightStudio) is the framework

As it is abstract, let's introduce it.

The bin directory is the final result of generation. There are two main programs and two script binary files.

The main program is in the Unity directory, and mode1 and mode2 are exported in two scenarios respectively.

Mode1script and mode2script are two script file projects. They are two leleexe files. After compiling and executing them from vs, all the files in your project will be compiled as C # light.

And output it to The./bin/file. csledll. bytes under the bin.

In this way, the separate compilation of the script file and the main unity project is completed. If the script has an error, the console will provide information.

Script Compilation: Create a script project through vs, compile the verification script, and generate a binary file.

Program Compilation: Compile the Output Using unity.

This way

1. scripts and programs are completely isolated from different projects. Script programmers write scripts. programmers of the main program write the main program and perform their respective duties.

2. In addition, the script program will not appear in the main program.

3. The saved binary file is the result of lexical processing, which is lightning loaded on the mobile phone.

 

Maybe you have already discovered a problem. The main program needs to register the types of script calls, and many other classes are self-compiled, without this information, the script cannot perform compilation verification.

Yes, this will take advantage of another feature of Unity. If the unity project code is compiled with vs or monodevelop, a DLL will be generated, although Unity does not need it.

We only need to let the script project reference this DLL and initialize the script engine in the same way as the main program, so that we can get the same script compiling environment as the main program for processing.

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.