50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Actions;
|
|
using UnityEngine;
|
|
|
|
namespace UI {
|
|
public class UnitActionSystemUI : MonoBehaviour {
|
|
[SerializeField] private Transform ActionButtonPrefab;
|
|
[SerializeField] private Transform ActionButtonContainerTransform;
|
|
|
|
private List<ActionButtonUI> actionButtonUIList;
|
|
|
|
private void Awake() => actionButtonUIList = new();
|
|
|
|
private void Start() {
|
|
UnitActionSystem.Instance.OnSelectedUnitChanged += UnitActionSystem_OnSelectedUnitChanged;
|
|
UnitActionSystem.Instance.OnSelectedActionChanged += UnitActionSystem_OnSelectedActionChanged;
|
|
CreateUnitActionButtons();
|
|
UpdateSelectedVisual();
|
|
}
|
|
|
|
private void UnitActionSystem_OnSelectedActionChanged(object sender, EventArgs e) => UpdateSelectedVisual();
|
|
|
|
private void UnitActionSystem_OnSelectedUnitChanged(object sender, EventArgs e) {
|
|
CreateUnitActionButtons();
|
|
UpdateSelectedVisual();
|
|
}
|
|
|
|
private void CreateUnitActionButtons() {
|
|
foreach (Transform buttonTransform in ActionButtonContainerTransform) {
|
|
Destroy(buttonTransform.gameObject);
|
|
}
|
|
|
|
actionButtonUIList.Clear();
|
|
|
|
foreach (BaseAction baseAction in UnitActionSystem.Instance.SelectedUnit.BaseActionArray) {
|
|
Transform actionButtonTransform = Instantiate(ActionButtonPrefab, ActionButtonContainerTransform);
|
|
ActionButtonUI actionButtonUI = actionButtonTransform.GetComponent<ActionButtonUI>();
|
|
actionButtonUI.SetBaseAction(baseAction);
|
|
actionButtonUIList.Add(actionButtonUI);
|
|
}
|
|
}
|
|
|
|
private void UpdateSelectedVisual() {
|
|
foreach (ActionButtonUI actionButtonUI in actionButtonUIList) {
|
|
actionButtonUI.UpdateSelectedVisual();
|
|
}
|
|
}
|
|
}
|
|
} |