Example #1
0
    public static PlayerDataToSave LoadData(PlayerHandler player)
    {
        //Location to save
        string path = Application.persistentDataPath + "/" + "Huskies" + ".jpeg";

        //if we have the file at that path
        if (File.Exists(path))
        {
            Debug.Log(path + " Loaded");

            //get our binary formatter
            BinaryFormatter formatter = new BinaryFormatter();
            //and read the data from the path
            FileStream stream = new FileStream(path, FileMode.Open);
            //sell the data from what it is back to usable variables
            PlayerDataToSave data = formatter.Deserialize(stream) as PlayerDataToSave;
            //we are done
            stream.Close();
            //send usable data back to the PlayerDataToSave Script
            return(data);
        }
        else
        {
            return(null);
        }
    }
Example #2
0
    public void Load()
    {
        PlayerDataToSave data = PlayerSaveToBinary.LoadData(player);

        player.name = data.playerName;

        player.curCheckPoint = GameObject.Find(data.checkPoint).GetComponent <Transform>();

        player.maxHealth  = data.maxHealth;
        player.maxMana    = data.maxMana;
        player.maxStamina = data.maxStamina;

        player.curHealth  = data.curHealth;
        player.curMana    = data.curMana;
        player.curStamina = data.curStamina;

        player.transform.position = new Vector3(data.pX, data.pY, data.pZ);
        player.transform.rotation = new Quaternion(data.rX, data.rY, data.rZ, data.rW);


        /*
         * OLD STUFF
         *
         * //Players current health is set to playerPrefs saved float called CurHealth, else set it to MaxHealth
         * player.curHealth = PlayerPrefs.GetFloat("CurHealth", player.maxHealth);
         * player.curStamina = PlayerPrefs.GetFloat("CurStamina", player.maxStamina);
         * player.curMana = PlayerPrefs.GetFloat("CurMana", player.maxMana);
         *
         * //Get the player poisition x.y,z and put it into a vector3 and set the new player position
         * player.transform.position = new Vector3(PlayerPrefs.GetFloat("PlayerX", 1), PlayerPrefs.GetFloat("PlayerY", 1), PlayerPrefs.GetFloat("PlayerZ", 1));
         *
         * //Get the saved rotation of the character and set via a Quaternion (4 floats, X,Y,Z,W)
         * player.transform.rotation = new Quaternion(PlayerPrefs.GetFloat("RotationX", 0), PlayerPrefs.GetFloat("RotationY", 0), PlayerPrefs.GetFloat("RotationZ", 0), PlayerPrefs.GetFloat("RotationW", 0));
         */
    }
    public static PlayerDataToSave LoadData(PlayerHandler player)
    {
        string path = Application.persistentDataPath + "\\" + player.name + ".png";

        if (File.Exists(path))
        {
            // Creates objects.
            BinaryFormatter formatter = new BinaryFormatter();

            // Creates filepath at the specific place where the file was saved and opens it.
            FileStream stream = new FileStream(path, FileMode.Open);

            // Deserialize data in a certain format that the PlayerDataToSave can read.
            PlayerDataToSave data = formatter.Deserialize(stream) as PlayerDataToSave;

            // Close Stream
            stream.Close();

            // Return the data to the function which called it.
            return(data);
        }

        else
        {
            // Return nothing cause it doesnt exist.
            return(null);
        }
    }
