Home Game Development c# – How would I save texture together with different knowledge in binary file in Unity?

c# – How would I save texture together with different knowledge in binary file in Unity?

0
c# – How would I save texture together with different knowledge in binary file in Unity?

[ad_1]

So I’ve a save technique that may save knowledge to a binary file and one other operate that saves simply the feel. I wish to save each of them in a similar file. I assume I would wish to create sterilization surrogate for the Texture2D (I did this for another varieties like Vector3 and Quaternion) however I am unable to discover anyplace how would I do it for texture. I’m at the moment saving texture like byte array and I assume that might assist however I’m not positive add it to different knowledge.

Here is my code for saving the information:

 public static bool Save(string fileLocation, string saveFileidentify,object saveData)
{
    BinaryFormatter formatter = GetBinaryFormater();

    if (!Directory.Exists(fileLocation))
    {
        Directory.CreateDirectory(fileLocation);
    }

    string path = fileLocation + "/" + saveFileidentify + ".save";
    FileStream file = File.Create(path);
    formatter.Serialize(file, saveData);
    file.Close();

    Debug.Log("Save to: " + path);
    return true;
}

And right here is the one for the feel:

 public static bool SaveTexture(string fileLocation, string filename, Texture2D textureToSave)
{
    if (!Directory.Exists(fileLocation))
    {
        Directory.CreateDirectory(fileLocation);
    }

    byte[] byteArray = textureToSave.EncodeToJPG();
    string savedFileidentify = fileLocation + "/" + filename + ".jpg";

    File.WriteAllBytes(savedFileidentify, byteArray);
    Debug.Log("File saved at: " + savedFileidentify);

    return true;
}

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here