剧情
This commit is contained in:
45
Assets/Scripts/Story/StoryUI/DialogUI/ChoiceGroupUI.cs
Normal file
45
Assets/Scripts/Story/StoryUI/DialogUI/ChoiceGroupUI.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
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(StoryManager.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>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user