Files
aibis-dream/Assets/Scripts/UI/DialogUI/DialogOption.cs
T
dingyuntian 0168b03234 1.4优化
1. 新建梦境专用场景
2. 增加单行对话框,梦境中全程使用该对话框
3. 增加已选择选项标记功能

TODO
1. 增加梦境选择框
2. 为选项增加已选择表现
2026-01-02 23:19:06 +08:00

78 lines
2.4 KiB
C#

using System;
using System.Linq;
using System.Collections.Generic;
using AibisDream.Framework;
using AibisDream.Kit;
using AibisDream.Utility;
using UnityEngine;
using Yarn.Unity;
namespace AibisDream
{
public struct DialogOption
{
private Action<int> _onOptionSelected;
private DialogueOption _option;
public bool IsAvailable => _option.IsAvailable;
public bool IsSelected { get; private set; }
public string Line => _option.Line.TextWithoutCharacterName.Text;
public CharacterVo Character => _option.Line.GetCharacterVo();
/// <summary>
/// 选择该选项
/// </summary>
public void Select()
{
if (!_option.IsAvailable)
{
Debug.Log($"{_option.Line} 不可用");
return;
}
EnumEventSystem.Global.Send(DialogEventEnum.OptionSelected, TransToLine());
_onOptionSelected.Invoke(_option.DialogueOptionID);
}
private LineInfo TransToLine()
{
return new LineInfo
{
isOption = true,
lineId = _option.TextID,
lineText = _option.Line.TextWithoutCharacterName.Text,
character = _option.Line.GetCharacterVo(),
isAutoSkip = false
};
}
public static DialogOption[] GeneOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
{
return dialogueOptions
.Select(item => new DialogOption { _option = item, _onOptionSelected = onOptionSelected }).ToArray();
}
public static DialogOption[] GeneOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected, HashSet<string> selectedIds)
{
var options = new List<DialogOption>();
foreach (var item in dialogueOptions)
{
var option = new DialogOption { _option = item, _onOptionSelected = onOptionSelected };
if (selectedIds.Contains(option._option.TextID))
{
option.IsSelected = true;
}
options.Add(option);
}
return options.ToArray();
}
}
[Serializable]
public struct TextParam
{
public float charSpace;
public float lineSpace;
public int maxCharNum;
}
}