public void loadPlayerObject(int file) { SavePackage package; try { FileStream fs; if (file == 1) { fs = new FileStream(saveGameFile1, FileMode.Open); } else if (file == 2) { fs = new FileStream(saveGameFile2, FileMode.Open); } else if (file == 4) { fs = new FileStream(tmpSaveGameFile, FileMode.Open); } else { fs = new FileStream(saveGameFile3, FileMode.Open); } package = SavePackage.ParseFrom(fs); fs.Flush(); fs.Close(); } catch (IOException excep) { IOException dummy = excep; log("IO ERROR: COULD NOT LOAD GAME DATA"); return; } player.GetComponent <Player> ().setPlayerStatus(package.Player); }
// Use this for initialization void Start() { dotBG = GameObject.Find("DOTBGPREFAB").GetComponent <Image>(); splashContainer = GameObject.Find("SplashContainer"); mainContainer = GameObject.Find("MainContainer"); chromAbbAmount = Camera.main.GetComponent <VignetteAndChromaticAberration>().chromaticAberration; volumeSlider.value = PlayerPrefs.GetFloat("MasterVolume"); qualitySlider.value = QualitySettings.GetQualityLevel(); FileStream fs; try { fs = new FileStream(MasterDriver.saveGameFile1, FileMode.Open); // load1.text = PlayerPrefs.GetString("Load1","EMPTY"); SavePackage package = SavePackage.ParseFrom(fs); load1.text = package.Player.Name + "_" + package.Player.Version; fs.Flush(); fs.Close(); // Debug.LogError("Loaded save 1"); } catch (IOException excep) { load1.text = "EMPTY"; // Debug.LogError("nopee"); } try { fs = new FileStream(MasterDriver.saveGameFile2, FileMode.Open); // load2.text = PlayerPrefs.GetString("Load2","EMPTY"); SavePackage package = SavePackage.ParseFrom(fs); load2.text = package.Player.Name + "_" + package.Player.Version; fs.Flush(); fs.Close(); } catch (IOException excep) { load2.text = "EMPTY"; } try { fs = new FileStream(MasterDriver.saveGameFile3, FileMode.Open); // load3.text = PlayerPrefs.GetString("Load3","EMPTY"); SavePackage package = SavePackage.ParseFrom(fs); load3.text = package.Player.Name + "_" + package.Player.Version; fs.Flush(); fs.Close(); } catch (IOException excep) { load3.text = "EMPTY"; } }
public void load(int file) { CityHelp.helpMode = -3; Debug.Log("LOADING : " + file); SavePackage package; try { FileStream fs; if (file == 1) { fs = new FileStream(saveGameFile1, FileMode.Open); } else if (file == 2) { fs = new FileStream(saveGameFile2, FileMode.Open); } else if (file == 4) { fs = new FileStream(tmpSaveGameFile, FileMode.Open); } else { fs = new FileStream(saveGameFile3, FileMode.Open); } package = SavePackage.ParseFrom(fs); fs.Flush(); fs.Close(); } catch (IOException excep) { IOException dummy = excep; log("IO ERROR: COULD NOT LOAD GAME DATA"); return; } //WORLD GENERATION currentMap = new Map(package.Seed); //QUESTS List <QuestSave> questSaves = new List <QuestSave> (); questSaves.AddRange(package.QuestDataList); questListener = new QuestListener(questSaves); //CONVERSATIONS List <ConversationSave> conversationSaves = new List <ConversationSave> (); conversationSaves.AddRange(package.ConversationDataList); LoadResources.Instance.setConversationData(conversationSaves); //PLAYER STATUS player.transform.position = new Vector3(0.0f, player.transform.position.y, 0.0f); //global shift currentArea = currentMap.getArea(package.Player.PlayerPosition.AreaX, package.Player.PlayerPosition.AreaY); player.GetComponentInChildren <Player> ().setPlayerStatus(package.Player); currentArea.getGroup().generateAreas(); Transform camera = getCamera(); camera.position = new Vector3(package.Player.PlayerPosition.LocalX, camera.position.y, package.Player.PlayerPosition.LocalY); Quaternion rotation = camera.rotation; rotation.eulerAngles = new Vector3(0.0f, package.Player.Rotation, 0.0f); camera.rotation = rotation; //SPAWNED OBJECTS List <SpawnedObject> spawnedObjects = new List <SpawnedObject> (); spawnedObjects.AddRange(package.SpawnedObjectsList); foreach (SpawnedObject o in spawnedObjects) { GlobalPosition pos = o.ObjectPosition; Area area = currentMap.getArea(pos.AreaX, pos.AreaY); GameObject obj; WorldMap.AddStarAt(pos.AreaX, pos.AreaY, o.Description); if (o.HasEnemyAttributes) { obj = (GameObject)getEnemyFromProtobuf(o.ObjectData); obj = (GameObject)GameObject.Instantiate(obj); obj.GetComponent <Enemy>().name = o.ObjectData.Name; //TODO set enemy health } else { obj = (GameObject)getItemFromProtobuf(o.ObjectData); ItemDropObject drop = LoadResources.Instance.CommonItemDrop.GetComponent <ItemDropObject>(); GameObject newDrop = (GameObject)GameObject.Instantiate(drop.gameObject); GameObject newObject = (GameObject)GameObject.Instantiate(obj); newObject.SetActive(false); newObject.GetComponent <Item>().name = o.ObjectData.Type; if (o.ObjectData.HasItemInformation && o.ObjectData.ItemInformation.HasSaveVersion && newObject.GetComponent <Weapon>() != null) { newObject.GetComponent <Weapon>().version = o.ObjectData.ItemInformation.SaveVersion; } newDrop.GetComponent <ItemDropObject>().item = newObject; obj = newDrop; } obj.transform.position = new Vector3(pos.LocalX, obj.transform.position.y, pos.LocalY); if (area.basicRoom != null) { area.basicRoom.addSpawnedObject(obj); } if (area != currentArea) { obj.SetActive(false); } } }