question with multiple choise system
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using Assets.Scripts.Actions;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ConversationController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public TextMeshProUGUI _title;
|
||||
[SerializeField]
|
||||
public Button _choiceButton;
|
||||
|
||||
private List<ChoiceController> choiceControllers = new();
|
||||
public static ConversationController Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
Hide();
|
||||
}
|
||||
|
||||
public void Change(string title, Dictionary<string, BaseAction> options)
|
||||
{
|
||||
RemoveChoices();
|
||||
_title.text = title;
|
||||
gameObject.SetActive(true);
|
||||
|
||||
for (var count = 0; count < options.Count; count++)
|
||||
{
|
||||
ChoiceController c = ChoiceController.AddChoiceButton(_choiceButton, options.ElementAt(count), count);
|
||||
choiceControllers.Add(c);
|
||||
}
|
||||
|
||||
_choiceButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void RemoveChoices()
|
||||
{
|
||||
foreach (ChoiceController c in choiceControllers)
|
||||
Destroy(c.gameObject);
|
||||
|
||||
choiceControllers.Clear();
|
||||
}
|
||||
public void Hide()
|
||||
{
|
||||
RemoveChoices();
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user