using UnityEngine;
public class Delay : MonoBehaviour
{
	public float delayTime = 3.0f;
    private bool _isDelayActive;
    private bool _start;
    private void OnEnable()
    {
        if (_start)
        {
            // 注:手动重复打开会重置激活时间
            if (!_isDelayActive)
                IndependentEffectManager.AddParticleDelay(this);
            else
                _isDelayActive = false;
        }
    }

    private void Start()
    {
        _start = true;
        OnEnable();
    }
    /// <summary>
    /// 由IndependentEffectManager推送的开启事件
    /// </summary>
    public void DelayActive()
    {
        // 如果自身已经激活,则不做任何处理
        if (gameObject.activeSelf)
            _isDelayActive = false;
        // 如果父节点尚未激活,回退到初始状态
        else if (transform.parent != null && !transform.parent.gameObject.activeInHierarchy)
            _isDelayActive = false;
        else
            _isDelayActive = true;
        gameObject.SetActive(true);
    }
    /// <summary>
    /// 重置延迟开启状态 - 如果当前在激活节点下,则重新开始延迟
    /// </summary>
    public void ClearDelay()
    {
        IndependentEffectManager.RemoveParticleDelay(this);
        _isDelayActive = false;
        gameObject.SetActive(true);
    }
}