Skip to main content
Version: Next

Editor support

GamePlay-related functions often require a custom editor, and the data of a custom editor is often recorded in units, and the data structure is relatively complex, and each record is saved as a separate json file. luban supports this type of editor workflow.

Luban generates the code used by the editor to read and write the json file of the record. Editor developers only need to use the Load and Save functions to load and save the record as a json file that conforms to the Luban parser configuration rules.

Generate relevant parameters

The default namespace of the generated editor code class is "editor." + topmodule . This default value can be modified by option 'editor.topmodule' in the root definition file, for example

<root>
<topmodule name="cfg"/>
<option name="editor.topmodule" value="MyEditorConfig"/>
</root>

generate

The code generated by luban for the editor is very different from the code used for the project runtime, with the following key differences

  • Table code will not be generated. Because the editor generally operates data in units of records, there is no need to generate codes for table loading and saving.
  • Tables code will not be generated. Because there is no such need.
  • Generate additional metadata for enum xxx_Metadata class, which defines the metadata of all enum enumeration items
  • The generated bean code contains ToJson and FromJson functions
  • The datetime type corresponds to the string type, and the text corresponds to the EditorText class

Unity

Take --gen_types code_cs_unity_editor_json to generate it.

Refer to the example project Csharp_Unity_Editor_json

An example of use is as follows

// load
var skill = new editor. skill. Skill();
skill.LoadJsonFile("10001.json");
UnityEngine.Debug.Log("skill id:{0}, name:{1}", skill.Id, skill.Name);

// save
var skill = new editor. skill. Skill();
skill.Id = 10001;
skill.Name = "attack";
skill.SaveJsonFile("10001.json");

UE4

Take --gen_types code_cpp_ue_editor_json.

Not yet rigorously tested. Wait until there is actual demand and then test.