Example #4
0
    // Update is called once per frame
    public void Load()
    {
        PlayerDataToSave data = PlayerSaveToBinary.LoadData(player);

        player.name = data.playerName;

        player.maxHealth  = data.maxHealth;
        player.maxMana    = data.maxMana;
        player.maxStamina = data.maxStamina;

        player.curHealth  = data.curHealth;
        player.curMana    = data.curMana;
        player.curStamina = data.curStamina;

        player.transform.position = new Vector3(data.pX, data.pY, data.pZ);
        player.transform.rotation = new Quaternion(data.rX, data.rY, data.rZ, data.rW);

        /* players current health is set to PlayerPrefs saved float called CurHealth, else set it to MaxHealth
         * player.curHealth = PlayerPrefs.GetFloat("CurHealth", player.maxHealth);
         * player.curMana = PlayerPrefs.GetFloat("CurMana", player.maxMana);
         * player.curStamina = PlayerPrefs.GetFloat("CurStamina", player.maxStamina);
         * // Position
         * /* x = PlayerPrefs.GetFloat("PlayerX", 1);
         * y = PlayerPrefs.GetFloat("PlayerY", 1);
         * z = PlayerPrefs.GetFloat("PlayerZ", 1);
         *
         * player.transform.position = new Vector3(PlayerPrefs.GetFloat("PlayerX", 29.51f), PlayerPrefs.GetFloat("PlayerY", 51f), PlayerPrefs.GetFloat("PlayerZ", 59.14f));
         * player.transform.rotation = new Quaternion(PlayerPrefs.GetFloat("PlayerRotX", 0), PlayerPrefs.GetFloat("PlayerRotY", 0), PlayerPrefs.GetFloat("PlayerRotZ", 0), PlayerPrefs.GetFloat("PlayerRotW", 0));
         * Debug.Log("Last player position");
         */
    }
    public static void SavePlayer(GameObject player)
    {
        BinaryFormatter formatter = new BinaryFormatter();

        string     path = Application.persistentDataPath + "/PlayerSettings.bin";
        FileStream file = new FileStream(path, FileMode.Create);

        PlayerDataToSave buffer = new PlayerDataToSave(player);

        PlayerController.observers.Clear();

        formatter.Serialize(file, buffer);
        file.Close();
    }
Example #6
0
    public void BinaryLoad()
    {
        PlayerDataToSave data = PlayerSaveToBinary.LoadData(player);

        player.maxHealth  = data.maxHealth;
        player.maxMana    = data.maxMana;
        player.maxStamina = data.maxStamina;

        player.currentHealth  = data.currentHealth;
        player.currentMana    = data.currentMana;
        player.currentStamina = data.currentStamina;

        player.currentCheckPoint = GameObject.Find(data.checkpoint).GetComponent <Transform>();

        if (!(data.currentPositionX == 0 && data.currentPositionY == 0 && data.currentPositionZ == -5))
        {
            player.transform.position = new Vector3(data.currentPositionX, data.currentPositionY, data.currentPositionZ);
            player.transform.rotation = new Quaternion(data.currentRotationX, data.currentRotationY, data.currentRotationZ, data.currentRotationW);
        }
        else
        {
            player.transform.position = player.currentCheckPoint.position;
            player.transform.rotation = player.currentCheckPoint.rotation;
            Debug.Log("Loading character at " + player.currentCheckPoint.position);
        }

        player.skinIndex    = data.skinIndex;
        player.hairIndex    = data.hairIndex;
        player.mouthIndex   = data.mouthIndex;
        player.eyesIndex    = data.eyesIndex;
        player.clothesIndex = data.clothesIndex;
        player.armourIndex  = data.armourIndex;

        player.characterClass = data.characterClass;
        player.characterName  = data.characterName;

        for (int i = 0; i < player.stats.Length; i++)
        {
            player.stats[i].value = data.stats[i];
        }

        LoadCustomisation.SetTexture("Skin", data.skinIndex);
        LoadCustomisation.SetTexture("Hair", data.hairIndex);
        LoadCustomisation.SetTexture("Mouth", data.mouthIndex);
        LoadCustomisation.SetTexture("Eyes", data.eyesIndex);
        LoadCustomisation.SetTexture("Clothes", data.clothesIndex);
        LoadCustomisation.SetTexture("Armour", data.armourIndex);
    }
    public static void SavePlayerData(PlayerHandler player)
    {
        //Reference a Binary Formatter
        BinaryFormatter formatter = new BinaryFormatter();
        //Location to Save
        string path = Application.persistentDataPath + "/" + PlayerDataToSave.saveSlot;
        //Create a file path
        FileStream stream = new FileStream(path, FileMode.Create);
        //What Data to write to the file
        PlayerDataToSave data = new PlayerDataToSave(player);

        //write it and convert to bytes for writing to binary
        formatter.Serialize(stream, data);
        //Ending
        stream.Close();
    }
