mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-27 11:54:41 +00:00
73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
|
using System;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
/// <summary>
|
|||
|
/// Dialog Example
|
|||
|
/// Multiple event calls to modify the contents of a dialog box are not recommended,
|
|||
|
/// Usually, I will choose to conduct actual dialogue development in combination with some kind of configuration table system,
|
|||
|
/// But doing so here can make users learn BehaviorTreeSystem more simply and clearly
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĶԻ<C4B6><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ֵ<EFBFBD><D6B5><EFBFBD>Ƽ<EFBFBD><C6BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><C2A3>һ<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>ʵ<EFBFBD>ʶԻ<CAB6><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ѧϰ<D1A7><CFB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2B5A5BA><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
///
|
|||
|
/// The behavior tree can quickly build a dialogue system and speed up the development of the plot system
|
|||
|
/// <20><>Ϊ<EFBFBD><CEAA><EFBFBD>ܿ<EFBFBD><DCBF>ٵĹ<D9B5><C4B9><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>Ի<EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5>Ŀ<EFBFBD><C4BF><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
public class Example2 : MonoBehaviour
|
|||
|
{
|
|||
|
[SerializeField]
|
|||
|
Transform m_grid;
|
|||
|
[SerializeField]
|
|||
|
BehaviorTreeSlayer.BehaviorTree behaviorTree;
|
|||
|
[SerializeField]
|
|||
|
Texture2D[] icons;
|
|||
|
[SerializeField]
|
|||
|
Text label;
|
|||
|
[SerializeField]
|
|||
|
RawImage portrait;
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
behaviorTree.Regist("SetIcon", SetIcon);
|
|||
|
behaviorTree.Regist("SetText", SetText);
|
|||
|
behaviorTree.Regist("SetBtns", SetBtns);
|
|||
|
}
|
|||
|
|
|||
|
private void SetBtns(object obj)
|
|||
|
{
|
|||
|
int count = (int)obj;
|
|||
|
for (int i = 0; i < count; i++)
|
|||
|
{
|
|||
|
m_grid.GetChild(i).gameObject.SetActive(true);
|
|||
|
}
|
|||
|
for (int i = count; i < m_grid.childCount; i++)
|
|||
|
{
|
|||
|
m_grid.GetChild(i).gameObject.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
private void OnDestroy()
|
|||
|
{
|
|||
|
behaviorTree.UnRegist("SetIcon");
|
|||
|
behaviorTree.UnRegist("SetText");
|
|||
|
behaviorTree.UnRegist("SetBtns");
|
|||
|
}
|
|||
|
private void SetText(object obj)
|
|||
|
{
|
|||
|
//Please notice that sometimes, \n maybe auto translate to \\n
|
|||
|
label.text = obj.ToString().Replace("\\n", "\n");
|
|||
|
}
|
|||
|
|
|||
|
private void SetIcon(object obj)
|
|||
|
{
|
|||
|
int idx = (int)obj;
|
|||
|
portrait.texture = icons[idx % icons.Length];
|
|||
|
}
|
|||
|
|
|||
|
public void OnClick(int x)
|
|||
|
{
|
|||
|
behaviorTree["index"] = x;
|
|||
|
behaviorTree.Dispatch("EvtIndex", behaviorTree);
|
|||
|
}
|
|||
|
|
|||
|
}
|