Esempio n. 1
0
        private static T ReadFromJson <T>(string filePath, bool createIfNot = true) where T : class, new()
        {
            T data = null;

            if (File.Exists(filePath))
            {
                data = (T)JsonUtility.FromJsonWithType(File.ReadAllText(filePath));
            }
            if (data == null && createIfNot)
            {
                data = new T();
            }
            return(data);
        }
Esempio n. 2
0
        private static void WriteAsJson <T>(string filePath, T data) where T : class, new()
        {
            string dir = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(dir))
            {
                if (!Directory.CreateDirectory(dir).Exists)
                {
                    Debug.LogError("CheckerUtility::SaveAsJson->Create dir failed.dir = " + dir);
                    return;
                }
            }
            File.WriteAllText(filePath, JsonUtility.ToJsonWithType(data));
        }