You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rua/Script/CharacterUIManager.cs

93 lines
3.3 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class CharacterUIManager : MonoBehaviour
{
Character self;
PointsBar healthBar;
PointsBar poiseBar;
PointsBar manaBar;
public GameObject healthDamageAmountPrefab;
public GameObject poiseDamageAmountPrefab;
public GameObject outOfMovementPrefab;
public GameObject healthRecoveryAmountPrefab;
public GameObject poiseRecoveryAmountPrefab;
public GameObject manaDamageAmountPrefab;
public GameObject manaRecoveryAmountPrefab;
private void Awake()
{
healthBar = transform.GetChild(0).GetComponent<PointsBar>();
poiseBar = transform.GetChild(1).GetComponent<PointsBar>();
manaBar = transform.GetChild(3).GetComponent<PointsBar>();
self = transform.parent.GetComponent<Character>();
}
public void ChangePoints(int amount, float ratio, int type)
{
PointsBar pointsBar = null;
GameObject amountPrefab = null;
float deltaY = 0;
float deltaX = 0.5f;
if(type == 0)
{
pointsBar = healthBar;
if(amount <= 0)
amountPrefab = healthDamageAmountPrefab;
else
amountPrefab = healthRecoveryAmountPrefab;
deltaY = 0.5f;
}
else if(type == 1)
{
pointsBar = poiseBar;
if(amount <= 0)
amountPrefab = poiseDamageAmountPrefab;
else
amountPrefab = poiseRecoveryAmountPrefab;
deltaY = 0.3f;
}
else if(type == 2)
{
pointsBar = manaBar;
if(amount <= 0)
amountPrefab = manaDamageAmountPrefab;
else
amountPrefab = manaRecoveryAmountPrefab;
deltaX = -0.5f;
deltaY = 0.7f;
}
else return;
pointsBar.ChangeUI(ratio); //根据血条或韧性条改变UI显示
Vector2 position = transform.position;
position.x += deltaX;
position.y += deltaY;
FloatingDigit(amount,amountPrefab,position);
}
public void RefreshHMPPointsBars()
{
healthBar.ChangeUI(self.GetCurrentHealth()/((float)(self.GetMaxHealth())));
poiseBar.ChangeUI(self.GetCurrentPoise()/((float)(self.GetMaxPoise())));
manaBar.ChangeUI(self.GetCurrentMana()/((float)(self.GetMaxMana())));
}
public void OutOfMovement()
{
Vector2 position = transform.position;
position.x -= 0.5f;
position.y += 0.4f;
GameObject instance = Instantiate(outOfMovementPrefab, position, Quaternion.identity);
GameObject text = instance.transform.GetChild(0).gameObject;
}
void FloatingDigit(int amount, GameObject digitPrefab, Vector2 position) //显示漂浮的数字
{
GameObject instance = Instantiate(digitPrefab,position,Quaternion.identity);
GameObject text = instance.transform.GetChild(0).gameObject;
text.GetComponent<TMP_Text>().text = amount.ToString();
}
public void FloatingString(string str)
{
GameObject instance = Instantiate(manaDamageAmountPrefab,transform.position,Quaternion.identity);
GameObject text = instance.transform.GetChild(0).gameObject;
text.GetComponent<TMP_Text>().text = str;
}
}