Created
January 8, 2018 13:51
-
-
Save friuns2/c409dd0eed2124d2b248cb893cb4f734 to your computer and use it in GitHub Desktop.
corontinue impl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
//your application logic | |
public class MyGameObject : MonoBehaviour | |
{ | |
public override void Awake() | |
{ | |
StartCorontinue(MyCorontinueMethod()); | |
} | |
IEnumerator MyCorontinueMethod() | |
{ | |
print("1"); | |
yield return null; | |
print("2"); | |
yield return null; | |
print("3"); | |
yield return null; | |
while (true) | |
{ | |
print("Update Corontinue"); | |
yield return null; | |
} | |
} | |
public override void Update() | |
{ | |
print("Update"); | |
} | |
} | |
//unity engine logic | |
public class MonoBehaviour | |
{ | |
public MonoBehaviour() | |
{ | |
UnityMainLoop.monoBehaviours.Add(this); | |
Awake(); | |
} | |
public virtual void Awake() | |
{ | |
} | |
public virtual void Update() | |
{ | |
} | |
public void StartCorontinue(IEnumerator cor) | |
{ | |
UnityMainLoop.corontinues.Add(cor); | |
} | |
public static void print(object o) | |
{ | |
Console.WriteLine(o); | |
} | |
} | |
class UnityMainLoop | |
{ | |
public static List<IEnumerator> corontinues = new List<IEnumerator>(); | |
public static List<MonoBehaviour> monoBehaviours = new List<MonoBehaviour>(); | |
public static void Main2() | |
{ | |
var myScript = new MyGameObject(); // semplified unity main loop | |
while (true) | |
{ | |
//Unity corontinues execution | |
for (int i = corontinues.Count - 1; i >= 0; i--) | |
{ | |
var a = corontinues[i]; | |
if (!a.MoveNext()) | |
corontinues.Remove(a); | |
} | |
//update execution | |
foreach (var a in monoBehaviours) | |
a.Update(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment