void Awake() { TinyCoro.SpawnNext(DoPreform); var cameraRotate = new UnityObject(GameObject.Find("CameraRotate")); cameraRotate.UnityUpdate += u => u.Transform.Rotate(Vector3.up, -2f * Time.deltaTime); var guiRect = new Rect(0, 0, Screen.width, Screen.height); cameraRotate.UnityGUI += (u) => { var guiText = string.Format("Generation: {0}\nBest Score: {1} (distance + head height + waist height, in gen: {2})\nv0.4 running for {3}", Generation, TopScore, TopScoreGen, TimeSpan.FromSeconds(Time.timeSinceLevelLoad)); if (_configLines != null) { guiText += "\n" + string.Join("\n", _configLines); } GUI.Label(guiRect, guiText); }; }
private static IEnumerator PreformThreadedOperation(Action threadedOperation) { var thread = new Thread(new ThreadStart(threadedOperation)); thread.Start(); yield return(TinyCoro.WaitUntil(() => !thread.IsAlive)); }
/// <summary> /// Adds an new TinyCoro to the pool after the currently exceutiny one (or last if none are running) /// </summary> /// <param name="threadedOperation"></param> /// <returns></returns> public static TinyCoro SpawnNext(Func<IEnumerator> operation, string name = null) { var coro = new TinyCoro(operation); coro.Name = name; var index = _allCoros.Count; if (Current != null) index = _allCoros.IndexOf(Current) + 1; _allCoros.Insert(index, coro); Debug.Log(coro + " created at index " + index); return coro; }
/// <summary> /// Adds an new TinyCoro to the pool after the currently exceutiny one (or last if none are running) /// </summary> /// <param name="threadedOperation"></param> /// <returns></returns> public static TinyCoro SpawnNext(Func <IEnumerator> operation, string name = null) { var coro = new TinyCoro(operation); coro.Name = name; var index = _allCoros.Count; if (Current != null) { index = _allCoros.IndexOf(Current) + 1; } _allCoros.Insert(index, coro); Debug.Log(coro + " created at index " + index); return(coro); }
public static void StepAllCoros() { for (int i = 0; i < _allCoros.Count; ) { //Step normal Current = _allCoros[i]; if (Current.Alive) Current.Step(); if (!Current.Alive) { _allCoros.RemoveAt(i); } else { ++i; } } Current = null; }
public static void StepAllCoros() { for (int i = 0; i < _allCoros.Count;) { //Step normal Current = _allCoros[i]; if (Current.Alive) { Current.Step(); } if (!Current.Alive) { _allCoros.RemoveAt(i); } else { ++i; } } Current = null; }
void Update() { TinyCoro.StepAllCoros(); }
public static TinyCoro SpawnAfter(Action threadedOperation) { return(TinyCoro.SpawnNext(() => PreformThreadedOperation(threadedOperation))); }