using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; using UnityEngine.SceneManagement; public class SaveDynamicObjects : MonoBehaviour { public void Save() { //saving player position var player = GameObject.FindGameObjectWithTag("Player"); player.GetComponent().SavePosition(); player.GetComponent().SaveCheckpoint(); SaveElementsByScene(); } public void SaveElementsByScene() { switch(SceneManager.GetActiveScene().name) { case "SampleScene": { SaveSampleScene(); break; } case "CaveEntrance": { break; } case "WizardHouse": { //TODO dynamic elements if added break; } case "OutsideWizardsHouse": { //TODO dynamic elements if added break; } default: { Debug.Log("Niedopasowano sceny podczaas zapisu dynamicznych elementow"); break; } } } //TODO get list of elemnts from each scene individually - don't describe here each one manually !!! private void SaveSampleScene() { //Saving Thugs from Cave/SampleScene List thugs = GameObject.Find("NPCManager").GetComponent().thugs; foreach (var thug in thugs) { var ThugFromScene = GameObject.FindObjectsOfType(true).Where(sr => sr.gameObject.name == thug.name).ToArray()[0]; if (ThugFromScene != null) { Debug.Log("Save thug"); ThugFromScene.GetComponent().SaveCheckpoint(); } else { if (OnMapAppearanceMethod.Gateway == OnMapAppearanceMethodEnum.NewGame) { PlayerPrefs.SetInt(thug.name + "-S", 0); } else { PlayerPrefs.SetInt(thug.name + "-S", 1); } } } //saving bossThug ThugModel bossThug = GameObject.Find("NPCManager").GetComponent().bossThug; var BossThugFromScene = GameObject.FindObjectsOfType(true).Where(sr => sr.gameObject.name == bossThug.name).ToArray()[0]; if (BossThugFromScene != null) { BossThugFromScene.GetComponent().SaveCheckpoint(); } else { if (OnMapAppearanceMethod.Gateway == OnMapAppearanceMethodEnum.NewGame) { PlayerPrefs.SetInt(bossThug.name + "-S", 0); } else { PlayerPrefs.SetInt(bossThug.name + "-S", 1); } } } }