Skip to content
DucNV_2000 edited this page Oct 17, 2024 · 6 revisions

Introduction

flowchart LR
    Unity.Serialization{Unity.Serialization} --> W(Write) & R(Read) 
    click Unity.Serialization "https://docs.unity3d.com/Packages/[email protected]/manual/index.html" _blank
    Data[("Data <br> Profile 0<br>.<br>.<br>.<br> Profile N <br> Dictionary&lt;string,byte[]>")] --> |Default use profile 0| ChangeProfile(ChangeProfile) 
    Data --> |Auto save on Application pause or quit| SaveToFile(SaveToFile)--> Unity.Serialization
    Data --> |Auto load when startup| LoadFromFile(LoadFromFile)--> Unity.Serialization
    Data --> Get(Get&lt;T>) & Set(Set&lt;T>) & DeleteKey(DeleteKey) & HasKey(HasKey) & DeleteAll(DeleteAll)
    File{{File Data}} --- W & R
Loading
  • Using Unity.Serialization to serialize binary data
  • Data allows you to store data in byte[] form in blocks called profiles. Each profile is a Dictionary with the key as a string and the value as a byte[]. The default profile will be 0 if you want to Load or Save in another profile you will need to call the ChangeProfile function.

Use

  • Initialize data when loading the game: GameData.Init()
  • Change Profile: GameData.ChangeProfile(int profile)
  • Load Data: GameData.Load() Load all data from file for game, data will be loaded automatically when starting the game
  • Get Data: GameData.Get("KEY", valueDefault); use similar to PlayerPrefs
  • Set Data: GameData.Set("KEY", value); use similar to PlayerPrefs
  • Save Data: GameData.Save() data will be automatically saved when quit game or pause game.
  • Has Key: GameData.HasKey(string key) to check if the profile has a key,
  • DeleteKey: GameData.DeleteKey(string key)to delete the key from the profile
  • DeleteAll: GameData.DeleteAll() to delete the entire key
  • Backup: GameData.Backup() Get raw byte[] of all data of profile
  • Restore: GameData.Restore(byte[] bytes) Load from byte[]
Clone this wiki locally