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.
 
 
 
 
 
 

169 lines
5.5 KiB

using CoreGame;
using UnityEngine;
namespace CoreGame.Render
{
public class HpBarItem : ISptPool
{
private float m_RedHpBarChangeStep;
private StateBarRender m_Render;
private float m_MaxZ;
private float m_MinZ;
public void Init(StateBarRender render)
{
m_RedHpBarChangeStep = 0f;
m_Render = render;
m_MaxZ = m_Render.hpMaxZ.position.z * 0.2f + 0.5f;
m_MinZ = m_Render.hpMinZ.position.z * 0.2f + 0.5f;
}
public void SetHpBar(float rate, float hpShieldRate)
{
if (m_Render == null)
{
return;
}
// var tempGreenPos = render.greenHpBar.localPosition;
var tempGreenCol = m_Render.GreenHpSprite.color;
if (hpShieldRate > 0f && m_Render.hpShieldBar != null)
{
var tempHpShieldCol = m_Render.HpShieldSprite.color;
tempHpShieldCol.a = Mathf.Lerp(m_MinZ, m_MaxZ, Mathf.Clamp01(hpShieldRate));
m_Render.HpShieldSprite.color = tempHpShieldCol;
}
// var tempRedPos = render.redHpBar.localPosition;
var tempRedCol = m_Render.RedHpSprite.color;
rate = Mathf.Clamp01(rate);
var a = Mathf.Lerp(m_MinZ, m_MaxZ, rate);
tempGreenCol.a = a;
m_Render.GreenHpSprite.color = tempGreenCol;
if (a >= tempRedCol.a)
{
tempRedCol.a = a;
m_Render.RedHpSprite.color = tempRedCol;
m_RedHpBarChangeStep = 0f;
}
else
{
m_RedHpBarChangeStep = ((tempRedCol.a - tempGreenCol.a) / BattleConst.HpBarRedStep).AsFloat;
}
}
public void UpdateRedHpBar()
{
if (m_RedHpBarChangeStep > 0.00001f)
{
var tempGreenCol = m_Render.GreenHpSprite.color;
var tempRedCol = m_Render.RedHpSprite.color;
if (tempRedCol.a - tempGreenCol.a > 0.001f)
{
var fillAmount = tempRedCol.a - m_RedHpBarChangeStep;
tempRedCol.a = fillAmount;
m_Render.RedHpSprite.color = tempRedCol;
}
}
}
public void Reset()
{
m_RedHpBarChangeStep = 0f;
m_Render = null;
m_MaxZ = 0f;
m_MinZ = 0f;
}
}
public class AmmoBarItem : ISptPool
{
private bool m_AmmoBarReload;
private float m_WhiteAmmoBarTime;
private float m_GreyAmmoReloadTimeAcc;
private float m_GreyAmmoReloadTime;
private StateBarRender m_Render;
private float m_MaxZ;
private float m_MinZ;
public void Init(StateBarRender render)
{
m_Render = render;
m_MaxZ = m_Render.ammoMaxZ.position.z * 0.2f + 0.5f;
m_MinZ = m_Render.ammoMinZ.position.z * 0.2f + 0.5f;
}
public void SetAmmoBar(float rate)
{
var tempPurpleCol = m_Render.PurpleAmmoSprite.color;
rate = Mathf.Clamp01(rate);
var a = Mathf.Lerp(m_MinZ, m_MaxZ, rate);
tempPurpleCol.a = a;
m_Render.PurpleAmmoSprite.color = tempPurpleCol;
}
public void ReloadAmmoStart(float greyTime, float greyTimeAcc)
{
m_AmmoBarReload = true;
m_WhiteAmmoBarTime = BattleConst.AmmoBarWhiteTime.AsFloat;
m_GreyAmmoReloadTime = greyTime;
m_GreyAmmoReloadTimeAcc = greyTimeAcc;
}
public void ReloadAmmoEnd()
{
m_AmmoBarReload = false;
m_Render.whiteAmmoBar.gameObject.SetActiveWrap(false);
m_Render.greyAmmoBar.gameObject.SetActiveWrap(false);
}
public void UpdateGreyAmmoBar(float deltaTime)
{
m_Render.purpleAmmoBar.gameObject.SetActiveWrap(!m_AmmoBarReload);
if (!m_AmmoBarReload) return;
if (m_GreyAmmoReloadTimeAcc < m_GreyAmmoReloadTime)
{
m_GreyAmmoReloadTimeAcc += deltaTime;
var tempGreyCol = m_Render.GreyAmmoSprite.color;
var rate = m_GreyAmmoReloadTimeAcc / m_GreyAmmoReloadTime;
var a = Mathf.Lerp(m_MinZ, m_MaxZ, rate);
tempGreyCol.a = a;
m_Render.GreyAmmoSprite.color = tempGreyCol;
var handlePos = Vector3.Lerp(m_Render.ammoMinZ.position, m_Render.ammoMaxZ.position, rate);
m_Render.ammoReloadHandle.position = handlePos;
m_Render.greyAmmoBar.gameObject.SetActiveWrap(true);
m_Render.whiteAmmoBar.gameObject.SetActiveWrap(false);
}
else
{
m_Render.greyAmmoBar.gameObject.SetActiveWrap(false);
if (m_WhiteAmmoBarTime >= 0f)
{
m_WhiteAmmoBarTime -= deltaTime;
m_Render.whiteAmmoBar.gameObject.SetActiveWrap(true);
}
else
{
m_Render.whiteAmmoBar.gameObject.SetActiveWrap(false);
m_AmmoBarReload = false;
}
}
}
public void Reset()
{
m_AmmoBarReload = false;
m_WhiteAmmoBarTime = 0f;
m_GreyAmmoReloadTimeAcc = 0f;
m_GreyAmmoReloadTime = 0f;
m_Render = null;
m_MaxZ = 0f;
m_MinZ = 0f;
}
}
}