Merge branch 'feature/dialog-option' into develop

This commit is contained in:
2024-08-13 02:43:49 +08:00
3 changed files with 19 additions and 0 deletions
@@ -5,6 +5,7 @@
<<load_scene OptionTestScene>>
我: 加载测试场景 #line:0a67910
我: 提供两个按钮进行点击 #line:0cb2011
我: 代码部分在Asset->Scripts->Test->OptionTest #line:0344182
[command name=show_buttons /] #line:006eeaa
-> 按钮1 #line:0db0f08
我: 按下了按钮1 #line:0d84460
@@ -18,6 +18,9 @@ namespace AibisDream
this.onOptionSelected = onOptionSelected;
}
/// <summary>
/// 选项中的文字
/// </summary>
public string Text
{
get
+15
View File
@@ -13,11 +13,20 @@ namespace AibisDream.Test
void Start()
{
// 初始化时注册Command
// 第一个参数为[command name=xxx]的参数
// 第二个参数是注册的函数,在Yarn走到选择项时触发
DialogController.Instance.RegisterOptionCommand("show_buttons", ShowButtons);
// 不重要
panel = transform.GetChild(0).gameObject;
prefab = Resources.Load<GameObject>("Perfabs/UI/Choice Button");
}
/// <summary>
/// 注册的命令
/// </summary>
/// <param name="options">触发时提供的选择项</param>
public void ShowButtons(YarnOption[] options)
{
foreach (YarnOption option in options)
@@ -25,8 +34,13 @@ namespace AibisDream.Test
var instance = Instantiate(prefab);
instance.transform.SetParent(panel.transform);
instance.GetComponentInChildren<TextMeshProUGUI>().text = option.Text;
instance.GetComponent<Button>().onClick.AddListener(() => {
// 执行SelectOption(), 对话就会从对应的选项往下继续执行
option.SelectOption();
panel.SetActive(false);
});
}
@@ -34,6 +48,7 @@ namespace AibisDream.Test
public void OnDestroy()
{
// 注意在合适的时机移除命令
DialogController.Instance.RemoveOptionCommand("show_buttons");
}
}