Unity は SharpConfig を使用して構成ファイルを読み取り、変更します

gamesetting.cfg は、streamingAssets の下に配置されます

[GameStting]
name = gamesetting

[Test]
name = newName

[Array]
name = {123,345,567,879}

SharpConfig を使用します。

 

設定ファイルをロードする

    public void Load()
    {
        string filepath = Application.streamingAssetsPath + "/gamesetting.cfg";
        Configuration cfg = Configuration.LoadFromFile(filepath);

        Section gamesetting = cfg["GameStting"];
        string name = gamesetting["name"].StringValue;

        Section test = cfg["Test"];
        string name1 = test["name"].StringValue;

        Debug.Log(name + "     " + name1);
    }

 

設定ファイルを変更する

   public void SaveCon()
    {
        Configuration cfg = new Configuration();
        string filepath = Application.streamingAssetsPath + "/gamesetting.cfg";

        Section gamesetting = new Section("GameStting");
        gamesetting.Add(new Setting("name", "gamesetting"));
        cfg.Add(gamesetting);

        Section test = new Section("Test");
        test.Add(new Setting("name", "newName"));
        cfg.Add(test);

        string[] str = { "123", "345", "567", "879" };
        Section array = new Section("Array");
        array.Add(new Setting("name", str));
        cfg.Add(array);

        cfg.SaveToFile(filepath);
    }

 

おすすめ

転載: blog.csdn.net/LuffyZ/article/details/106237719