全站通知:

模组设置面板

阅读

    

2023-11-30更新

    

最新编辑:Lu_23333

阅读:

  

更新日期:2023-11-30

  

最新编辑:Lu_23333

来自城市:天际线WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索
页面贡献者 :
xl123071
Lu_23333
施工中:欢迎协助编辑本页,请参考帮助:编辑帮助帮助:编辑规范。请从以下方面协助编辑:
  • 需要翻译

It is possible to add options in the Options panel for use in your own mods. The options panel should be used for custom settings for your mod. To enable your mod to be displayed in the Options panel, you need to implement the method OnSettingsUI() in your IUserMod class already describing your mod. (See below)

public class MyMod : IUserMod {
    public string Name { get { return "MyMod"; } }
    public string Description { get { return "My very own mod"; } }

    public void OnSettingsUI(UIHelperBase helper) {
        // Render UI elements using the UIHelperBase (see below)
    }
}

API Reference

UIHelperBase AddGroup(string text);
object AddButton(string text, OnButtonClicked eventCallback);
object AddSpace(int height);
object AddCheckbox(string text, bool defaultValue, OnCheckChanged eventCallback);
object AddSlider(string text, float min, float max, float step, float defaultValue, OnValueChanged eventCallback);
object AddDropdown(string text, string[] options, int defaultSelection, OnDropdownSelectionChanged eventCallback);
object AddTextfield(string text, string defaultContent, OnTextChanged eventChangedCallback, OnTextSubmitted eventSubmittedCallback = null);

Example

using ICities;
using UnityEngine;

public class MyMod : IUserMod {
    public string Name { get { return "MyMod"; } }
    public string Description { get { return "My very own mod"; } }

    public void OnSettingsUI(UIHelperBase helper) {
        UIHelperBase group = helper.AddGroup("My Own Group");
        group.AddCheckbox("My Checkbox", false, (isChecked) => Debug.Log(isChecked));
        group.AddSlider("My Slider", 0, 1, 0.01f, 0.5f, (value) => Debug.Log(value));
        group.AddDropdown("My Dropdown", new string[] { "First Entry", "Second Entry", "Third Entry" }, -1, (index) => Debug.Log(index));
        group.AddSpace(250);
        group.AddButton("My Button", () => { Debug.Log("Button clicked!"); });
        group.AddTextfield("My Textfield", "Default value", (value) => Debug.Log("text changed: " + value), (value) => Debug.Log("text submitted: " + value));
    }
}

See also

说明

本文内容长期有效,适用任何游戏版本。

本页内容最初译自官方Wiki:Mod Options Panel,经双方编辑后内容可能与来源不同。