Сделал работу кнопок программы, начал делать настройки
This commit is contained in:
1 parent
9e7457b818
commit
a3cccd5530
30 files changed
+15837
-17296
No files matched your search
@@ -0,0 +1,75 @@
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user