void Start(){
CoroutineChain.Start
.Play(Test1())
.Call(()=>Debug.Log("Middle of chaining"))//non coroutine
.Wait(1f)
.Sequential(Test1, Test2, Test3) //runs one after another
.Parallel(Test1(), Test2(), Test3()) //runs all at the same time
.Call(()=>Debug.Log("Complete!")); //all parallel routine complete.
}
}
*17-04-20
rename Plll to Parallel
add Call
add Start
*17-04-20 (2)
remove unirx dependency
add Play(Func next)
add sequencial
rename Parrallel to PlayWithUpper temporary and change Parrallel.
*17-04-21
remove PlayWithUpper
make Parallel completely
release 0.1
Thanks for everybody!
At first this is only 30 line small file, but now raise to 150 line.
I leave a while but if find a bug or a suggestion leave message on this thread or gist page.
Thanks for ideas again. happy coding!
IEnumerator Start()
{
yield return Test1();
yield return new WaitForSeconds(1f);
yield return Test2();
StartCoroutine(Test3()); //I'm assuming Plll is parrallel, so we don't wait on it
}
I believe the idea is using objectchaining. Similar to how one uses Linq or how one programs in jQuery.
Functionally they should behave the same, Its just code sugar mostly which isn’t really a bad thing. Though persionally I would rename that Plll(), its not a very sugary name.
Is the MainThreadDispatcher a version of this? That made the code work, but since you’ve seemed to change the back-end some, the code won’t work right out of the box.
Anyway, this is nice if you need some kind of sequential workflow often. It might be a case of “they were so preoccupied with whether or not they could, they didn’t stop to think if they should”
I’ll suggest adding overloads for Play, both a Play(Func):
public Chain Play(params Func<IEnumerator>[] next)
{
Chain current = this;
for (int i = 0; i < next.Length; i++)
{
current = Chaining(next(), current);
}
return current;
}
//allows doing this:
CoroutineChain.Start
.Play(Test1, Test2)
.Wait(5)
.Play(Test3);
}
It might be that that overload should be named “Sequential” instead? Then if you do a similar trick with Parallel, it would be possible to make the code a lot easier to read:
* *CoroutineChain.Start .Sequential(Test1, Test2, Test3) //runs one after another .Wait(5) .Parallel(Test1, Test2, Test3); //runs all at the same time }* * idk, though.
it depends on how people will want to use it, but if it bothers them so much (the overcrowding parameters that is…) then they could just simply package up the coroutine calls into lambada closures.
var closureA = () => XPositionTween(trans,x,time);
var closureB = () => ColorTween(graphic,Color.clear, time);
CoroutineChain.Start
.Sequential(closureA())
.Parallel(closureB());
...