예제 #1
0
    public static bool TryLoad(DataName dataName, out float dataOut)
    {
        string key = "F_" + dataName.ToString();

        dataOut = PlayerPrefs.GetFloat(key);
        return(PlayerPrefs.HasKey(key));
    }
예제 #2
0
        public static void ToStringTest(string value)
        {
            var instance = new DataName(value);

            var strValue = instance.ToString();

            // セットした値と取得した値が一致すること
            Assert.AreEqual(strValue, value);
        }
예제 #3
0
    public static void Save <T>(DataName dataName, T data)
    {
        string key = typeof(T) + "_" + dataName.ToString();

        if (SavedData.TryGetValue(key, out object thisData))
        {
            SavedData[key] = data;
        }
        else
        {
            SavedData.Add(key, data);
        }

        string JsonString = JsonConvert.SerializeObject(data);

        PlayerPrefs.SetString(key, JsonString);
    }
예제 #4
0
    public static bool TryLoad <T>(DataName dataName, out T dataOut)
    {
        dataOut = default;
        string key = typeof(T) + "_" + dataName.ToString();

        if (SavedData.TryGetValue(key, out object thisData))
        {
            dataOut = (T)thisData;
            return(true);
        }

        if (PlayerPrefs.HasKey(key))
        {
            string JsonString = PlayerPrefs.GetString(key, "");
            dataOut = JsonConvert.DeserializeObject <T>(JsonString);
            SavedData.Add(key, dataOut);
            return(true);
        }

        Debug.LogWarning("Cannot Load Data : " + key);
        return(false);
    }
예제 #5
0
    public static void Save(DataName dataName, float data)
    {
        string key = "F_" + dataName.ToString();

        PlayerPrefs.SetFloat(key, data);
    }
예제 #6
0
    public static void Save(DataName dataName, int data)
    {
        string key = "I_" + dataName.ToString();

        PlayerPrefs.SetInt(key, data);
    }