简体   繁体   中英

Unity3d FullInspector and Json.net not serializing data

Problem: I'm having a hard time serializing data with full inspector and json.net.

Here is a example of a simple test I just ran. I have both json.net and full inspector in the project. When I place the test script on an object in the scene I can see the exposed model object and edit its properties. However when I run the application none of the data persists. Am I missing something?

I see there is a ref wrapper in the documentation , but that seems to be for serializing behavior references, not standard objects. (maybe I am wrong)

using FullInspector;
using Newtonsoft.Json;

public class test : BaseBehavior
{
    public JsonModel model;

}

public class JsonModel : BaseObject
{
    [JsonProperty(propertyName: "id")]
    public string ID { get; set; }
}

You can see once I run the project in the unity editor, the data disappears. (running is indicated by the tint in color)

在此处输入图片说明

The reason the above code has an attribute is because that is intended to be a json.net object so I can deserialize responses from my cms and bind the data to this object. That is not the only use for this model object though, I want to be able to expose it in the editor and manually plug data and save the data ( because some content will be housed locally and has the same structure ) .

在此处输入图片说明

JsonModel is serialized by Unity - it needs a [Serializable] annotation.

Please note that BaseObject only supports Full Serializer; this will work as is however because FS will serialize auto-properties by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM