๐บ๏ธ PlayerSave
PlayerSave โ Persistent Save System
The PlayerSave
class is a static high-level API for saving and retrieving all persistent data in the game, such as nickname, level, items, coins, stats, color, selected clothes, and more.
It automatically handles encryption, serialization (for complex types), and saving behind the scenes through the configured ILocalSaveProvider
. No need to manually call PlayerPrefs.Save()
.
๐พ What It Does
Stores and retrieves player data using
SetString
,SetInt
,SetFloat
(encrypted under the hood)Automatically saves after every change
Supports:
๐ง Nickname, pet ID, level, EXP
๐ฆ Item quantities (dictionary-based)
๐ฎ High Scores
๐ Selected clothes and food
๐งผ Stat values (like hygiene, hunger)
๐ฐ Multiple coin types (by ID)
๐จ Pet color customization
โฑ Offline stat decay timestamp
Raises events like
OnCurrencyChanged
,OnStatsChanged
,OnExpChanged
๐ง How It Works
Uses an
ILocalSaveProvider
(default:PlayerPrefsSaveProvider
)Each call to
SetInt
,SetString
, etc.:Encrypts and stores the value
Automatically triggers
provider.Save()
Uses JSON serialization for complex data (e.g., inventory)
Data is saved securely in
PlayerPrefs
, but can be swapped to a cloud or custom provider
๐ง Built-In Keys
Nickname
PLAYER_NICK
"FluffyCat"
Pet ID
PLAYER_PET
0
, 1
, 2
...
Level / Exp
PLAYER_LVL
, PLAYER_EXP
5
, 1500
Stat
STAT_{statName}
STAT_Hygiene
Coins
COIN_{coinId}
COIN_Gold
Scores
SCORE_{mode}
SCORE_FlappyPet
Items
ITEMS_JSON
JSON-encoded inventory
Food
SELECTED_FOOD
"apple_01"
Clothes
SELECTED_CLOTHES_{slot}
"hat_02"
Pet Color
PET_COLOR
#FFCC99FF
Last Update
PET_LAST_STAT_UPDATE
UTC Ticks (as string)
๐ฅ Saving Data
You donโt need to call PlayerPrefs.Save()
โ just use the functions below:
This will encrypt, store, and save automatically.
๐ค Reading Data
You can retrieve saved values using the matching Get
functions:
๐ฆ Item System (Dictionary-based)
Items are stored in a JSON dictionary behind the scenes:
๐ฎ Scores, Stats & Coins
๐จ Clothes, Food & Color
โฑ Offline Stat Decay
Used to calculate how much time has passed offline for stat decay (hunger, hygiene, etc.)
๐งช Switching Save Backend
If needed, you can replace the save provider with your own implementation:
Your class must implement ILocalSaveProvider
.
โ
Highlights
๐ Encrypted & auto-saving system
๐ง Uses standard APIs:
SetString
,GetInt
, etc.๐งฑ Structured: supports stats, coins, scores, food, clothes
๐ Ready for cloud migration (via provider interface)
Last updated