- Home /
hay i am new in saving and loading date in binary formate I wana to save and load list of data
I had a used json format to store data previously but it doesn't seems secured one as the data is stored in simpler form and easily editable by the player so i found this binarry formator on youtube which seems prity secured one but i was unable to fine how to store a list of data using that format. basicaly this is the class which i am using for couple of times with different character to store ther time, feed and sleep status. so basicaly i was using this class as an list in another class to store the values in this.
using UnityEngine;
[System.Serializable] public class PetDataHolder {
public string closeTime = "00:00:00";
public string timeLeft = "00:00:00";
public int xp;
public string feedTimerStore = "00:00:00";
public string sleepTimerStore = "00:00:00";
public string lockTimerStore = "00:00:00";
[HideInInspector] public int Hr, Min,sec;
[HideInInspector] public float Sec;
[HideInInspector] public int feedHr, feedMin;
[HideInInspector] public float feedSec;
[HideInInspector] public int sleepHr, sleepMin;
[HideInInspector] public float sleepSec;
[HideInInspector] public int lockhr, lockMin;
[HideInInspector] public float locksec;
public int totalFeedToday;
public int totalSleepToday;
public int totalLockDownToday;
public int days;
[HideInInspector]public bool startFeed;
[HideInInspector]public bool startSleep;
[HideInInspector]public bool startLockDown;
[HideInInspector]public bool petExhousted;
}
Answer by rh_galaxy · Sep 28, 2021 at 02:15 PM
Why not use and convert your binary format to base64. It's harder to modify, and not possible to read like json and plain text. But you must face it, either go a full feature crypting enging or something, and do it with what you can. Right now this small approach should work.
//save
byte[] b = BitConverter.GetBytes(1024);
System.Array.Copy(BitConverter.GetBytes(pd.xp), 0, b, iOffs + 0, 4);
string base64 = System.Convert.ToBase64String(b);
Debug.Log(base64.ToString());
//load
byte[] bytes = System.Convert.FromBase64String(szFileText);
Debug.Log(szFileText);
(not completely sure of the code stuff but you will work it out).
Your answer
![](https://koobas.hobune.stream/wayback/20220613043524im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Save / Load List with Prefabs instantiated in the runtime 2 Answers
Save Load Data unity 0 Answers
Set int to object from list? 0 Answers
im getting a serialization exception eror in my load method 0 Answers