コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】関数を連結して実行できる「ChainedWorks」紹介

はじめに

https://bitbucket.org/snippets/Lordinarius/8rnLn/chainedworks

上記のサイト様が公開されている「ChainedWorks」を使用することで
関数を連結して実行できるようになります

使用例

using UnityEngine;

public class Example : MonoBehaviour
{
    private void Start()
    {
        var chainedWork = new ChainedWork();
        chainedWork.AddWork( () => Debug.Log( "delegate" ), 2 );
        chainedWork.AddWork( MethodWithNoParameter, 1.2f );
        chainedWork.AddWork( () => MethodWithParameter( 5 ), 1.4f );
        StartCoroutine( chainedWork.DoWorkCO() );
    }

    private void MethodWithNoParameter()
    {
        Debug.Log( "MethodWithNoParameter" );
    }

    private void MethodWithParameter( int param )
    {
        Debug.Log( "MethodWithParameter: " + param.ToString() );
    }

}