Created
April 2, 2019 23:20
-
-
Save z3nth10n/518d100795b28528f5a4ae9e8a0b5b4e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 GTAMapper.Extensions.Threading; | |
using System; | |
using System.Collections; | |
using UnityEngine; | |
namespace GTAMapper.Extensions | |
{ | |
public static class BatchedCoroutines | |
{ | |
public static IEnumerator BatchCoroutines( | |
MonoBehaviour monoBehaviour, | |
Action finish, | |
Func<int, bool>[] waitUntil = null, | |
params Tuple<Action<object>, ConcurrentQueuedCoroutines<object>>[] tuple) // Tuple<Action<T>, ConcurrentQueuedCoroutines<T>> || dynamic | |
// Fix for: https://stackoverflow.com/questions/15417174/using-the-params-keyword-for-generic-parameters-in-c-sharp | |
{ | |
int i = 0; | |
foreach (var val in tuple) | |
{ | |
if (waitUntil != null && waitUntil[i] != null) | |
yield return new WaitUntil(() => waitUntil[i](i)); | |
yield return val.Item2.GetCoroutine(monoBehaviour, val.Item1); | |
++i; | |
} | |
finish?.Invoke(); | |
} | |
} | |
} |
This file contains hidden or 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; | |
public static class F { | |
public static Func<int, bool>[] GetFuncs(params Func<int, bool>[] waitUntil) | |
{ | |
return waitUntil; | |
} | |
} |
This file contains hidden or 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
namespace GTAMapper.Core { | |
public class Program : MonoBehaviour { | |
protected ConcurrentQueuedCoroutines<object> debuggingCoroutine = new ConcurrentQueuedCoroutines<object>(), | |
colorCoroutine = new ConcurrentQueuedCoroutines<object>(); | |
public void Start() { | |
StartCoroutine(BatchedCoroutines.BatchCoroutines( | |
this, | |
() => areCoroutinesCollected = true, | |
F.GetFuncs(null, (_ii) => debuggingCoroutine.Queue.Count > 0), | |
new Tuple<Action<object>, ConcurrentQueuedCoroutines<object>>((obj) => | |
{ | |
Tuple<int, Color> tuple = (Tuple<int, Color>)obj; | |
int i = tuple.Item1, | |
_x = i % width, | |
_y = i / width; | |
UnityEngine.Color actualColor = debugTexture.GetPixel(_x, _y), | |
mixedColor = UnityEngine.Color.Lerp(actualColor, tuple.Item2, .5f); | |
if (actualColor != mixedColor) | |
{ | |
debugTexture.SetPixel(_x, _y, mixedColor); | |
debugTexture.Apply(); | |
} | |
}, colorCoroutine), | |
new Tuple<Action<object>, ConcurrentQueuedCoroutines<object>>((obj) => | |
{ | |
Color[] colors = (Color[])obj; | |
debugTexture.SetPixels32(colors.CastBack().ToArray()); | |
debugTexture.Apply(); | |
}, debuggingCoroutine))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment