Trying to have a system able to store any kind of yield instructions
YieldInstruction m_yield;
void SetInstruction()
{
switch(condition)
{
case UseWait:
m_yield = new WaitForSeconds(1f);
break;
case UseWaitUntil:
m_yield = new WaitUntil(() => flag == true); // Cannot cast here
}
}
Changing the type to IEnumerator puts the problem on the first one. CustomeYieldInstruction is not doing either.
I can't put my finger on what is the relation between YieldInstruction and CustomYieldInstruction. Despite the names, one is its own base type and the latter is IEnumerator.
I'm also confused since the two methods can yield in a IEnumerator method but won't cast into it if done as I am trying.
public sealed class WaitForSeconds : YieldInstruction{ /* ** */ }
public class YieldInstruction { }
public sealed class WaitUntil : CustomYieldInstruction { /* ** */}
public abstract class CustomYieldInstruction : IEnumerator { /* ** */ }
and I can do :
public IEnumerator Sequence()
{
yield return new WaitForSeconds(1f),
yield return new WaitUntil(()=> condition == true);
}