Unit classes that do not inherit MonoBehaviour have a MapUnit class that inherits MonoBehaviour.
In other words
public class Unit {
[HideInInspector][ES3Serializable]
public MapUnit mapUnit;
}
Here, it would be best if just saving the Unit would also save the MapUnit, but that would always result in null, so we also saved the MapUnit object.
It is code like the following.
Code: Select all
void DoSave(){
List<GameObject> mapUnits = new List<GameObject>(units.Count);
foreach (var unit in units) mapUnits.Add(unit.mapUnit.gameObject);
ES3.Save("mapUnits", mapUnits, file_name);
ES3.Save("units", units, file_name);
}
void DoLoad(){
var mapUnits = ES3.Load<List<GameObject>>("mapUnits", file_name);
var units = ES3.Load<List<Unit>>("units", file_name);
}
However, the 3D model that mapunit had went wrong.
The left side of the following image shows the model in use, before saving.
The right is the state of the model when it is loaded. Only a little bit of equipment on his waist accounts for his being there. This 3D model is maintained by MapUnit itself. Is this not a good idea?
However, I am using [ES3Serializable] and the model should be properly stored.
Is this a bad way to store the model you are using?
Code: Select all
public class MapUnit : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler {
[ES3Serializable]
[SerializeField] List<GameObject> UnitModels;