Ejemplo n.º 1
0
    public static void Saveplayer(SaveMaster SaveMaster)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Application.persistentDataPath + "/player.sav";
        FileStream      stream    = new FileStream(path, FileMode.Create);

        playerdatascript data = new playerdatascript(SaveMaster);

        formatter.Serialize(stream, data);
        stream.Close();
    }
    public void LoadPlayer()
    {
        playerdatascript data = SaveSystemScript.LoadPlayer();
        Vector3          position;

        position.x = data.position[0];
        position.y = data.position[1];
        position.z = data.position[2];
        itemlist.Clear();
        inventory.items.Clear();
        inventory.RefreshUI();

        for (int i = 0; i < data.items.Length; i++)
        {
            itemlist.Add(data.items[i]);
        }
        for (int i = 0; i < itemlist.Count; i++)
        {
            if (itemlist[i] == 1)
            {
                items.Add(TantoKnife);
                inventory.AddItem(TantoKnife);
            }
            else if (itemlist[i] == 2)
            {
                items.Add(TokhilPistol);
                inventory.AddItem(TokhilPistol);
            }
            else if (itemlist[i] == 3)
            {
                items.Add(Vectorsmg);
                inventory.AddItem(Vectorsmg);
            }
            else if (itemlist[i] == 4)
            {
                items.Add(HuntingRifle);
                inventory.AddItem(HuntingRifle);
            }
        }
        inventory.RefreshUI();
        Player.transform.position = position;
        ninemilammo = data.ninemilammo;
        weaponmanagement.NineMillimeterRounds = ninemilammo;
        rifleammo = data.rifleammo;
        weaponmanagement.riflefloat = rifleammo;
    }
Ejemplo n.º 3
0
    // Start is called before the first frame update
    public static playerdatascript LoadPlayer()
    {
        string path = Application.persistentDataPath + "/player.sav";

        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path, FileMode.Open);

            playerdatascript data = formatter.Deserialize(stream) as playerdatascript;
            stream.Close();

            return(data);
        }
        else
        {
            Debug.LogError("Save File Not found In " + path);
            return(null);
        }
    }