您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
40 行
988 B
40 行
988 B
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIHeartDisplay : MonoBehaviour
|
|
{
|
|
[SerializeField] Image _slidingImage = default;
|
|
[SerializeField] Image _combatBackgroundImage = default;
|
|
[SerializeField] Image _backgroundImage = default;
|
|
|
|
[Header("Listening on")]
|
|
[SerializeField] BoolEventChannelSO _combatStateEvent = default;
|
|
|
|
private void OnEnable()
|
|
{
|
|
_combatStateEvent.OnEventRaised += OnCombatState;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
_combatStateEvent.OnEventRaised -= OnCombatState;
|
|
}
|
|
|
|
public void SetImage(float percent)
|
|
{
|
|
_slidingImage.fillAmount = percent;
|
|
if (percent == 0f)
|
|
{
|
|
_backgroundImage.color = new Color(_backgroundImage.color.r, _backgroundImage.color.g, _backgroundImage.color.b, 0.5f);
|
|
}
|
|
else
|
|
{
|
|
_backgroundImage.color = new Color(_backgroundImage.color.r, _backgroundImage.color.g, _backgroundImage.color.b, 1f);
|
|
}
|
|
}
|
|
|
|
private void OnCombatState(bool isCombat)
|
|
{
|
|
_combatBackgroundImage.gameObject.SetActive(isCombat);
|
|
}
|
|
}
|