public void SaveGame() { Game Game = new Game(); BadgeManagerSetup BadgeManagerSetup = FindObjectOfType <BadgeManagerSetup>(); if (BadgeManagerSetup) { Game.Badges = new List <BadgeStruct>(); foreach (GameObject Badge in GameObject.FindGameObjectsWithTag("Badge")) { BadgeStruct SaveData = new BadgeStruct(); GameObject BadgeHolderGameObject = Badge.transform.parent.gameObject; BadgeHolder BadgeHolder = BadgeHolderGameObject.GetComponent <BadgeHolder>(); string PrefabPath = BadgeHolder.PrefabResourcePath; SaveData.Name = BadgeHolderGameObject.transform.name; SaveData.PrefabResourcePath = PrefabPath; SaveData.LocalPosition = BadgeHolderGameObject.transform.localPosition; SaveData.LocalRotation = BadgeHolderGameObject.transform.localRotation; Game.Badges.Add(SaveData); Debug.Log("Save data:" + SaveData.Name + " path " + SaveData.PrefabResourcePath); } } PlayerProgress PlayerProgress = FindObjectOfType <PlayerProgress>(); PlayerProgress.Save(Game); }
public void LoadGame() { PlayerProgress PlayerProgress = FindObjectOfType <PlayerProgress>(); Game Game = PlayerProgress.Load(); if (Game != null) { foreach (BadgeHolder Badge in FindObjectsOfType <BadgeHolder>()) { Destroy(Badge.gameObject); } BadgeManagerSetup BadgeManagerSetup = FindObjectOfType <BadgeManagerSetup>(); foreach (BadgeStruct BadgeStruct in Game.Badges) { Debug.Log("Loading data " + BadgeStruct.Name + " path " + BadgeStruct.PrefabResourcePath); GameObject NewBadge = Instantiate(BadgeManagerSetup.BadgePrefab); NewBadge.transform.name = BadgeStruct.Name; NewBadge.transform.parent = BadgeManagerSetup.transform; BadgeHolder BadgeHolder = NewBadge.GetComponent <BadgeHolder>(); BadgeHolder.PrefabResourcePath = BadgeStruct.PrefabResourcePath; NewBadge.transform.localPosition = BadgeStruct.LocalPosition; NewBadge.transform.localRotation = BadgeStruct.LocalRotation; } } }