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