유니티 코루틴 관련 함수(대화 관련)

|
출처 : http://www.unitystudy.net/bbs/board.php?bo_table=writings&wr_id=43


코루틴용 데이터

엔진이 수행하는 기능

yield return null

다음 프레임까지 대기

yield return new WaitForSeconds(float)

지정된 초 만큼 대기

yield return new WaitForFixedUpdate()

다음 물리 프레임까지 대기

yield return new WaitForEndOfFrame()

모든 렌더링작업이 끝날 때까지 대기

yield return StartCoRoutine(string)

다른 코루틴이 끝날 때까지 대기

yield return new WWW(string)

웹 통신 작업이 끝날 때까지 대기

yield return new AsyncOperation

비동기 작업이 끝날 때까지 대기 ( 씬로딩 )



순차적 수행 가능







public class DialogExample : MonoBehaviour {

   

    bool showDialog = false;

    string answer = "";

   

    IEnumerator Start()

    {

        yield return StartCoroutine("ShowDialog"); //다른 코루틴이 끝날 때까지 대기

        yield return StartCoroutine(answer);

    }

   //answer 에 값이 들어가기 전까지는 코루틴이 끝나지 않음

    IEnumerator ShowDialog()

    {

        showDialog = true;

        do

        {

            yield return null;

        } while(answer == "");

       

        showDialog = false;

    }

   

    IEnumerator ActionA()

    {

        Debug.Log ("Action A");

        yield return new WaitForSeconds(1f);

    }

 

    IEnumerator ActionB()

    {

        Debug.Log ("Action B");

        yield return new WaitForSeconds(2f);

    }

   

    void OnGUI()

    {

        if(showDialog)

        {

            if(GUI.Button(new Rect(10f, 10f, 100f, 20f), "A"))

            {

                answer = "ActionA";  

            } else if(GUI.Button(new Rect(10f, 50f, 100f, 20f), "B")) {

                answer = "ActionB";

            }

        }

    }

   

}




Trackback 0 And Comment 0

블로그 변경.

|

블로그 주소 변경 및 디자인 전체적으로 전부 다 변경.

전부 Unity3D 관련 자료들을 다룰 예정임.

참고 사이트 및 스크립트 관련 기능 위주로 포스팅 할 예정



Trackback 0 And Comment 0

Update 및 FixedUpdate 사용시 주의점

|

void Update () 는 일반적인 연산 및 Translate로 이동할시 사용

void FixedUpdate()는Rigidbody를 이용한 연산시 사용함 ex) AddForce 

 

FixedUpdate는 일정한 시간마다 호출되기 때문에 정확한 물리연산을 필요로 할때 사용하면된다.


Trackback 0 And Comment 0