public void Load(GameobjectSaveData fullSave) { foreach (var save in fullSave.saves) { try { Type type = save.GetSaveType(); Component comp = GetComponent(type); if (comp == null) { throw new Exception("No component of type " + type.ToString() + " on gameobject " + gameObject.name); } ISaveableComponent saveable = (ISaveableComponent)comp; if (saveable == null) { throw new Exception("Component of type " + type.ToString() + " on gameobject " + gameObject.name + " is not a ISaveable"); } saveable.Load(save); } catch (Exception e) { Debug.LogError("Error when loading component due to " + e.ToString()); } } }
public GameobjectSaveData GetSave() { GameobjectSaveData save = new GameobjectSaveData(); if (prefabName != null) { save.prefabPath = prefabName; print(save.prefabPath); if (save.prefabPath.Length == 0) { throw new Exception("Invalid prefab path on object " + gameObject.name); } } else { Debug.LogError("No prefab on saveable object"); } save.saves = GetSavesFromComponents(); return(save); }