72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class MinionBar : MonoBehaviour {
|
|
|
|
List<GameObject> minionTypes;
|
|
public GameObject minionIconPrefab;
|
|
|
|
List<MinionIcon> minionIcons;
|
|
int currentIndex;
|
|
|
|
void Awake() {
|
|
minionTypes = new List<GameObject>();
|
|
minionIcons = new List<MinionIcon>();
|
|
}
|
|
|
|
// public void Start() {
|
|
// minionIcons = new List<MinionIcon>();
|
|
// for (int i=0; i<minionTypes.Count; ++i) {
|
|
// GameObject newIconObj = Instantiate(minionIconPrefab, transform);
|
|
// minionIcons.Add(newIconObj.GetComponent<MinionIcon>());
|
|
// // minionIcons[i].icon = minionTypes.icon; // TODO
|
|
// minionIcons[i].indexInMinionList = i;
|
|
// minionIcons[i].UnSelect();
|
|
// }
|
|
// minionIcons[currentIndex].Select();
|
|
// }
|
|
|
|
public void ChangeSelectedIcon(InputAction.CallbackContext context) {
|
|
|
|
float floatDelta = context.ReadValue<float>();
|
|
int delta = 0;
|
|
if(floatDelta > 0.5f) {
|
|
delta = 1;
|
|
} else if(floatDelta < -0.5f) {
|
|
delta = -1;
|
|
}
|
|
|
|
minionIcons[currentIndex].UnSelect();
|
|
|
|
currentIndex += delta;
|
|
if(currentIndex >= minionIcons.Count) {
|
|
currentIndex = 0;
|
|
} else if(currentIndex < 0) {
|
|
currentIndex = minionIcons.Count - 1;
|
|
}
|
|
|
|
minionIcons[currentIndex].Select();
|
|
// print("new selected minion type : " + currentIndex.ToString());
|
|
}
|
|
|
|
public void AddMinionType(GameObject newMinionPrefab) {
|
|
minionTypes.Add(newMinionPrefab);
|
|
MinionIcon newIcon = Instantiate(minionIconPrefab, transform).GetComponent<MinionIcon>();
|
|
minionIcons.Add(newIcon);
|
|
// minionIcons[i].icon = minionTypes.icon; // TODO
|
|
newIcon.indexInMinionList = minionIcons.Count;
|
|
if(currentIndex == minionIcons.Count - 1) {
|
|
newIcon.Select();
|
|
} else {
|
|
newIcon.UnSelect();
|
|
}
|
|
}
|
|
|
|
public GameObject GetCurrentMinion() {
|
|
return minionTypes[currentIndex];
|
|
}
|
|
|
|
}
|