public InteractableSave(InteractableSave value) { InteractableID = value.InteractableID; IsDisabled = value.IsDisabled; IsLocked = value.IsLocked; IsActivated = value.IsActivated; }
// This should really be a bool so that the game can be prevented loading if it fails. static void LoadSavedGame(string saveGameLocation) { LoadedSaveName = ""; LoadedTotalTime = 0f; LoadedPosition = Vector3.zero; LoadedCollectables.Clear(); LoadedInteractables.Clear(); SaveGameLocation = saveGameLocation; XmlReader xmlReader; xmlReader = XmlReader.Create(saveGameLocation); while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element) { // <SaveData SaveFileName="SaveFileName" SaveFileDate="SaveFileDate" SaveFileTime="SaveFileTime" SaveFileTimeOnGame="SaveFileTimeOnGame" SaveFilePositionX/Y/Z="Vector3"> if (xmlReader.Name == "player") { LoadedSaveName = xmlReader.GetAttribute("saveName"); LoadedTotalTime = float.Parse(xmlReader.GetAttribute("saveTotalTime")); LoadedPosition = new Vector3( float.Parse(xmlReader.GetAttribute("playerPositionX")), float.Parse(xmlReader.GetAttribute("playerPositionY")), float.Parse(xmlReader.GetAttribute("playerPositionZ")) ); } if (xmlReader.Name == "collectable") { string CollectableID = xmlReader.GetAttribute("CollectableID"); CollectableType CollectableType = (CollectableType)Enum.Parse(typeof(CollectableType), xmlReader.GetAttribute("CollectableType")); bool CollectableCollected = bool.Parse(xmlReader.GetAttribute("CollectableCollected")); CollectableSave currentLoadingCollectable = new CollectableSave( CollectableID, CollectableType, CollectableCollected ); LoadedCollectables.Add(currentLoadingCollectable); } if (xmlReader.Name == "interactable") { string InteractableID = xmlReader.GetAttribute("InteractableID"); bool IsDisabled = bool.Parse(xmlReader.GetAttribute("IsDisabled")); bool IsLocked = bool.Parse(xmlReader.GetAttribute("IsLocked")); bool IsActivated = bool.Parse(xmlReader.GetAttribute("IsActivated")); InteractableSave currentLoadingInteractable = new InteractableSave( InteractableID, IsDisabled, IsLocked, IsActivated ); LoadedInteractables.Add(currentLoadingInteractable); } } } xmlReader.Close(); }