- Home /
Question by
Hotshot10101 · Jun 26, 2017 at 12:38 PM ·
json
Json Serialization
Why will this work with UnityEngine.UsonUtility.ToJson:
using System;
using System.Collections.Generic;
[Serializable]
public class MoveShipsCollection<T>
{
public List<T> MoveShipsList = new List<T> ();
public void Add (T item)
{
MoveShipsList.Add (item);
}
}
var moveShipsCollection = MoveShipsCollection<MoveShips> moveShips = new MoveShipsCollection<MoveShips> ();
var json = JsonUtility.ToJson (moveShipsCollection);
But as part of this other class it I just get an empty string:
using System;
using System.Collections.Generic;
[Serializable]
public class MoveShipsJson
{
public MoveShipsCollection<MoveShips> MoveShips;
public InfinityMilitaryPiCarryCollection<InfinityMilitaryPiCarry> InfinityMilitaryPiCarrys;
}
Comment
Answer by GilbertoBitt · Jun 26, 2017 at 01:33 PM
Are you saying that I just need to derive my class from ScriptableObject? Do I need to derive all of them that way or just the $$anonymous$$oveShipsJson Class?
$$anonymous$$ost of that post is talking about subclassing not being supported and I am not subclassing.
Your answer