Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Collections.Generic;
- using UnityEngine;
- public class SaveSystem : MonoBehaviour {
- public static SaveSystem saveSystem;
- public int playerLevel = 1;
- public float xp;
- public float xpToNextLevel = 100;
- public int skillPoints = 0;
- public int gold = 0;
- public bool hasGame;
- public int numberOfEnemys = 1;
- public float playerHeath = 100;
- [Header("Shop")]
- public List<ShopStuff> shopList = new List<ShopStuff>();
- public int mainWeapon = 1;
- public int sideWeapon = 1;
- public bool hasItem;
- [Header("Inventory")]
- public List<Item> items = new List<Item>();
- [Header("Perks")]
- public float drawSpeed = 260f;
- public int drawSpeedDamage;
- public int drawSpeedN;
- public int AddHealth;
- public int AddHealthN;
- public float addStamina;
- [Header("Level")]
- public bool main;
- public bool arena;
- public bool trainig;
- public bool death;
- public bool Barracks;
- public GameObject playerControlls;
- [Header("Customize Character")]
- public string playerName;
- void Awake () {
- if (saveSystem != null)
- {
- Debug.LogError ("More then one GameControllers in the scene");
- }
- else
- {
- saveSystem = this;
- }
- Load ();
- }
- void Update()
- {
- if (xp >= xpToNextLevel)
- {
- playerLevel++;
- skillPoints++;
- xpToNextLevel += xpToNextLevel;
- }
- }
- public void Controlls()
- {
- playerControlls.SetActive(!playerControlls.activeSelf);
- }
- public void Save()
- {
- BinaryFormatter bf = new BinaryFormatter();
- FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.data");
- PlayerData data = new PlayerData();
- data.playerLevel = playerLevel;
- data.xp = xp;
- data.xpToNextLevel = xpToNextLevel;
- data.skillPoints = skillPoints;
- hasGame = true;
- data.hasGame = hasGame;
- data.gold = gold;
- data.drawSpeed = drawSpeed;
- data.drawSpeedNumber = drawSpeedN;
- data.AddHealth = AddHealth;
- data.AddHealthN = AddHealthN;
- data.drawSpeedDamage = drawSpeedDamage;
- data.numberOfEnemys = numberOfEnemys;
- data.mainWeapon = mainWeapon;
- data.sideWeapon = sideWeapon;
- data.hasItem = hasItem;
- data.arena = arena;
- data.death = death;
- data.main = main;
- data.trainig = trainig;
- data.Barracks = Barracks;
- data.playerHeath = playerHeath;
- data.addStamina = addStamina;
- data.playerName = playerName;
- data.items = items;
- data.shopList = shopList;
- bf.Serialize(file, data);
- file.Close();
- Debug.Log("has been saved");
- }
- public void Load()
- {
- Debug.Log("has deen Laoding");
- if (File.Exists(Application.persistentDataPath + "/playerInfo.data"))
- {
- BinaryFormatter bf = new BinaryFormatter();
- FileStream file = File.Open (Application.persistentDataPath + "/playerInfo.data", FileMode.Open);
- PlayerData data = (PlayerData)bf.Deserialize (file);
- file.Close();
- playerLevel = data.playerLevel;
- xpToNextLevel = data.xpToNextLevel;
- skillPoints = data.skillPoints;
- xp = data.xp;
- gold = data.gold;
- drawSpeed = data.drawSpeed;
- drawSpeedN = data.drawSpeedNumber;
- AddHealth = data.AddHealth;
- AddHealthN = data.AddHealthN;
- hasGame = data.hasGame;
- drawSpeedDamage = data.drawSpeedDamage;
- numberOfEnemys = data.numberOfEnemys;
- mainWeapon = data.mainWeapon;
- sideWeapon = data.sideWeapon;
- shopList = data.shopList;
- hasItem = data.hasItem;
- death = data.death;
- main = data.main;
- trainig = data.trainig;
- arena = data.arena;
- Barracks = data.Barracks;
- playerHeath = data.playerHeath;
- addStamina = data.addStamina;
- playerName = data.playerName;
- items = data.items;
- Debug.Log ("has deen Laoded");
- }
- }
- public void Delete()
- {
- File.Delete(Application.persistentDataPath + "/playerInfo.data");
- Debug.Log("has deen deleted");
- playerLevel = 1;
- skillPoints = 0;
- xp = 0;
- xpToNextLevel = 100;
- gold = 0;
- hasGame = false;
- drawSpeed = 260f;
- drawSpeedN = 0;
- AddHealthN = 0;
- AddHealth = 0;
- drawSpeedDamage = 0;
- numberOfEnemys = 1;
- PlayerPrefs.DeleteAll();
- mainWeapon = 1;
- sideWeapon = 1;
- hasItem = false;
- playerHeath = 100;
- main = true;
- trainig = false;
- arena = false;
- death = false;
- Barracks = false;
- addStamina = 0;
- playerName = "Player";
- items.Clear();
- Debug.Log ("has staets has been reset");
- }
- }
- [Serializable]
- class PlayerData
- {
- public int playerLevel;
- public float xp;
- public float xpToNextLevel;
- public int skillPoints;
- public int gold;
- public int AddHealth;
- public int AddHealthN;
- public int drawSpeedNumber;
- public int drawSpeedDamage;
- public float drawSpeed;
- public bool hasGame;
- public int numberOfEnemys;
- public List<ShopStuff> shopList = new List<ShopStuff>();
- public int mainWeapon;
- public int sideWeapon;
- public float addStamina;
- public bool hasItem;
- public bool main;
- public bool arena;
- public bool trainig;
- public bool death;
- public bool Barracks;
- public float playerHeath;
- public string playerName;
- public List<Item> items = new List<Item>();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement