54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class MinionBar : MonoBehaviour {
|
|
|
|
public Object[] minionTypes;
|
|
public GameObject minionIconPrefab;
|
|
|
|
MinionIcon[] minionIcons;
|
|
int currentIndex;
|
|
|
|
public void Start() {
|
|
minionIcons = new MinionIcon[minionTypes.Length];
|
|
for (int i=0; i<minionTypes.Length; ++i) {
|
|
GameObject newIconObj = Instantiate(minionIconPrefab, transform);
|
|
minionIcons[i] = 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.Length) {
|
|
currentIndex = 0;
|
|
} else if(currentIndex < 0) {
|
|
currentIndex = minionIcons.Length - 1;
|
|
}
|
|
|
|
minionIcons[currentIndex].Select();
|
|
// print("new selected minion type : " + currentIndex.ToString());
|
|
}
|
|
|
|
public Object GetCurrentMinion() {
|
|
return minionTypes[currentIndex];
|
|
}
|
|
|
|
}
|