Unity3d game project client editor implementation steps

Source: Internet
Author: User
The client editor is mainly used to serialize the configuration file (in Excel format) to generate binary files and load and use them in the game.


I learned how to implement the editor of another project:
1. Use flex to generate a desktop program and use as3xls to Operate Excel to obtain data
2. Generate the frontend VO. CS and corresponding XML and backend files.
3. Generate the C # desktop program
4. Load VO. CS and generate corresponding objects using reflection
5. load XML and set the XML value to the object through reflection
6. Generate a file through serialization

In this way, you need to operate two tools each time you generate the configuration. In my opinion, it is better to directly use the C # desktop program to read excel.
1. Generate a C # desktop program
2. Use oledb to read Excel (C # There are several ways to read excel, Baidu)
3. Generate the VO. CS File
4. Reflection generates VO objects and sets value objects.
5. serialization
Many problems have been encountered during the above steps.
1. Use oledbto read and obtain the Excel file, and upload the. xlsand. XLSX files at the same time:
/// 2003 (Microsoft. Jet. oledb.4.0)
String strconn = string. format ("provider = Microsoft. jet. oledb.4.0; Data Source = {0}; extended properties = 'excel 8.0; HDR = yes; IMEX = 1; '", excelfilepath );
/// 2010 (Microsoft. Ace. oledb.12.0)
String strconn = string. format ("provider = Microsoft. ace. oledb.12.0; Data Source = {0}; extended properties = 'excel 8.0; HDR = yes; IMEX = 1; '", excelfilepath );


2. Create a string to save the VO. CS file, and then use reflection to dynamically create an object based on the string.


Csharpcodeprovider provider = new csharpcodeprovidor (); // create a compiler
Compilerparameters paras = new compilerparameters (); // you can specify compilation parameters.
Paras. referenceassemblies. Add ("system. dll ");
Paras. generateexecutable = false; // compile it into EXE or DLL
Paras. generateinmemory = true; // whether to write data to the memory. Data is written to the disk without writing data to the memory.
Compilerresults result = provider. compileassembleyfromsource (paras, sourcecode (Object string Code); // compile the code
Assembly as = result. compiledassemble; // obtain the compiled assembly
Object OBJ = As. createinstance ("com. Game. VO. voname ");


3. Set the Excel value to OBJ through reflection


4. save the set-value object to arraylist, serialize it, and save it as vo. bytes, Which is saved. bytes is used to load files in Unity (the file extension is ". bytes "is the ending binary data. Unity regards them as textasset .) :
Public byte [] serializebinary (Object Request)
{
System. runtime. serialization. formatters. Binary. binaryformatter serializer = new system. runtime. serialization. formatters. Binary. binaryformatter ();
System. Io. memorystream memstream = new system. Io. memorystream ();
Serializer. serialize (memstream, request );
Return memstream. getbuffer ();
}



5. Put the generated VO. bytes and VO. Cs in the unity3d project.


6. Use unity3d to package the VO. bytes file into an assetbundle file (this step is to compress the file and reduce the file size)


7. Run the unity3d project, load the packaged VO. assetbundle file, and load it into Bytes:
String url = "http://www.mywebsite.com/mygame/assetbundles/vo.assetBundle"; ienumerator start () {// start a download of the given URL www WWW = www. loadfromcacheordownload (URL, 1); // wait for download to complete yield return WWW; // load and retrieve the assetbundle bundle = www. assetbundle; // load the textasset object textasset TXT = bundle. load ("mybinaryastext", typeof (textasset) as textasset; // retrieve the binary data as an array of bytes byte [] bytes = TXT. bytes ;}
8. deserialize the binary data to obtain the configuration data. Note that the VO. CS file generated earlier must be placed in the com. Game. VO directory. Otherwise, the deserialization will report that the VO object is not found.
Public object deserializebinary (byte [] BUF)
{
System. Io. memorystream memstream = new memorystream (BUF );
Memstream. Position = 0;
System. runtime. serialization. formatters. Binary. binaryformatter deserializer =
New system. runtime. serialization. formatters. Binary. binaryformatter ();
Object newobj = deserializer. deserialize (memstream );
Memstream. Close ();
Return newobj;
}


9. Complete.


Unity3d game project client editor implementation steps

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.