Ejemplo n.º 1
0
    public PlayerData(PlayerHealth player, Boss boss, EnemyHealth enemyHealth, Minon minion)
    {
        if (player != null)
        {
            this.playerHealth = player.currentHeatlh;
            this.position     = new float[3];
            this.position[0]  = player.transform.position.x;
            this.position[1]  = player.transform.position.y;
            this.position[2]  = player.transform.position.z;
        }

        //boss
        if (boss != null)
        {
            this.bossWasInstantiate = boss.wasInstantiated;
            this.bossPosition       = new float[3];
            this.bossPosition[0]    = boss.transform.position.x;
            this.bossPosition[1]    = boss.transform.position.y;
            this.bossPosition[2]    = boss.transform.position.z;
            this.bossHealth         = enemyHealth.currentHeatlh;
        }


        //minion
        if (minion != null)
        {
            this.minionHealth      = enemyHealth.currentHeatlh;
            this.minionPosition    = new float[3];
            this.minionPosition[0] = minion.transform.position.x;
            this.minionPosition[1] = minion.transform.position.y;
            this.minionPosition[2] = minion.transform.position.z;
        }
    }
Ejemplo n.º 2
0
 public PlayerData(PlayerHealth playerHealth, Minon minion)
 {
     this.playerHealth = playerHealth.currentHeatlh;
     this.position     = new float[3];
     position[0]       = playerHealth.transform.position.x;
     position[1]       = playerHealth.transform.position.y;
     position[2]       = playerHealth.transform.position.z;
 }
Ejemplo n.º 3
0
    public void Load()
    {
        player = FindObjectOfType <PlayerHealth>();

        boss        = FindObjectOfType <Boss>();
        enemyHealth = FindObjectOfType <EnemyHealth>();
        minion      = FindObjectOfType <Minon>();

        PlayerData data = SaveSystem.Load();

        if (player != null)
        {
            //player data loaded
            player.currentHeatlh = data.playerHealth;
            //player.TakeDamage(0);
            Vector3 position;
            position.x = data.position[0];
            position.y = data.position[1];
            position.z = data.position[2];
            player.transform.position = position;
        }


        //boss data load
        if (boss != null)
        {
            Vector3 bossPosition;
            bossPosition.x            = data.bossPosition[0];
            bossPosition.y            = data.bossPosition[1];
            bossPosition.z            = data.bossPosition[2];
            boss.transform.position   = bossPosition;
            enemyHealth.currentHeatlh = data.bossHealth;
            Debug.Log("boss was null");
        }
        else if (data.bossWasInstantiate && data.bossHealth > 0)
        {
            Instantiate(bossPrefab, new Vector3(data.bossPosition[0], data.bossPosition[1], data.bossPosition[2]), Quaternion.identity);
            enemyHealth.currentHeatlh = data.bossHealth;

            Debug.Log("boss was created becaause is null but was instantiated");
        }

        //minion data load
        if (minion != null)
        {
            enemyHealth.currentHeatlh = data.minionHealth;
            enemyHealth.TakeDamage(0);
            Vector3 minionPosition;
            minionPosition.x          = data.minionPosition[0];
            minionPosition.y          = data.minionPosition[1];
            minionPosition.z          = data.minionPosition[2];
            minion.transform.position = minionPosition;
        }


        //}
    }
Ejemplo n.º 4
0
    private void OnApplicationQuit()
    {
        player = FindObjectOfType <PlayerHealth>();

        boss        = FindObjectOfType <Boss>();
        enemyHealth = FindObjectOfType <EnemyHealth>();
        minion      = FindObjectOfType <Minon>();
        SaveSystem.Save(player, boss, enemyHealth, minion);
        print("Se salio ");
    }
Ejemplo n.º 5
0
    public static void Save(PlayerHealth playerHealth, Boss boss, EnemyHealth enemyHealth, Minon minion)
    {
        BinaryFormatter formatter  = new BinaryFormatter();
        string          path       = Application.persistentDataPath + "/gamedata.sgv";
        FileStream      fileStream = new FileStream(path, FileMode.OpenOrCreate);

        if (boss != null)
        {
            PlayerData data = new PlayerData(playerHealth, boss, enemyHealth, minion);
            formatter.Serialize(fileStream, data);
        }
        else
        {
            PlayerData data = new PlayerData(playerHealth, minion);
            formatter.Serialize(fileStream, data);
        }

        fileStream.Close();
    }