91 lines
3.4 KiB
C#
91 lines
3.4 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using TMPro;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
public class StatPanelController : MonoBehaviour {
|
|||
|
|
[SerializeField] public TextMeshProUGUI pwrText;
|
|||
|
|
[SerializeField] public TextMeshProUGUI dexText;
|
|||
|
|
[SerializeField] public TextMeshProUGUI stbText;
|
|||
|
|
[SerializeField] public TextMeshProUGUI hpText;
|
|||
|
|
[SerializeField] public TextMeshProUGUI expText;
|
|||
|
|
[SerializeField] public TextMeshProUGUI dmgText;
|
|||
|
|
|
|||
|
|
[SerializeField] public AudioClip allocateSuccessAudioClip;
|
|||
|
|
[SerializeField] public AudioClip allocateFailureAudioClip;
|
|||
|
|
|
|||
|
|
[SerializeField] public float refreshTime = 2.0f;
|
|||
|
|
|
|||
|
|
private CharacterController2D playerSource;
|
|||
|
|
|
|||
|
|
|
|||
|
|
public void Refresh() {
|
|||
|
|
Stats stats = State.state.stats;
|
|||
|
|
pwrText.text = stats.pwr.ToString() + "/" + stats.cache.totalPwr.ToString();
|
|||
|
|
dexText.text = stats.dex.ToString() + "/" + stats.cache.totalDex.ToString();
|
|||
|
|
stbText.text = stats.stb.ToString() + "/" + stats.cache.totalStb.ToString();
|
|||
|
|
hpText.text = stats.hp.ToString() + "/" + stats.cache.totalMaxHP.ToString();
|
|||
|
|
expText.text = stats.exp.ToString() + " / " + stats.level.ToString();
|
|||
|
|
dmgText.text = stats.cache.baseDamage.ToString();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void AllocateStr(bool allocateAll = false) {
|
|||
|
|
if (State.state.stats.availableStatPoints < 1) {
|
|||
|
|
playerSource.PlaySound(allocateFailureAudioClip);
|
|||
|
|
} else {
|
|||
|
|
if (allocateAll) {
|
|||
|
|
State.state.stats.allocateStat(State.state.stats.availableStatPoints);
|
|||
|
|
State.state.stats.availableStatPoints = 0;
|
|||
|
|
} else {
|
|||
|
|
State.state.stats.availableStatPoints -= 1;
|
|||
|
|
State.state.stats.allocateStat(1);
|
|||
|
|
}
|
|||
|
|
playerSource.PlaySound(allocateSuccessAudioClip);
|
|||
|
|
}
|
|||
|
|
Refresh();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void AllocateDex(bool allocateAll = false) {
|
|||
|
|
if (State.state.stats.availableStatPoints < 1) {
|
|||
|
|
playerSource.PlaySound(allocateFailureAudioClip);
|
|||
|
|
} else {
|
|||
|
|
if (allocateAll) {
|
|||
|
|
State.state.stats.allocateStat(0,State.state.stats.availableStatPoints);
|
|||
|
|
State.state.stats.availableStatPoints = 0;
|
|||
|
|
} else {
|
|||
|
|
State.state.stats.availableStatPoints -= 1;
|
|||
|
|
State.state.stats.allocateStat(0, 1);
|
|||
|
|
}
|
|||
|
|
playerSource.PlaySound(allocateSuccessAudioClip);
|
|||
|
|
}
|
|||
|
|
Refresh();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void AllocateStb(bool allocateAll = false) {
|
|||
|
|
if (State.state.stats.availableStatPoints < 1) {
|
|||
|
|
playerSource.PlaySound(allocateFailureAudioClip);
|
|||
|
|
} else {
|
|||
|
|
if (allocateAll) {
|
|||
|
|
State.state.stats.allocateStat(0, 0, State.state.stats.availableStatPoints);
|
|||
|
|
State.state.stats.availableStatPoints = 0;
|
|||
|
|
} else {
|
|||
|
|
State.state.stats.availableStatPoints -= 1;
|
|||
|
|
State.state.stats.allocateStat(0, 0, 1);
|
|||
|
|
}
|
|||
|
|
playerSource.PlaySound(allocateSuccessAudioClip);
|
|||
|
|
}
|
|||
|
|
Refresh();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public IEnumerator RefreshLoop() {
|
|||
|
|
Refresh();
|
|||
|
|
yield return new WaitForSeconds(refreshTime);
|
|||
|
|
StartCoroutine("RefreshLoop");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Awake() {
|
|||
|
|
StartCoroutine("RefreshLoop");
|
|||
|
|
playerSource = GameObject.FindGameObjectWithTag("Player").GetComponent<CharacterController2D>();
|
|||
|
|
}
|
|||
|
|
}
|