Example #8
0
    // Update is called once per frame
    public void Load()
    {
        PlayerDataToSave data = PlayerSaveToBinary.LoadData(player);

        player.name          = data.playerName;
        player.curCheckPoint = GameObject.Find(data.checkPoint).GetComponent <Transform>();

        player.maxHealth  = data.maxHealth;
        player.maxMana    = data.maxMana;
        player.maxStamina = data.maxStamina;

        player.curHealth  = data.curHealth;
        player.curMana    = data.curMana;
        player.curStamina = data.curStamina;

        if (!(data.pX == 0 && data.pY == 0 && data.pZ == 0))
        {
            player.transform.position = new Vector3(data.pX, data.pY, data.pZ);
            player.transform.rotation = new Quaternion(data.rX, data.rY, data.rZ, data.rW);
        }
        else
        {
            player.transform.position = player.curCheckPoint.position;
            player.transform.rotation = player.curCheckPoint.rotation;
        }

        player.skinIndex    = data.skinIndex;
        player.hairIndex    = data.hairIndex;
        player.mouthIndex   = data.mouthIndex;
        player.eyesIndex    = data.eyesIndex;
        player.clothesIndex = data.clothesIndex;
        player.armourIndex  = data.armourIndex;

        player.characterClass = (CharacterClass)data.classIndex;
        player.characterName  = data.playerName;

        for (int i = 0; i < player.stats.Length; i++)
        {
            player.stats[i].value = data.stats[i];
        }
        LoadCustomisation.SetTexture("Skin", data.skinIndex);
        LoadCustomisation.SetTexture("Hair", data.hairIndex);
        LoadCustomisation.SetTexture("Mouth", data.mouthIndex);
        LoadCustomisation.SetTexture("Eyes", data.eyesIndex);
        LoadCustomisation.SetTexture("Clothes", data.clothesIndex);
        LoadCustomisation.SetTexture("Armour", data.armourIndex);
    }
Example #9
0
    public static void SavePlayerData(PlayerHandler player)
    {
        //Reference a Binary Formatter
        BinaryFormatter formatter = new BinaryFormatter();
        //Location to save
        string path = Application.persistentDataPath + "/" + "Huskies" + ".jpeg";
        //Create File at file path
        FileStream stream = new FileStream(path, FileMode.Create);
        //What Data to write to the file
        PlayerDataToSave data = new PlayerDataToSave(player);

        //Write it all and converting to bytes for writing to binary
        formatter.Serialize(stream, data);
        //And we are done
        Debug.Log(path);
        stream.Close();
    }
Example #10
0
    public static void SavePlayerData(PlayerHandler player)
    {
        //Refrence a Binary Formatter
        BinaryFormatter formatter = new BinaryFormatter();

        //Location to Save
        string path = Application.persistentDataPath + "/" + player.name + ".god";

        //Create file at file path
        FileStream stream = new FileStream(path, FileMode.Create);

        //What Data to write to the file
        PlayerDataToSave data = new PlayerDataToSave(player);

        formatter.Serialize(stream, data);

        stream.Close();
    }
    public static void SavePlayerData(PlayerHandler player)
    {
        // Creates a binary formatter object
        BinaryFormatter formatter = new BinaryFormatter();

        // Location to save
        string path = Application.persistentDataPath + "/" + player.name + ".png";

        // Creates a stream object
        FileStream stream = new FileStream(path, FileMode.Create);

        // Data to write.
        PlayerDataToSave data = new PlayerDataToSave(player);

        // Saves data into the specific path we want it to into a specific format.
        formatter.Serialize(stream, data);
        stream.Close();
    }
