목차

<note> 2014/1/5 에 유니티 보다가 적은 건데, 별 내용 아니니까 삭제 해야 하나. 흠. </note>

CoRoutine에 람다 표현식 응용

Unity3D의 CoRoutine을 사용할 때, 람다함수로 간단한 코드 몇줄은 바로 포함시켜서 실행 하도록.

private IEnumerator waitThenCallback(float time, Action callback)
{
  yield return new WaitForSeconds(time);
  callback();
}
 
void Start()
{
  splashScreen.show();
 
  StartCoroutine( waitThenCallback( 
      5, 
      () => { Debug.Log("Five seconds have passed!"); }
  ));
 
  StartCoroutine( waitThenCallback(
      10,
      () => { Debug.Log("Ten seconds have passed!"); }
  ));
 
  StartCoroutine( waitThenCallback(
      20,
      () => { 
        Debug.Log("Twenty seconds have passed!");
        splashScreen.hide();
      }
  ));
}

LeanTween의 Action 함수

LeanTween에는 System.Action<float>() 델리게이트 함수를 파라미터로 받아 주기 때문에, 아래 코드처럼 짧게 작성할 수 있다.

함수 추가하기 귀찮을때 굿.

LeanTween.value( 
    gameObject, 
    delegate( float v_ ) { mUISprite.alpha = v_; }, 
    0, 1, 1f );