Esempio n. 1
0
        /// <summary>
        /// Save our Character Stats.
        /// </summary>
        public void Save()
        {
            // Create a new Player_Data.
            Character_Data data = new Character_Data();

            // Save the data.
            data.currentHealth = CurrentHealth;
            data.currentMana   = CurrentMana;
            // Save the bonus information.
            data.bonusHealth    = BonusHealth;
            data.bonusMana      = BonusMana;
            data.bonusDamage    = BonusDamage;
            data.bonusMoveSpeed = BonusMoveSpeed;

            // Turn the Character_Stats data into Json data.
            string charStatsToJson = JsonUtility.ToJson(data);

            // IF we are saving the player,
            // ELSE we are saving an non player.
            if (playerManager != null)
            {
                // Save the information.
                PlayerPrefs.SetString("Player", charStatsToJson);
            }
            else
            {
                // Save the information. (scene name / gameobject name).  Care when using this as you want unique names of your monsters if you choose to have them saved.
                PlayerPrefs.SetString(SceneManager.GetActiveScene().name + "/" + gameObject.name, charStatsToJson);
            }
        }
Esempio n. 2
0
        private void Load()
        {
            string charStatsJson;

            // IF we are loading the player,
            // ELSE we are loading an enemy.
            if (playerManager != null)
            {
                // Load the information.
                charStatsJson = PlayerPrefs.GetString("Player");
                // IF there is nothing in this string.
                if (String.IsNullOrEmpty(charStatsJson))
                {
                    // Load the default value of the stats.
                    CurrentHealth = DefaultHealth;
                    CurrentMana   = DefaultMana;
                    // GTFO of here we done son!
                    return;
                }
            }
            else
            {
                // Load the information. (scene name / gameobject name).
                charStatsJson = PlayerPrefs.GetString(SceneManager.GetActiveScene().name + "/" + gameObject.name);
                // IF there is nothing in this string.
                if (String.IsNullOrEmpty(charStatsJson))
                {
                    // Load the default value of the stats.
                    CurrentDamage    = DefaultDamage;
                    CurrentHealth    = DefaultHealth;
                    MaxHealth        = DefaultMaxHealth;
                    CurrentMana      = DefaultMana;
                    MaxMana          = DefaultMaxMana;
                    CurrentMoveSpeed = DefaultMoveSpeed;
                    // GTFO of here we done son!
                    return;
                }
            }
            // Turn the json data to represent Equipment_Data.
            Character_Data data = JsonUtility.FromJson <Character_Data> (charStatsJson);

            // Load the player stats.
            CurrentHealth  = data.currentHealth;
            CurrentMana    = data.currentMana;
            BonusDamage    = data.bonusDamage;
            BonusMoveSpeed = data.bonusMoveSpeed;
            BonusHealth    = data.bonusHealth;
            BonusMana      = data.bonusMana;;
        }