Files
ichni_Official/Assets/Scripts/Story/StoryUI/DialogUI/ChoiceGroupUI.cs
SoulliesOfficial b19469976a Menu基本完成
2025-06-14 14:42:49 -04:00

45 lines
1.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using I2.Loc;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Ichni.Story.UI
{
public class ChoiceGroupUI : MonoBehaviour
{
public GameObject choiceButtonPrefab;
public RectTransform container;
public List<Button> choiceButtonList;
public string choiceName;
public int choiceIndex;
public void Initialize(ChoiceGroup choiceGroup)
{
this.choiceName = choiceGroup.choiceName;
choiceButtonList = new List<Button>();
for (var index = 0; index < choiceGroup.choices.Count; index++)
{
var choice = choiceGroup.choices[index];
int cIndex = index; // Capture the current index for the listener
GameObject choiceButton = Instantiate(choiceButtonPrefab, container);
choiceButton.GetComponentInChildren<Localize>().SetTerm(ChapterSelectionManager.instance.currentChapter + "/" + choice.choiceText);
choiceButton.GetComponent<Button>().onClick.AddListener(() =>
{
DialogManager.instance.PlayNextDialogParagraph(choice.nextDialogName);
DialogManager.instance.isPlayingChoice = false;
choiceButtonList.ForEach(b => b.interactable = false);
DialogManager.instance.PlayDialog();
this.choiceIndex = cIndex;
GameSaveManager.instance.StorySaveModule.selectedChoices[choiceName] = cIndex;
});
choiceButtonList.Add(choiceButton.GetComponent<Button>());
}
}
}
}