public static Equipment FromJson(string json) { SerializeableEquipment myClone = UnityEngine.JsonUtility.FromJson <SerializeableEquipment>(json); Equipment equipment = new Equipment { }; if (myClone.body != null) { equipment.InitializeBody(myClone.body.Length); for (int i = 0; i < myClone.body.Length; i++) { equipment.body[i] = myClone.body[i].GetRealOne(); } } else { Debug.LogError("Body is null from equipment clone: " + json); } if (myClone.gear != null) { equipment.InitializeGear(myClone.gear.Length); for (int i = 0; i < myClone.gear.Length; i++) { equipment.gear[i] = myClone.gear[i].GetRealOne(); } } else { Debug.LogError("Gear is null from equipment clone: " + json); } return(equipment); }
public string GetJson() { var clone = new SerializeableEquipment(); clone.body = new EquipmentItem.SerializableEquipmentItem[body.Length]; for (int i = 0; i < body.Length; i++) { clone.body[i] = body[i].GetSerializeableClone(); } clone.gear = new EquipmentItem.SerializableEquipmentItem[gear.Length]; for (int i = 0; i < gear.Length; i++) { clone.gear[i] = gear[i].GetSerializeableClone(); } var json = UnityEngine.JsonUtility.ToJson(clone); //Debug.LogError("json: " + json + ":" + body.Length); return(json); }