c# - Issue with JSON serialization in Unity -
i'm trying serialize array of custom monobehaviours, using json. know can't done directly, i'm using wrapper class , serializing instead.
this wrapper object
[system.serializable]
public class wavescollection {
public wave[] waves;
}
that's object being wrapped (only important bits of it)
[system.serializable]
public class wave : monobehaviour {
[serializefield]public float[] appeartimes;//at time should n-th enemy appear;
[serializefield]public vector2[] positions;//where should n-th enemy appear;
[serializefield]public enemytype[] enemiestoappear;//what enemies should appear
}
wavesarray = new wave[] {thiswave, thiswave, thiswave};
wavescollection collection = new wavescollection();
collection.waves = new wave[10];
wavesarray.copyto(collection.waves, 0);
streamwriter sw = file.createtext(writepath);
string json = jsonutility.tojson(collection);
sw.writeline(json);
sw.close();
and that's code serializing. i've got array of non-null wave objects , copy wrapper object. try write in file , output is
{"waves":[{"instanceid":-99992},{"instanceid":-99992},{"instanceid":-99992},{"instanceid":0},{"instanceid":0},{"instanceid":0},{"instanceid":0},{"instanceid":0},{"instanceid":0},{"instanceid":0}]}
could give me few directions on i'm doing wrong?
Comments
Post a Comment