Skip to content

Instantly share code, notes, and snippets.

@zhenlinyang
Created July 6, 2016 09:05
Show Gist options
  • Save zhenlinyang/516104bd2945d35b6f2384b66daea0d9 to your computer and use it in GitHub Desktop.
Save zhenlinyang/516104bd2945d35b6f2384b66daea0d9 to your computer and use it in GitHub Desktop.
Unity5.3 CustomYieldInstruction Sample
public class CustomYieldInstructionSample : MonoBehaviour
{
IEnumerator TheCoroutine()
{
TheLock theLock = new TheLock();
yield return new WaitTheFinish(theLock.GetLockState);
}
}
public class WaitTheFinish : CustomYieldInstruction
{
private Func<bool> m_theLockState;
public override bool keepWaiting
{
get { return m_theLockState.Invoke(); }
}
public WaitTheFinish(Func<bool> theLockState)
{
m_theLockState = theLockState;
}
}
public class TheLock
{
private bool m_isLock = true;
public bool GetLockState()
{
return m_isLock;
}
public void RemoveTheLock()
{
m_isLock = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment