Skip to content
DucNV_2000 edited this page Aug 5, 2024 · 5 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 \n Profile 0\n .\n.\n.\n Profile N \n Dictionary&ltstring,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<T>) & Set(Set&ltT>) & 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