using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public class MonoMgr : SingletonAutoMono<MonoMgr>
{
    /// <summary>
    /// 帧更新
    /// </summary>
    private event UnityAction onUpdate;

    /// <summary>
    /// 固定帧更新
    /// </summary>
    private event UnityAction onFixedUpdate;

    /// <summary>
    /// 延迟帧更新
    /// </summary>
    private event UnityAction onLateUpdate;

    
    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="action"></param>
    public void AddUpdateListener(UnityAction action)
    {
        onUpdate += action;
    }

    /// <summary>
    /// 移除
    /// </summary>
    /// <param name="action"></param>
    public void RemoveUpdateListener(UnityAction action)
    {
        onUpdate -= action;
    }

    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="action"></param>
    public void AddFixedUpdateListener(UnityAction action)
    {
        onFixedUpdate += action;
    }

    /// <summary>
    /// 移除
    /// </summary>
    /// <param name="action"></param>
    public void RemoveFixedUpdateListener(UnityAction action)
    {
        onFixedUpdate -= action;
    }

    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="action"></param>
    public void AddLateUpdateListener(UnityAction action)
    {
        onLateUpdate += action;
    }

    /// <summary>
    /// 移除
    /// </summary>
    /// <param name="action"></param>
    public void RemoveLateUpdateListener(UnityAction action)
    {
        onLateUpdate -= action;
    }

    /// <summary>
    /// 帧更新
    /// </summary>
    private void Update()
    {
        onUpdate?.Invoke();
    }

    /// <summary>
    /// 物理帧更新
    /// </summary>
    private void FixedUpdate()
    {
        onFixedUpdate?.Invoke();
    }

    /// <summary>
    /// 延迟帧更新
    /// </summary>
    private void LateUpdate()
    {
        onLateUpdate?.Invoke();
    }

}
