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