Example #1
0
    public void SaveConfigure(BuildTarget buildTarget)
    {
        if (!IsValidBuildTarget(buildTarget))
        {
            Debug.LogError("buildTarget Is InValid ");
            return;
        }
        string path = ConfigureFilePath(buildTarget);

        if (configure == null)
        {
            configure = RefelctionHelper.CreateNew <T>();
        }
        string resultJson = JsonUtility.ToJson(configure);

        File.WriteAllText(path, resultJson);
        Debug.Log(string.Format("Configure saved at {0}!", path));
    }
Example #2
0
    public bool ReadConfigure(BuildTarget buildTarget)
    {
        if (!IsValidBuildTarget(buildTarget))
        {
            Debug.LogError("buildTarget Is InValid ");
            return(false);
        }
        string path = ConfigureFilePath(buildTarget);

        if (File.Exists(path))
        {
            string alltext = File.ReadAllText(path);
            try
            {
                configure = JsonUtility.FromJson <T>(alltext);
                return(true);
            }
            catch
            {
                Debug.LogError(path + " Configure parse failed! ");
                return(false);
            }
        }
        else
        {
            Debug.LogError(path + " Configure Not Exit!");
            configure = RefelctionHelper.CreateNew <T>();
            string jsonstr = JsonUtility.ToJson(configure);
            if (!Directory.Exists(ConfigureRootPath()))
            {
                Directory.CreateDirectory(ConfigureRootPath());
            }
            File.WriteAllText(path, jsonstr);
            Debug.Log(string.Format("Configure created at {0}!", path));
            return(false);
        }
    }