Beispiel #1
0
        public void SaveThisData(FightersSaveData data)
        {
            try
            {
                BinaryFormatter bf = new BinaryFormatter();

                FileStream fileStream = File.Create(defaultSavePath);
                bf.Serialize(fileStream, data);
                fileStream.Close();
            }
            catch (Exception ex)
            {
                Debug.LogError("Exception in SaveLoadManager-SaveThisData: " + ex.Message);
            }
        }
Beispiel #2
0
        public static FightersSaveData NullData()
        {
            var fighter = new Fighter();
            var data    = new FightersSaveData();

            data.enemyLevel  = 1;
            data.enemyHealth = fighter.GetTotalHealth_Enemy(1);

            data.alliesLevel = new List <float>();
            data.alliesLevel.Add(1);

            data.alliesHealth = new List <float>();
            data.alliesHealth.Add(fighter.GetTotalHealth_Enemy(1));

            data.alliesPosition = new List <aVector3>();

            return(data);
        }
Beispiel #3
0
        void Awake()
        {
            enemy = new Fighter();
            enemy.ResetFighter(Fighter.FighterType.Enemy);
            ally = new Fighter();
            ally.ResetFighter(Fighter.FighterType.Ally);

            saveLoadManager  = new SaveLoadManager();
            fightersSaveData = saveLoadManager.LoadSavedData();
            if (fightersSaveData == null)
            {
                fightersSaveData = FightersSaveData.NullData();
            }

            gameState = GameState.Idle;
            SetState(new IdleState(this));
            SpawnNewAllies();
            SpawnEnemies();
        }
Beispiel #4
0
 private void OnApplicationFocus(bool focus)
 {
     if (!focus)
     {
         var data = new FightersSaveData();
         data.enemyLevel     = enemy.GetLevel();
         data.enemyHealth    = enemy.GetCurrentHealth();
         data.alliesLevel    = new List <float>();
         data.alliesHealth   = new List <float>();
         data.alliesPosition = new List <aVector3>();
         for (int i = 0; i < allyFighterControllers.Count; i++)
         {
             data.alliesLevel.Add(allyFighterControllers[i].fighter.GetLevel());
             data.alliesHealth.Add(allyFighterControllers[i].fighter.GetCurrentHealth());
             data.alliesPosition.Add(new aVector3(allyFighterControllers[i].transform.position.x, allyFighterControllers[i].transform.position.y, allyFighterControllers[i].transform.position.z));
         }
         saveLoadManager.SaveThisData(data);
     }
 }
Beispiel #5
0
        public FightersSaveData LoadSavedData()
        {
            try
            {
                FileStream fileStream = File.Open(defaultSavePath, FileMode.Open);
                if (File.Exists(defaultSavePath) && fileStream.Length > 0)
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    //GameSave data = (GameSave)bf.Deserialize(fileStream);
                    FightersSaveData data = bf.Deserialize(fileStream) as FightersSaveData;
                    fileStream.Close();

                    return(data);
                }
                return(null);
            }
            catch (Exception ex)
            {
                Debug.LogError("Exception in SaveLoadManager-LoadSavedData: " + ex.Message);
                return(null);
            }
        }