void LoadNpcs() { var npcs = FindObjectsOfType <NpcSystem>(); foreach (var runtime in saveGame.npcRuntimes) { NpcRuntime foundRuntime = null; NpcSystem foundSystem = null; foreach (var npc in npcs) { var npcSaveGameId = npc.GetComponent <SaveGameIdSystem>().SaveGameId; if (npcSaveGameId == runtime.saveGameId) { foundRuntime = runtime; foundSystem = npc.GetComponent <NpcSystem>(); break; } } if (foundRuntime == null) { var spawned = Instantiate(runtimePrefabSettings.npcCharacterPrefab, runtime.position, runtime.rotation); spawned.transform.localScale = runtime.scale; spawned.GetComponent <SaveGameIdSystem>().SaveGameId = runtime.saveGameId; spawned.GetComponent <NpcSystem>().OnLoad(saveGame); } else { foundSystem.OnLoad(saveGame); } } }
public void OnSave(MySaveGame saveGame) { Debug.Log("NpcSystem OnSave: " + GetComponent <SaveGameIdSystem>().SaveGameId); var saveGameIdSystem = this.GetComponent <SaveGameIdSystem>(); var abilitySystem = GetComponent <AbilitySystem>(); var classSystem = GetComponent <ClassSystem>(); var healthSystem = GetComponent <HealthSystem>(); npcRuntime = new NpcRuntime(saveGameIdSystem.SaveGameId, abilitySystem.abilityRuntimes, classSystem.classRuntime); npcRuntime.position = transform.position; npcRuntime.rotation = transform.rotation; npcRuntime.scale = transform.localScale; npcRuntime.maxHealth = healthSystem.maxHealth; npcRuntime.currentHealth = healthSystem.currentHealth; npcRuntime.isAlive = healthSystem.IsAlive; saveGame.npcRuntimes.Add(npcRuntime); }