76 lines
2.0 KiB
C#
76 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class ControlButtonsScript : MonoBehaviour
|
|
{
|
|
[SerializeField] private List<string> buttonTitle = new List<string>();
|
|
[SerializeField] private List<UnityEngine.UI.Button> buttonObject = new List<UnityEngine.UI.Button>();
|
|
public Dictionary<string, UnityEngine.UI.Button> buttonsDictionary { get; private set; }
|
|
|
|
List<string> activeButtons = new List<string>();
|
|
|
|
private void Awake()
|
|
{
|
|
BuildDictionary();
|
|
}
|
|
|
|
private void BuildDictionary()
|
|
{
|
|
buttonsDictionary = new Dictionary<string, UnityEngine.UI.Button>();
|
|
for (int i = 0; i < buttonTitle.Count && i < buttonObject.Count; i++)
|
|
{
|
|
buttonsDictionary[buttonTitle[i]] = buttonObject[i];
|
|
}
|
|
}
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
//Debug.Log(buttonsDictionary.Count);
|
|
disableButtons();
|
|
|
|
buttonsDictionary["Run"].interactable = true;
|
|
}
|
|
|
|
void disableButtons()
|
|
{
|
|
foreach (var button in buttonsDictionary.Values)
|
|
{
|
|
button.interactable = false;
|
|
}
|
|
activeButtons.Clear();
|
|
}
|
|
public void SetActiveButtons(List<string> buttonsToActivate)
|
|
{
|
|
if (activeButtons.SequenceEqual(buttonsToActivate)) return;
|
|
|
|
disableButtons();
|
|
foreach (var button in buttonsToActivate)
|
|
{
|
|
buttonsDictionary[button].interactable = true;
|
|
}
|
|
|
|
activeButtons = buttonsToActivate;
|
|
}
|
|
|
|
public void RunButtonAction()
|
|
{
|
|
disableButtons();
|
|
buttonsDictionary["Pause"].interactable = true;
|
|
buttonsDictionary["Stop"].interactable = true;
|
|
}
|
|
public void PauseButtonAction()
|
|
{
|
|
disableButtons();
|
|
buttonsDictionary["Run"].interactable = true;
|
|
buttonsDictionary["Stop"].interactable = true;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|