feat(dialog): 重构选项已选状态视觉表现

This commit is contained in:
2026-05-25 18:43:23 +08:00
parent 7e579a2eb0
commit db5fbb0cb8
5 changed files with 15 additions and 142 deletions
+2 -78
View File
@@ -143,7 +143,6 @@ MonoBehaviour:
text: {fileID: 6343862642438606438}
button: {fileID: 3624986506224747444}
arrow: {fileID: 2138736795402918014}
selectedSign: {fileID: 994585125679848239}
colorBlock:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.4, g: 0.4, b: 0.4, a: 1}
@@ -152,6 +151,7 @@ MonoBehaviour:
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 0
m_FadeDuration: 0
selectedColor: {r: 0.5471698, g: 0.5471698, b: 0.5471698, a: 1}
--- !u!114 &9163890225660695161
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -192,81 +192,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_HorizontalFit: 2
m_VerticalFit: 0
--- !u!1 &4507535836329041407
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2100970350256881776}
- component: {fileID: 2572548913308526007}
- component: {fileID: 994585125679848239}
m_Layer: 5
m_Name: SelectSign
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &2100970350256881776
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4507535836329041407}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8909982681958940574}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0.5}
m_AnchorMax: {x: 1, y: 0.5}
m_AnchoredPosition: {x: 8, y: 0}
m_SizeDelta: {x: 16, y: 16}
m_Pivot: {x: 0, y: 0.5}
--- !u!222 &2572548913308526007
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4507535836329041407}
m_CullTransparentMesh: 1
--- !u!114 &994585125679848239
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4507535836329041407}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 566787ba43e2a5646bdabb62bd6845f2, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &4951730373337149047
GameObject:
m_ObjectHideFlags: 0
@@ -372,8 +297,7 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 2100970350256881776}
m_Children: []
m_Father: {fileID: 1274478104802664553}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
+4
View File
@@ -14667,6 +14667,10 @@ PrefabInstance:
propertyPath: m_Name
value: OnelineBox
objectReference: {fileID: 0}
- target: {fileID: 8352794458094198668, guid: 60f4427b2070be04f90c1486bb86062c, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
+1 -43
View File
@@ -1,6 +1,5 @@
#nullable enable
using System.Collections.Generic;
using System.Threading.Tasks;
using AibisDream.Framework;
using UnityEngine;
@@ -10,7 +9,6 @@ namespace AibisDream
{
public class OptionView : DialoguePresenterBase
{
private HashSet<string> _selectedIds = new();
[SerializeField] private DefaultOptions defaultOptions;
[SerializeField] private CenterOptions centerOptions;
[SerializeField] private OnelineOptions onelineOptions;
@@ -31,7 +29,6 @@ namespace AibisDream
{
return YarnTask.CompletedTask;
}
public void LoadBubbles(BubbleSlotGroupData data)
{
defaultViewType = data.dialogViewType;
@@ -44,7 +41,7 @@ namespace AibisDream
var options = DialogOption.GeneOptions(dialogueOptions, optionId =>
{
optionSelectedSource.TrySetResult(optionId);
}, _selectedIds);
});
var viewType = GetCurrentViewType(options);
@@ -101,45 +98,6 @@ namespace AibisDream
return optionViewType;
}
// --------------------------- 生命周期方法 ---------------------------
private void OnEnable()
{
RegisterEvent();
}
private void OnDisable()
{
UnRegisterEvent();
}
private void RegisterEvent()
{
// 进入游戏或者进入下一个Yarn的时候清空
EnumEventSystem.Global.Register(GameLoopEnum.GameStart, ClearSelectedIds);
EnumEventSystem.Global.Register(EventEnum.NextYarn, ClearSelectedIds);
// 选择选项的时候记录
EnumEventSystem.Global.Register<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected, RecordSelectedId);
}
private void UnRegisterEvent()
{
EnumEventSystem.Global.UnRegister(GameLoopEnum.GameStart, ClearSelectedIds);
EnumEventSystem.Global.UnRegister(EventEnum.NextYarn, ClearSelectedIds);
EnumEventSystem.Global.UnRegister<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected, RecordSelectedId);
}
private void ClearSelectedIds()
{
_selectedIds.Clear();
}
private void RecordSelectedId(LineInfo lineInfo)
{
_selectedIds.Add(lineInfo.lineId);
}
public void HideDialog()
{
defaultOptions.HideOptions();
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Collections.Generic;
using AibisDream.Framework;
@@ -15,7 +15,6 @@ namespace AibisDream
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();
@@ -51,21 +50,6 @@ namespace AibisDream
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]
@@ -11,11 +11,12 @@ namespace AibisDream
[SerializeField] private TMP_Text text;
[SerializeField] private BaseButton button;
[SerializeField] private Image arrow;
[SerializeField] private Image selectedSign;
[Header("颜色配置")]
[SerializeField] private ColorBlock colorBlock;
[Header("已选择颜色")]
[SerializeField] private Color selectedColor;
private DialogOption _option;
public void Init()
@@ -35,8 +36,6 @@ namespace AibisDream
return;
}
selectedSign.gameObject.SetActive(option.IsSelected);
text.SetText(option.Line);
button.onClick.AddListener(() =>
{
@@ -72,11 +71,15 @@ namespace AibisDream
}
}
private Color GetNormalColor()
{
return colorBlock.normalColor;
}
private void SetColor(Color color)
{
arrow.color = color;
text.color = color;
selectedSign.color = color;
}
}
}