Search Unity

Assets AsCoroutine - use coroutine in a functional style.

Discussion in 'Works In Progress - Archive' started by zsaladin, Sep 12, 2017.

  1. zsaladin

    zsaladin

    Joined:
    Jan 20, 2015
    Posts:
    11
    AsCouroutine is a unity asset that allows you to use Coroutine in a functional style. You can handle coroutine as first-class citizen so that you can use method chain and combine coroutines.

    You might face the case below. You would have to write an additional method because of using just one line of 'yield return' state related with some instructions like 'WaitForSeconds', 'WaitForEndOfFrame' and so on. Sometimes it is annoying and makes your code ugly.
    Code (CSharp):
    1. private void OnEnable()
    2. {
    3.     StartCoroutine(UnityCoroutine());
    4. }
    5.  
    6. private IEnumerator UnityCoroutine()
    7. {
    8.     yield return new WaitForSeconds(1f);
    9.     Debug.Log("UnityCoroutine");
    10. }

    Now you are free from writing the additional method.
    Code (CSharp):
    1. private void OnEnable()
    2. {
    3.     this.AsCoroutine()
    4.         .YieldWaitForSeconds(1f).Action(() => Debug.Log("AsCoroutine"))
    5.         .Start(this);
    6. }
    It makes your code simple and clean.

    And there are other features in it as well.
    You can access it through the link below.

    link : https://github.com/zsaladin/AsCoroutine
     
    Last edited: Sep 12, 2017