void LoadTexture() { string path = Application.persistentDataPath + "/customChar.png"; //check to see if our save file for this character if (File.Exists(path))//if it does have a save file then load and SetTexture Skin, Hair, Mouth and Eyes from PlayerPrefs { CharDataToSave data = CharCustomSaveData.LoadPlayerData(); //Textures SetTexture("Skin", data.skin); skin = data.skin; SetTexture("Hair", data.hair); hair = data.hair; SetTexture("Mouth", data.mouth); mouth = data.mouth; SetTexture("Eyes", data.eyes); eyes = data.eyes; SetTexture("Armour", data.armour); armour = data.armour; SetTexture("Clothes", data.clothes); clothes = data.clothes; //Stats strength = data.strength; dexterity = data.dexterity; constitution = data.constitution; wisdom = data.wisdom; intelligence = data.intelligence; charisma = data.charisma; //Char Class charClass = data.charClass; //Char Race charRace = data.charRace; health = data.health; mana = data.mana; //grab the gameObject in scene that is our character and set its Object name to the Characters name characterName = data.characterName; // FOR GUI //playerName = data.characterName.ToString; //FOR CANVAS } else//if it doesnt then load the CustomSet level { SetTexture("Skin", customSet.skinIndex = 0); SetTexture("Hair", customSet.hairIndex = 0); SetTexture("Mouth", customSet.mouthIndex = 0); SetTexture("Eyes", customSet.eyesIndex = 0); SetTexture("Armour", customSet.armourIndex = 0); SetTexture("Clothes", customSet.clothesIndex = 0); //grab the gameObject in scene that is our character and set its Object name to the Characters name characterName = customSet.charName; //set name to default } }
public static CharDataToSave LoadPlayerData() { string path = Application.persistentDataPath + "/customChar.png"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); CharDataToSave data = formatter.Deserialize(stream) as CharDataToSave; stream.Close(); return(data); } else { Debug.Log("No FILE Detected"); return(null); } }
public static void SavePlayerData(CustomisationSet customSet) { //reference to binary formatter BinaryFormatter formatter = new BinaryFormatter(); //path to save to string path = Application.persistentDataPath + "/customChar.png"; //file stream create file at path FileStream stream = new FileStream(path, FileMode.Create); //dataToSave with player info CharDataToSave data = new CharDataToSave(customSet); //format and serialize location and data formatter.Serialize(stream, data); //end stream.Close(); Debug.Log("Saved"); }