using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace TFramework
{
    public static class YieldWaitTool
    {
        static WaitForEndOfFrame _waitForEndOfFrame = new WaitForEndOfFrame();
        static WaitForFixedUpdate _waitForFixedUpdate = new WaitForFixedUpdate();
        static Dictionary<float, WaitForSeconds> _waitForSeconds = new Dictionary<float, WaitForSeconds>();
        static Dictionary<float, WaitForSecondsRealtime> _waitForSecondsRealtime = new Dictionary<float, WaitForSecondsRealtime>();

        public static YieldInstruction YieldWaitForEndOfFrame() => _waitForEndOfFrame;

        public static YieldInstruction YieldWaitForFixedUpdate() => _waitForFixedUpdate;

        public static YieldInstruction YieldWaitForSeconds(float second)
        {
            float _second = (float)Math.Round(second,2);
            if (!_waitForSeconds.ContainsKey(_second))
                _waitForSeconds.Add(_second, new WaitForSeconds(_second));
            return _waitForSeconds[_second];
        }

        public static IEnumerator YieldWaitForSecondsRealtime(float second)
        {
            float _second = (float)Math.Round(second, 2);
            if (!_waitForSecondsRealtime.ContainsKey(_second))
                _waitForSecondsRealtime.Add(_second, new WaitForSecondsRealtime(_second));
            return _waitForSecondsRealtime[_second];
        }
    }
}
