Example #1
0
    private void Load()
    {
        if (File.Exists(Application.persistentDataPath + "/playerData.dat"))
        {
            FileStream      file = File.Open(Application.persistentDataPath + "/playerData.dat", FileMode.Open);
            BinaryFormatter bf   = new BinaryFormatter();
            PLayerDataSave  data = bf.Deserialize(file) as PLayerDataSave;
            file.Close();

            pistolet.Ammo     = data.AmmoPistolet;
            mitraillette.Ammo = data.AmmoMitraillette;
            bazouka.Ammo      = data.AmmoBazooka;
            money             = data.Money;

            if (data.Items == null)
            {
                data.Items = new List <int>();
            }

            for (int i = 0; i < data.Items.Count; i++)
            {
                if (data.Items[i] == 1)
                {
                    items.Add((Item)item1);
                    //FindObjectOfType<InventoryUI>().slots[i].AddItem((Item)item1);
                }
                else if (data.Items[i] == 2)
                {
                    items.Add((Item)item2);
                }
                else if (data.Items[i] == 3)
                {
                    items.Add((Item)item3);
                }
                else if (data.Items[i] == 4)
                {
                    items.Add((Item)item4);
                }
                else if (data.Items[i] == 5)
                {
                    items.Add((Item)item5);
                }
                else if (data.Items[i] == 6)
                {
                    items.Add((Item)item6);
                }
            }
        }
    }
    private void Load()
    {
        if (File.Exists(Application.persistentDataPath + "/playerData.dat"))
        {
            FileStream      file = File.Open(Application.persistentDataPath + "/playerData.dat", FileMode.Open);
            BinaryFormatter bf   = new BinaryFormatter();
            PLayerDataSave  data = bf.Deserialize(file) as PLayerDataSave;
            file.Close();

            if (data.Health != 0)
            {
                health.CurrentValue = data.Health;
            }
        }
    }
Example #3
0
    private void Load()
    {
        if (File.Exists(Application.persistentDataPath + "/playerData.dat"))
        {
            FileStream file = File.Open(Application.persistentDataPath + "/playerData.dat", FileMode.Open);
            if (file.Length != 0)
            {
                BinaryFormatter bf   = new BinaryFormatter();
                PLayerDataSave  data = bf.Deserialize(file) as PLayerDataSave;

                lvl1Done = data.Lvl1Done;
                lvl2Done = data.Lvl2Done;
            }
            file.Close();
        }
    }
    private PLayerDataSave Load()
    {
        PLayerDataSave data = new PLayerDataSave();

        data.Items = new List <int>();

        if (File.Exists(Application.persistentDataPath + "/playerData.dat"))
        {
            FileStream file = File.Open(Application.persistentDataPath + "/playerData.dat", FileMode.Open);
            if (file.Length != 0)
            {
                BinaryFormatter bf = new BinaryFormatter();
                data = bf.Deserialize(file) as PLayerDataSave;
            }
            file.Close();
        }
        return(data);
    }
    private void Save(int currentLvl)
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = null;

        PLayerDataSave data = Load();

        if (!File.Exists(Application.persistentDataPath + "/playerData.dat"))
        {
            file = File.Create(Application.persistentDataPath + "/playerData.dat");
        }
        else
        {
            file = File.Open(Application.persistentDataPath + "/playerData.dat", FileMode.Open);
        }

        if (currentLvl == 2)
        {
            data.Lvl1Done = true;
        }
        else if (currentLvl == 3)
        {
            data.Lvl2Done = true;
        }

        if (currentLvl == -1)
        {
            data.Health           = 120;
            data.AmmoPistolet     = 0;
            data.AmmoMitraillette = 0;
            data.AmmoBazooka      = 0;
            data.Money            = 0;
            data.Items            = new List <int>();
        }
        else
        {
            data.Health           = PlayerMovement.playerInstance.Health.CurrentValue;
            data.AmmoPistolet     = Inventaire.instance.Pistolet.Ammo;
            data.AmmoMitraillette = Inventaire.instance.Mitraillette.Ammo;
            data.AmmoBazooka      = Inventaire.instance.Bazouka.Ammo;
            data.Money            = Inventaire.instance.NbMoney();

            if (data.Items == null)
            {
                data.Items = new List <int>();
            }
            for (int i = 0; i < Inventaire.instance.items.Count; i++)
            {
                if (Inventaire.instance.items[i].name == "Gun")
                {
                    data.Items.Add(1);
                }
                else if (Inventaire.instance.items[i].name == "Machine gun")
                {
                    data.Items.Add(2);
                }
                else if (Inventaire.instance.items[i].name == "RocketLauncher")
                {
                    data.Items.Add(3);
                }
                else if (Inventaire.instance.items[i].name == "Blue potion")
                {
                    data.Items.Add(4);
                }
                else if (Inventaire.instance.items[i].name == "Green potion")
                {
                    data.Items.Add(5);
                }
                else if (Inventaire.instance.items[i].name == "Red potion")
                {
                    data.Items.Add(6);
                }
            }

            /*data.Items = new List<SaveItems>();
             * for (int i = 0; i < Inventaire.instance.items.Count; i++)
             * {
             *  data.Items.Add(new Item())
             * }
             *
             * for (int i = 0; i < Inventaire.instance.items.Count; i++)
             * {
             *  data.Items[i].name = Inventaire.instance.items[i].name;
             *  data.Items[i].icon = Inventaire.instance.items[i].icon;
             *  data.Items[i].isDefaultItem = Inventaire.instance.items[i].isDefaultItem;
             *  data.Items[i].description = Inventaire.instance.items[i].description;
             * }*/
        }

        bf.Serialize(file, data);
        file.Close();
    }