waitUntil을 추가했음
## 효과
yield new 로 생기는 가비지콜렉션을 줄일수있다.
참고
https://velog.io/@livelyjuseok/C-Unity-%EC%BD%94%EB%A3%A8%ED%8B%B4-Yield-%EC%B5%9C%EC%A0%81%ED%99%94-%ED%95%98%EA%B8%B0IEqualityComparer
## 사용예
```
yield return YieldCache.WaitForEndOfFrame;
yield return YieldCache.WaitUntilcustom(() => isLoginSuccess);
yield return YieldCache.WaitUntilcustom(() => FirebaseDataManager.Instance != null);
yield return YieldCache.WaitUntilcustom(() => DataPersistenceManager.Instance != null);
//yield return new WaitForEndOfFrame();
//yield return new WaitUntil(() => isLoginSuccess);
//yield return new WaitUntil(() => FirebaseDataManager.Instance !=null);
//yield return new WaitUntil(() => DataPersistenceManager.Instance != null);
```
## 최적화 코드
```csharp 최적화 코드
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
static class YieldCache
{
class FloatComparer : IEqualityComparer<float>
{
bool IEqualityComparer<float>.Equals(float x, float y)
{
return x == y;
}
int IEqualityComparer<float>.GetHashCode(float obj)
{
return obj.GetHashCode();
}
}
class FloatComparerbool : IEqualityComparer<Func<bool>>
{
bool IEqualityComparer<Func<bool>>.Equals(Func<bool> x, Func<bool> y)
{
return x == y;
}
int IEqualityComparer<Func<bool>>.GetHashCode(Func<bool> obj)
{
return obj.GetHashCode();
}
}
public static readonly WaitForEndOfFrame WaitForEndOfFrame = new WaitForEndOfFrame();
public static readonly WaitForFixedUpdate WaitForFixedUpdate = new WaitForFixedUpdate();
private static readonly Dictionary<float, WaitForSeconds> _timeInterval = new Dictionary<float, WaitForSeconds>(new FloatComparer());
private static readonly Dictionary<float, WaitForSecondsRealtime> _timeIntervalReal = new Dictionary<float, WaitForSecondsRealtime>(new FloatComparer());
private static readonly Dictionary<Func<bool>, WaitUntil> _waitUntill = new Dictionary<Func<bool>, WaitUntil>(new FloatComparerbool());
public static WaitForSeconds WaitForSeconds(float seconds)
{
WaitForSeconds wfs;
if (!_timeInterval.TryGetValue(seconds, out wfs))
_timeInterval.Add(seconds, wfs = new WaitForSeconds(seconds));
return wfs;
}
public static WaitForSecondsRealtime WaitForSecondsRealTime(float seconds)
{
WaitForSecondsRealtime wfsReal;
if (!_timeIntervalReal.TryGetValue(seconds, out wfsReal))
_timeIntervalReal.Add(seconds, wfsReal = new WaitForSecondsRealtime(seconds));
return wfsReal;
}
public static WaitUntil WaitUntilcustom(Func<bool> state)
{
WaitUntil wfsReal;
if (!_waitUntill.TryGetValue(state, out wfsReal))
_waitUntill.Add(state, wfsReal = new WaitUntil(state));
return wfsReal;
}
}