【修复】修复code_cs_unity_editor_json无法加载多态数据的问题

main
walon 2022-03-02 16:51:07 +08:00
parent 0e3782dd48
commit 856f30df5b
1 changed files with 12 additions and 9 deletions

View File

@ -6,6 +6,7 @@ using SimpleJSON;
name = x.name
parent_def_type = x.parent_def_type
parent = x.parent
hierarchy_fields = x.hierarchy_fields
fields = x.fields
}}
@ -28,12 +29,10 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
{{~end~}}
}
{{~if !x.is_abstract_type~}}
public override void LoadJson(SimpleJSON.JSONObject _json)
{
{{~if parent_def_type ~}}
base.LoadJson(_json);
{{~end~}}
{{~ for field in fields ~}}
{{~ for field in hierarchy_fields ~}}
{
var _fieldJson = _json["{{field.name}}"];
if (_fieldJson != null)
@ -47,10 +46,10 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
public override void SaveJson(SimpleJSON.JSONObject _json)
{
{{~if parent_def_type ~}}
base.SaveJson(_json);
{{~if parent~}}
_json["{{x.json_type_name_key}}"] = "{{x.full_name}}";
{{~end~}}
{{~ for field in fields ~}}
{{~ for field in hierarchy_fields ~}}
{{~if field.ctype.is_nullable}}
if ({{field.convention_name}} != null)
{
@ -66,6 +65,7 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
{{~end~}}
{{~end~}}
}
{{~end~}}
public static {{name}} LoadJson{{name}}(SimpleJSON.JSONNode _json)
{
@ -75,6 +75,9 @@ public {{x.cs_class_modifier}} partial class {{name}} : {{if parent_def_type}} {
switch (type)
{
{{~for child in x.hierarchy_not_abstract_children~}}
{{~if child.namespace == x.namespace~}}
case "{{child.full_name}}":
{{~end~}}
case "{{cs_impl_data_type child x}}":obj = new {{child.full_name}}(); break;
{{~end~}}
default: throw new SerializationException();