阶段性完成
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using DG.Tweening;
|
||||
using SLSFramework.General;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace SLSFramework.UI
|
||||
{
|
||||
public class AttributeBarBase : UIElementBase
|
||||
{
|
||||
public Image fillImage;
|
||||
public LerpFloat fillLerp = new LerpFloat(1f, 0.2f);
|
||||
public bool useLerpColor;
|
||||
public LerpColor fillColor;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
fillLerp = new LerpFloat(1f, 0.2f);
|
||||
}
|
||||
|
||||
public void UpdateFillImage(float currentValue, float maxValue, bool isInstant = false)
|
||||
{
|
||||
if (maxValue < 0)
|
||||
{
|
||||
Debug.LogWarning("Max value is less than zero. Cannot update fill image.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentValue <= 0)
|
||||
{
|
||||
fillImage.fillAmount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isInstant)
|
||||
{
|
||||
float targetFill = currentValue / maxValue;
|
||||
fillLerp.targetValue = targetFill;
|
||||
}
|
||||
else
|
||||
{
|
||||
fillLerp.targetValue = currentValue / maxValue;
|
||||
fillLerp.currentValue = currentValue / maxValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateFillColor(Color color, bool isInstant = false)
|
||||
{
|
||||
if (useLerpColor)
|
||||
{
|
||||
if (!isInstant)
|
||||
{
|
||||
fillColor.targetValue = color;
|
||||
}
|
||||
else
|
||||
{
|
||||
fillColor.targetValue = color;
|
||||
fillColor.currentValue = color;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fillImage.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
fillLerp.Update(1);
|
||||
fillImage.fillAmount = fillLerp.currentValue;
|
||||
|
||||
if (useLerpColor)
|
||||
{
|
||||
fillColor.Update(1);
|
||||
fillImage.color = fillColor.currentValue;
|
||||
}
|
||||
}
|
||||
|
||||
private Tweener blinkTweener;
|
||||
|
||||
public virtual void Blink(Color blinkColor, float duration = 0.2f)
|
||||
{
|
||||
blinkTweener?.Kill();
|
||||
Color originalColor = useLerpColor ? fillColor.targetValue : fillImage.color;
|
||||
blinkTweener = fillImage.DOColor(blinkColor, duration / 2).SetLoops(2, LoopType.Yoyo).OnComplete(() =>
|
||||
{
|
||||
fillImage.color = originalColor;
|
||||
});
|
||||
blinkTweener.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b0e70941af825444a13a71584f8293f
|
||||
@@ -0,0 +1,11 @@
|
||||
using Cielonos.MainGame;
|
||||
using SLSFramework.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cielonos.UI
|
||||
{
|
||||
public class PlayerEnergyBar : AttributeBarBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf21b5081a05af848a744cb0f84e85dd
|
||||
@@ -0,0 +1,38 @@
|
||||
using Cielonos.MainGame;
|
||||
using SLSFramework.General;
|
||||
using SLSFramework.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI.Extensions.ColorPicker;
|
||||
|
||||
namespace Cielonos.UI
|
||||
{
|
||||
public class PlayerHealthBar : AttributeBarBase
|
||||
{
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
useLerpColor = true;
|
||||
fillColor = new LerpColor(GetTargetColor(1), 0.2f);
|
||||
}
|
||||
|
||||
public Color GetTargetColor(float ratio)
|
||||
{
|
||||
float hue = Mathf.Lerp(120f, 0f, 1 - ratio);
|
||||
return HSVUtil.ConvertHsvToRgb(hue, 0.41f, 1f, 1f);
|
||||
|
||||
/*if (ratio >= 0.9f)
|
||||
{
|
||||
return HSVUtil.ConvertHsvToRgb(120f, 0.41f, 1f, 1f);
|
||||
}
|
||||
else if(ratio >= 0.2f)
|
||||
{
|
||||
float hue = Mathf.Lerp(120f, 0f, (0.9f - ratio) / (0.9f - 0.2f));
|
||||
return HSVUtil.ConvertHsvToRgb(hue, 0.41f, 1f, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
return HSVUtil.ConvertHsvToRgb(0f, 0.41f, 1f, 1f);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21cc57bd78333344a976ee2432ed2fc9
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using Cielonos.MainGame;
|
||||
using SLSFramework.UI;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cielonos.UI
|
||||
{
|
||||
public class PlayerInfoUIArea : UIElementBase
|
||||
{
|
||||
public TMP_Text nameText;
|
||||
public TMP_Text healthText;
|
||||
public PlayerHealthBar healthBar;
|
||||
public PlayerEnergyBar energyBar;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
UpdateHealth(true);
|
||||
UpdateEnergy(true);
|
||||
}
|
||||
|
||||
public void UpdateHealth(bool isInstant = false)
|
||||
{
|
||||
float currentHealth = MainGameManager.Player.attributeSm["Health"];
|
||||
float maximumHealth = MainGameManager.Player.attributeSm["MaximumHealth"];
|
||||
float ratio = currentHealth / maximumHealth;
|
||||
Color fillColor = healthBar.GetTargetColor(ratio);
|
||||
string colorHex = ColorUtility.ToHtmlStringRGB(fillColor);
|
||||
healthBar.UpdateFillImage(currentHealth, maximumHealth);
|
||||
healthBar.UpdateFillColor(fillColor, isInstant);
|
||||
if(!isInstant) healthBar.Blink(Color.white);
|
||||
|
||||
int currentHealthInt = Mathf.CeilToInt(currentHealth);
|
||||
int maximumHealthInt = Mathf.CeilToInt(maximumHealth);
|
||||
if (ratio <= 0.2f)
|
||||
{
|
||||
healthText.text = $"<color=#{colorHex}>{currentHealthInt}</color> <size=18>/ {maximumHealthInt}</size>";
|
||||
}
|
||||
else
|
||||
{
|
||||
healthText.text = $"{currentHealthInt} <size=18>/ {maximumHealthInt}</size>";
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateEnergy(bool isInstant = false)
|
||||
{
|
||||
float currentEnergy = MainGameManager.Player.attributeSm["Energy"];
|
||||
float maximumEnergy = MainGameManager.Player.attributeSm["MaximumEnergy"];
|
||||
energyBar.UpdateFillImage(currentEnergy, maximumEnergy);
|
||||
if(!isInstant) energyBar.Blink(Color.white);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef18d95d744f79046978ef973afc9e65
|
||||
Reference in New Issue
Block a user