using System.Collections;
using UnityEngine;
namespace Ubisoft
{
///
/// Singleton used on Unity only to start co routines.
///
public sealed class HtCoroutineManager : HtSingletonHolder.IConsumer
{
///
/// Class needed to start a coroutine (inherits from MonoBehaviour)
///
private class CoroutineBehaviour : MonoBehaviour
{
}
private static HtCoroutineManager s_instance;
public static HtCoroutineManager Instance
{
get
{
if (s_instance == null)
{
s_instance = new HtCoroutineManager();
}
return s_instance;
}
}
///
/// The behaviour used to start the co routines.
///
private CoroutineBehaviour m_behaviour;
///
/// Initializes a new instance of the CoroutineManager class and create the behaviour object in order to start co routines.
///
private HtCoroutineManager()
{
m_behaviour = HtSingletonHolder.AddMainComponent(this);
}
public Coroutine StartCoroutine(IEnumerator routine)
{
return m_behaviour.StartCoroutine(routine);
}
public Coroutine StartCoroutine(string methodName)
{
return m_behaviour.StartCoroutine(methodName);
}
public Coroutine StartCoroutine(string methodName, object value)
{
return m_behaviour.StartCoroutine(methodName, value);
}
public void StopCoroutine(string methodName)
{
m_behaviour.StopCoroutine(methodName);
}
public void StopCoroutine(IEnumerator routine)
{
m_behaviour.StopCoroutine(routine);
}
public void StopCoroutine(Coroutine coroutine)
{
m_behaviour.StopCoroutine(coroutine);
}
public void Destroy()
{
if (m_behaviour != null)
{
HtSingletonHolder.RemoveMainComponent(true);
m_behaviour = null;
}
s_instance = null;
}
public void DestroySingleton(Component singleton)
{
if (singleton == m_behaviour)
{
Debug.LogInformation("Destroy " + this.GetType());
m_behaviour = null;
s_instance = null;
}
}
}
}