Files
SL1900 5e0d58cfad Initial version - 1.2.0.60
EN: 1.2.0.60
CN: 1.2.0.61
JP: 1.2.0.63
KR: 1.2.0.67
2025-12-03 01:00:00 +09:00

57 lines
1.7 KiB
Lua

local RapidJson = require("rapidjson")
local String = CS.System.String
local PlayerPrefs = CS.UnityEngine.PlayerPrefs
local LocalData = {}
function LocalData.SetLocalData(sMainKey, sSubKey, sValue)
local sJson = PlayerPrefs.GetString(sMainKey)
local mapData
if String.IsNullOrEmpty(sJson) == true then
mapData = {}
mapData[sSubKey] = sValue
else
mapData = RapidJson.decode(sJson)
mapData[sSubKey] = sValue
end
sJson = RapidJson.encode(mapData)
PlayerPrefs.SetString(sMainKey, sJson)
PlayerPrefs.Save()
end
function LocalData.GetLocalData(sMainKey, sSubKey)
local sJson = PlayerPrefs.GetString(sMainKey)
if String.IsNullOrEmpty(sJson) == true then
return nil
else
local mapData = RapidJson.decode(sJson)
return mapData[sSubKey]
end
end
function LocalData.DelLocalData(sMainKey, sSubKey)
local sJson = PlayerPrefs.GetString(sMainKey)
if String.IsNullOrEmpty(sJson) == false then
local mapData = RapidJson.decode(sJson)
mapData[sSubKey] = nil
sJson = RapidJson.encode(mapData)
PlayerPrefs.SetString(sMainKey, sJson)
PlayerPrefs.Save()
end
end
function LocalData.SetPlayerLocalData(sKey, sValue)
local nPlayerId = PlayerData.Base:GetPlayerId()
if type(nPlayerId) == "number" then
LocalData.SetLocalData(tostring(nPlayerId), sKey, sValue)
end
end
function LocalData.GetPlayerLocalData(sKey)
local nPlayerId = PlayerData.Base:GetPlayerId()
if type(nPlayerId) == "number" then
return LocalData.GetLocalData(tostring(nPlayerId), sKey)
end
end
function LocalData.DelPlayerLocalData(sKey)
local nPlayerId = PlayerData.Base:GetPlayerId()
if type(nPlayerId) == "number" then
LocalData.DelLocalData(tostring(nPlayerId), sKey)
end
end
return LocalData