apply final level up vfx

This commit is contained in:
NguyenVanDat
2025-11-12 14:05:00 +07:00
parent cfeebf3a15
commit f1e15cdc2d
6 changed files with 192 additions and 30 deletions
@@ -1,3 +1,4 @@
using System;
using BrewMonster.Scripts;
using UnityEngine;
@@ -13,10 +14,18 @@ namespace BrewMonster.PerfectWorld.Scripts.Vfx
public class BaseVfxObject : MonoBehaviour
{
[SerializeField] private ParticleSystem _vfx;
[SerializeField] private float _lifeTime =-1;
private string _vfxPath;
private Vector3 _originalScale = Vector3.one;
private Vector3 _offset = Vector3.zero;
private GFX_STATE m_iState;
[SerializeField]private GFX_STATE m_iState;
private float _elapsedTime = 0f;
private bool _lifetimeCompleted = false;
/// <summary>
/// 生命周期完成事件 / Event triggered when lifetime is completed
/// </summary>
public event Action OnLifetimeCompleted;
private void Awake()
{
@@ -37,6 +46,21 @@ namespace BrewMonster.PerfectWorld.Scripts.Vfx
AddressableManager.Instance.UnloadAsset(_vfxPath);
}
}
private void Update()
{
if (_lifeTime > 0 && m_iState == GFX_STATE.ST_PLAY && !_lifetimeCompleted)
{
_elapsedTime += Time.deltaTime;
if (_elapsedTime >= _lifeTime)
{
_lifetimeCompleted = true;
Stop();
OnLifetimeCompleted?.Invoke();
}
}
}
public void Init(string vfxPath)
{
@@ -159,19 +183,12 @@ namespace BrewMonster.PerfectWorld.Scripts.Vfx
if (_vfx != null)
{
m_iState = GFX_STATE.ST_PLAY;
gameObject.SetActive(true);
_vfx.Play();
}
}
/// <summary>
/// Play VFX with children
/// </summary>
public void PlayWithChildren()
{
if (_vfx != null)
{
m_iState = GFX_STATE.ST_PLAY;
_vfx.Play(true);
// 重置生命周期计时器 / Reset lifetime timer
_elapsedTime = 0f;
_lifetimeCompleted = false;
}
}
@@ -184,6 +201,7 @@ namespace BrewMonster.PerfectWorld.Scripts.Vfx
{
m_iState = GFX_STATE.ST_STOP;
_vfx.Stop();
gameObject.SetActive(false);
}
}
@@ -221,6 +239,11 @@ namespace BrewMonster.PerfectWorld.Scripts.Vfx
_vfx.Stop();
_vfx.Clear();
_vfx.Play();
// 重置生命周期计时器 / Reset lifetime timer
m_iState = GFX_STATE.ST_PLAY;
_elapsedTime = 0f;
_lifetimeCompleted = false;
}
}
@@ -229,23 +252,53 @@ namespace BrewMonster.PerfectWorld.Scripts.Vfx
/// </summary>
public bool IsPlaying()
{
return _vfx != null && _vfx.isPlaying;
return m_iState == GFX_STATE.ST_PLAY;
}
/// <summary>
/// 检查特效是否已结束 / Check if VFX is stopped
/// Set lifetime duration
/// </summary>
public bool IsStopped()
/// <param name="lifeTime">生命周期时长(秒),-1表示无限 / Lifetime in seconds, -1 for infinite</param>
public void SetLifeTime(float lifeTime)
{
return _vfx != null && _vfx.isStopped;
_lifeTime = lifeTime;
_elapsedTime = 0f;
_lifetimeCompleted = false;
}
/// <summary>
/// 获取粒子系统 / Get ParticleSystem component
/// Get lifetime duration
/// </summary>
public ParticleSystem GetParticleSystem()
public float GetLifeTime()
{
return _vfx;
return _lifeTime;
}
/// <summary>
/// Get elapsed time
/// </summary>
public float GetElapsedTime()
{
return _elapsedTime;
}
/// <summary>
/// Get remaining lifetime
/// </summary>
public float GetRemainingLifeTime()
{
if (_lifeTime <= 0)
return -1f;
return Mathf.Max(0f, _lifeTime - _elapsedTime);
}
/// <summary>
/// Check if lifetime is completed
/// </summary>
public bool IsLifetimeCompleted()
{
return _lifetimeCompleted;
}
}
}