Example #1
0
        IEnumerator LoadSaveInfo(int slot, GUILoadGameSlots slotInfo)
        {
            slotInfo.description.text = "";
            slotInfo.saveTime.text    = "";
            slotInfo.title.text       = "Loading, please wait...";
            Color slotImageColor = slotInfo.saveImage.color;

            slotImageColor.a         = 0;
            slotInfo.saveImage.color = slotImageColor;
            if (File.Exists(Application.persistentDataPath + "/gameData" + slot + ".png"))
            {
                string image = @"file://" + Application.persistentDataPath + "/gameData" + slot + ".png";
                using (WWW www = new WWW(image))
                {
                    yield return(www);

                    slotInfo.saveImage.sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));
                    slotImageColor.a          = 1;
                    slotInfo.saveImage.color  = slotImageColor;
                }
            }
            if (File.Exists(Application.persistentDataPath + "/gameData" + slot + ".dat"))
            {
                PlayerData data;
                try {
                    BinaryFormatter bf   = new BinaryFormatter();
                    FileStream      file = File.Open(Application.persistentDataPath + "/gameData" + slot + ".dat", FileMode.Open); //open the file
                    data = (PlayerData)bf.Deserialize(file);                                                                       //cast generic object to Playerdata and read info from file into PlayerData
                    file.Close();

                    slotInfo.description.text = "Health: " + data.health;
                    slotInfo.saveTime.text    = "" + data.lastSave;
                    slotInfo.title.text       = "Location: " + data.sceneName;
                }
                catch (Exception e)
                {
                    slotInfo.title.text       = "Error while loading file.";
                    slotInfo.saveTime.text    = e.Message;
                    slotInfo.description.text = "";
                }
            }
            else
            {
                slotInfo.description.text = "";
                slotInfo.saveTime.text    = "";
                slotInfo.title.text       = "Empty Slot";
            }
        }
Example #2
0
 public void LoadSaveInfoOnly(int slot, GUILoadGameSlots slotInfo)
 {
     StartCoroutine(LoadSaveInfo(slot, slotInfo));
 }