Unity简单对话系统的优化

在对之前写的对话系统的使用过程中,发现了一些问题,这是一篇代码优化的文章,还没看过的小伙伴可以看一下Unity简单对话系统的实现

1、场景上

在场景中,我们把左右角色对话的左右分别单独创建

2、代码上

我们把对话双方的头像或者立绘和名字存储在对话的数据文件中

using System;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu( menuName = "对话/DialogueData")]
public class DialogueData : ScriptableObject
{
	public int ID;
	public List<Dialogue> dialogueList;
	public string speakerNameLeft;
	public string speakerNameRight;
	public Sprite speakerLeft;
	public Sprite speakerRight;

	
}


[Serializable]
public class Dialogue
{
	public Row row;
	[TextArea(5,4)]
	public string speech;
	public List<Choose> chooseList = new List<Choose>();//对话是否有选项
}
[Serializable]
public class Choose
{
    public int ID;
    public string chooseBtnText;
}

3、DialoguePanel中

获取刚创建的组件

4、DialogueSystem中

同步信息方法改为同步到对话数据中的内容

在根据角色位置切换显示的方法中改为根据角色位置切换对应图片的显隐

最后在相应位置赋值即可

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值