u3d中數據存儲

Unity3D中的PlayerPrefs這個類。這個類中一共幫助咱們封裝了9個方法,用來數據的儲存與讀取spa

PlayerPrefs.SetString("key", "value");string

string str = PlayerPrefs.GetString("key", "defaule"));it

咱們發現它是以鍵值對的形式進行儲存與讀取,每個Key對應一個Value,儲存事後經過Key能夠獲得以前儲存的Value。這裏說 一下GetString()方法中的第二個參數, 它表明默認值。意思是若是經過第一個參數的Key沒有找到對應的Value的話GetString()方法就會返回咱們寫的第二個參數的默認值方法

//刪除 PlayerPrefs 中某一個key的值數據

PlayerPrefs. DeleteKey (key);let

//判斷 PlayerPrefs中是否存在這個key參數

bool b = PlayerPrefs.HasKey(key);封裝

相關文章
相關標籤/搜索