Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/geniikw/CoroutineChain
Unity3d, Coroutine, scripting
https://github.com/geniikw/CoroutineChain
coroutines unity3d unity3d-plugin
Last synced: about 2 months ago
JSON representation
Unity3d, Coroutine, scripting
- Host: GitHub
- URL: https://github.com/geniikw/CoroutineChain
- Owner: geniikw
- License: mit
- Created: 2018-02-16T10:31:19.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-03-03T06:40:02.000Z (almost 3 years ago)
- Last Synced: 2024-08-02T05:13:10.444Z (5 months ago)
- Topics: coroutines, unity3d, unity3d-plugin
- Language: C#
- Size: 409 KB
- Stars: 44
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CoroutineChain
Unity3d, Coroutine, scripting[AssetStore](https://assetstore.unity.com/packages/tools/input-management/coroutinechain-109785)
## Install
Use the unity package manager.(https://github.com/geniikw/CoroutineChain.git)
## Intro
- Easy to read coroutine code.
- Define callback simply
- Call coroutine at outside MonoBehavour.In my experience, generally coroutine code can be classified into two kinds.
One is a functional block. For example
```csharp
IEnumerator OneFunction(){
//do single task.
}
```Other is a squencial code. It consist of functional block coroutines.
```csharp
IEnumerator Sequncial(){
yield return StartCoroutine(A());
yield return StartCoroutine(B());
yield return StartCoroutine(C());
}
```It is a small asset that makes it possible to call Unity's coroutines while chaining them.
so you don't need to write seuqencial block. just chain it in call block.
```csharp
public void Start(){
//same as above.
CoroutineChain.Start
.Play(A())
.Play(B())
.Play(C());
//or
CoroutineChain.Start
.Sequencial(A(),B(),C());
}
```[AssetStore](https://www.assetstore.unity3d.com/kr/#!/content/109785)
## Reference
### Basic
all block wait previous block.
```csharp
void Start(){
this.StartChain() // or CoroutineChain.Start.Play ...
.Play(Coroutine())
.Sequencial(A(),B(),C()) // play one by one.
.Parallel(A(),B(),C()) // play same time.
.Wait(1f)
.Log("Complete!");
.Call(()=>Callback());
}
```### Play(IEnumerator coroutine)
play one coroutine. it is same as StartCoroutine().
```csharp
void Start(){
//Normal
StartCoroutine(A());
//CoroutineChain
this.StartChain()
.Play(A());
}
```### Wait(float sec)
```csharp
void Start(){
this.StartChain()
.Wait(1)
.Log("end");
//1sec later debug log show out.
}
```### Parallel(IEnumerator[] routines)
all coroutine start at same time
```csharp
void Start(){
///Normal.
StartCoroutine(A());
StartCoroutine(B());
StartCoroutine(C());
//CoroutineChain, Less Character!
this.StartChain()
.Parallel(A(),B(),C());
}
```### Sequential(IEnemerator[] routines)
it same as continuous Play block.
```csharp
IEnumerator Start(){///CoroutineStartBlock.
///Normal.
yield return StartCoroutine(A());
yield return StartCoroutine(B());
yield return StartCoroutine(C());
//CoroutineChain, Less Character!
yield return this.StartChain()
.Sequencial(A(),B(),C());
}
```
### Log(string log, ELogTtype type = ELogType.NORMAL)
log block is not coroutine.
```csharp
IEnumerator Start(){///CoroutineStartBlock.
///Normal.
yield return StartCoroutine(A());
yield return StartCoroutine(A());
yield return StartCoroutine(A());
Debug.Log(A, B and C all end!!");
//CoroutineChain
yield return this.StartChain()
.Sequencial(A(),B(),C())
.Log("A, B and C all end!!");
}
```### Call(Action)
you can simply setup callback.this is Parallel block using Call() as coroutine callback.
```csharp
IEnumerator Parallel(IEnumerator[] routines)
{
var all = 0;
foreach (var r in routines)
all++;var c = 0;
foreach (var r in routines)
player.StartChain()
.Play(r)
.Call(() => c++);while (c < all)
yield return null;
}
```### WaitFor(Func)
wait for a specific condition.
```csharp
void Start(){
CoroutineChain.Start
.WaitFor(()=>m_timer > 3f)
.Log("Complete");
}float m_timer = 0f;
void Update(){
m_timer += Time.deltaTime;
}```