对话框系统好难呀,我还是整不出来。

还是没整出来,哭了!

img


public class Dialog : MonoBehaviour {
    public Image Meimage;//获取图片
    public Image AIimage;//获取图片
    public TextAsset Filetext;//获取文本文件
    public Text Nametext;//读取的人名
    public Text Dialogtext;//获取对话的文本框
    public Button button;//定义对话继续按钮
    public GameObject optionbutton;//选项预设体
    public Transform buttongroup;//选项按钮父节点,用于自动排序
    public string[] dialogRaws;
    public int dialogIndex;//所以创建变量dialogIndex 有来保存当前对话索引从0开始,对话文本按行分割

    public List<Sprite> sprites = new List();//创建列表 角色图片列表

   public Dictionary<string, Sprite> imageDic = new Dictionary<string, Sprite>();//角色名字对应图片字典  将从角色名字对应图片

    private void Awake()
    {
        imageDic["AI"] = sprites[0];
        imageDic["Me"] = sprites[1];
    }


    // Use this for initialization
    void Start () {
        ReadText(Filetext);//读取文件
        ShowDialogRaws();
        
    }
    
    // Update is called once per frame
    void Update () {
        
    }
    public void UpdateText(string _name, string _text) {
        Nametext.text = _name;//人名,和说话内容的更新
        Dialogtext.text = _text;
    }
    public void UpdateImage(string _name, string _position)
    {//图像 更新图片 调用图像 
        if (_position == "左")
        {
            Meimage.sprite = imageDic[_name];
      

        }
        else if (_position == "右") {
           AIimage.sprite = imageDic[_name];
         
        }
    }
    //创建一个 读取我们的文件 一行一行读取 读取filetext 
    public void ReadText(TextAsset _textAsset) {
        dialogRaws = _textAsset.text.Split('\n');
    }

    public void ShowDialogRaws()
    {//显示对话行的脚本,函数,去显示  所以创建变量dialogIndex 有来保存当前对话索引从0开始
        for (int i = 0; i < dialogRaws.Length;i++)
        {
            string[] cells = dialogRaws[i].Split('\t');
            {
                if (cells[0] == "#" && int.Parse(cells[1]) == dialogIndex)//判断是不是# 
                {
                    UpdateText(cells[2], cells[4]);
                    UpdateImage(cells[2], cells[3]);

                    dialogIndex = int.Parse(cells[5]);//更新跳转ID
                    button.gameObject.SetActive(true);
                    break;
                }
                else if (cells[0] == "&" && int.Parse(cells[1]) == dialogIndex)//
                {
                    button.gameObject.SetActive(false);
                    GenerateOption(i);
                }
                else if (cells[0] == "END" && int.Parse(cells[1]) == dialogIndex)
                {
                    Debug.Log("结束");
                }
            }

        }
    }
    public void OnClikNext()
    {
        ShowDialogRaws();
        Debug.Log("再一次完成!");
    }
    public void GenerateOption(int _index)
    {
        string[] cells = dialogRaws[_index].Split('\t');
        if (cells[0] == "&")
        {
            //绑定按钮事件,前面button继续后跳转到这里进行选择,并且进行下一步。
            GameObject button = Instantiate(optionbutton, buttongroup);
            button.GetComponentInChildren().text = cells[4];//获取button组件 预设那个Text通过孩子组件,赋予cellos
            button.GetComponent

你写一个最简单的程序, 把对话框做出来。

太难了,肯定是字典问题,关键是,我也找不出哪错了 哎