Example #12
0
    public void LoadGame()
    {
        PlayerDataToSave buffer = SerializingSystem.LoadPlayer();

        if (buffer != null)
        {
            PlayerController.serialization = true;
            PlayerController.data          = buffer;
            if (buffer.SceneName == "SampleScene")
            {
                SceneManager.LoadSceneAsync(buffer.SceneName);
            }
            else
            {
                SceneManager.LoadSceneAsync("SampleScene");
                SceneManager.LoadSceneAsync(buffer.SceneName);
            }
        }
    }
Example #13
0
    public void FirstLoad()
    {
        PlayerDataToSave data = PlayerSaveToBinary.LoadData(player);

        //player.name = data.playerName;

        player.curCheckPoint = GameObject.Find("Home Checkpoint 1").GetComponent <Transform>();

        player.maxHealth  = data.maxHealth;
        player.maxMana    = data.maxMana;
        player.maxStamina = data.maxStamina;

        player.curHealth  = data.curHealth;
        player.curMana    = data.curMana;
        player.curStamina = data.curStamina;

        player.transform.position = new Vector3(data.pX, data.pY, data.pZ);
        player.transform.rotation = new Quaternion(data.rX, data.rY, data.rZ, data.rW);
    }
Example #14
0
    public void Load()
    {
        PlayerDataToSave data = PlayerSaveToBinary.LoadData(player);

        player.name          = data.playerName;
        player.curCheckPoint = GameObject.Find(data.checkPoint).GetComponent <Transform>();
        player.maxHealth     = data.maxHealth;
        player.maxMana       = data.maxMana;
        player.maxStamina    = data.maxStamina;

        player.curHealth  = data.curHealth;
        player.curMana    = data.curMana;
        player.curStamina = data.curStamina;

        if (!(data.posx == 0 && data.posy == 0 && data.posz == 0))
        {
            player.transform.position = new Vector3(data.posx, data.posy, data.posz);
            player.transform.rotation = new Quaternion(data.rotx, data.roty, data.rotz, data.rotw);
        }
        else
        {
            player.transform.position = player.curCheckPoint.position;
            player.transform.rotation = player.curCheckPoint.rotation;
        }

        player.skinIndex    = data.skinIndex;
        player.eyesIndex    = data.eyesIndex;
        player.mouthIndex   = data.mouthIndex;
        player.hairIndex    = data.hairIndex;
        player.clothesIndex = data.clothesIndex;
        player.armourIndex  = data.armourIndex;

        player.charClass     = (CharacterClass)data.classIndex;
        player.characterName = data.playerName;

        for (int i = 0; i < player.stats.Length; i++)
        {
            player.stats[i].value = data.stats[i];
        }
    }
Example #15
0
    public static PlayerDataToSave LoadData(PlayerHandler player)
    {
        string path = Application.persistentDataPath + "/" + player.name + ".god";

        if (File.Exists(path))
        {
            //Get our binary formatter
            BinaryFormatter formatter = new BinaryFormatter();
            // and read the data from the path
            FileStream stream = new FileStream(path, FileMode.Open);
            //set the data from what it is back to usable variables
            PlayerDataToSave data = formatter.Deserialize(stream) as PlayerDataToSave;
            //we are done
            stream.Close();
            //send usable data back to the PlayerDataToSave Script
            return(data);
        }
        else
        {
            return(null);
        }
    }
    public static PlayerDataToSave LoadData(PlayerHandler player)
    {
        //Location to Save
        string path = Application.persistentDataPath + "/" + PlayerDataToSave.saveSlot;

        //If we have the file at that path
        if (File.Exists(path))
        {
            //get our Binary formatter
            BinaryFormatter formatter = new BinaryFormatter();
            //and reat the data
            FileStream stream = new FileStream(path, FileMode.Open);
            //set the data from what it is back to usable variables
            PlayerDataToSave data = formatter.Deserialize(stream) as PlayerDataToSave;
            //Ending
            stream.Close();
            //Send usable data back to the PLayerDataSave Script
            return(data);
        }
        else
        {
            return(null);
        }
    }