성엽이
KKIMSSI
성엽이
전체 방문자
오늘
어제
  • 분류 전체보기 (454)
    • :) (2)
    • C프로그래밍이론 (9)
    • C++프로그래밍 (64)
      • STL (1)
    • C# (2)
    • Visual studio 10.0 (9)
    • AT91SAM7S256 (21)
    • 논리회로 (14)
    • AVR2560 (11)
    • TCPIP (16)
    • NetWork (4)
      • Ubuntu Linux (2)
    • Assembly (21)
    • UNIX 프로그래밍 (6)
    • RFID 분석 (1)
    • Win32 API (7)
    • Cortex-M3 (4)
    • Unity (91)
    • Flutter (9)
    • OwnProject (11)
      • It's mine (5)
      • 마인드스톰 실습 (1)
      • 보고서 자료 (2)
      • RPi B+ (2)
    • ETC (25)
      • 상식 (3)
    • MFC (40)
    • PostgeSQL (18)
    • 영상제어 (6)
      • VFW_영상처리 (1)
    • Python (0)
    • Java (30)
      • SpringBoot (2)
      • Javascript (1)
      • JSP (13)
      • Spring (8)
    • Oracle (4)
      • SQL (3)
    • HTML (6)
      • Thymeleaf (1)
      • CSS (1)
      • Bootstrap (3)
    • IDE (1)
      • VS Code (1)
    • Android (2)
    • Privacy Policy (0)
    • MYSQL (2)
      • MariaDB (2)
    • AWS (5)
    • 개인공부 (0)

블로그 메뉴

  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록
  • 관리자
  • 글쓰기

공지사항

인기 글

태그

  • Boot Code 분석
  • MFC
  • WINAPI
  • ARM Reverse Engineering
  • 문자열 나누기

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
성엽이

KKIMSSI

[Unity] yield return 종류
Unity

[Unity] yield return 종류

2020. 4. 8. 16:16

 

https://m.blog.naver.com/PostView.nhn?blogId=bsheep91&logNo=221360776168&proxyReferer=https%3A%2F%2Fwww.google.com%2F

 

지랄하는 프로그래머 #14 [Unity3D/유니티 3D] 코루틴 함수 (2) 함수 반환 방법

코루틴은 반드시 반환 값을 적어야 되는 함수입니다. 이 반환의 종류에는 여러 가지가 있습니다.1. yield r...

blog.naver.com

 

코루틴은 반드시 반환 값을 적어야 되는 함수입니다.

이 반환의 종류에는 여러 가지가 있습니다.

1. yield return null

IEnumerator TestCoroutine()
{
    yield return null;
}

yield return null은 자주 사용하는 함수인 Update()가 끝나면 그때 yield return null구문의 밑의 부분이 실행됩니다.


2. yield return new WaitForEndOfFrame()

IEnumerator TestCoroutine()
{
    yield return new WaitForEndOfFrame();
}

yield return new WaitForEndOfFrame()은 프로그램에서 한 프레임워크가 완전히 종료될 때 호출이 됩니다. 모든 Update()가 끝나고 화면 렌더링까지 끝났을 때 yield return new WaitForEndOfFrame()구문의 밑의 부분이 실행됩니다.

 

3. yield return new WaitForFixedUpdate()

IEnumerator TestCoroutine()
{
    yield return new WaitForFixedUpdate();
}

yield return new WaitForFixedUpdate() 은 이름에서 알 수 있듯이 FixedUpdate()가 끝나면 그때 yield return new WaitForFixedUpdate()구문의 밑의 부분이 실행됩니다.

 

4.  yield return new WaitForSeconds();

IEnumerator TestCoroutine()
{
    yield return new WaitForSeconds(1.0f);
}

yield return new WaitForSeconds()은 괄호 안의 시간(초)이 지나면 yield return new WaitForSeconds()구문의 밑의 부분이 실행됩니다.

 

5.  yield return new WaitForSecondsRealtime();

IEnumerator TestCoroutine()
{
    yield return new WaitForSecondsRealtime(1.0f);
}

yield return new WaitForSecondsRealtime()은 괄호 안의 시간(초)이 지나면 yield return new WaitForSecondsRealtime()구문의 밑의 부분이 실행됩니다. 하지만 여기서의 시간은 Time.timeScale의 영향을 받지 않는 절대적인 시간을 의미합니다.

 

Time.timeScale 에 대해서 알자!

https://bluemeta.tistory.com/3

 

유니티 씬을 정지시킬 수 있는 Time.timeScale 프로퍼티 [유니티|Unity]

1. Time.timeScale이란? 원래 스케일(Scale)이란 단어의 뜻이 규모, 등급 등을 나타내듯이, 유니티에서 Time.timeScale 프로퍼티는 시간이 어떤 속도로 흘러가는지를 의미합니다. Time.timeScale의 값이 1.0f라면..

bluemeta.tistory.com

 

 

 

6.  yield return new WaitUntil();

public class CoroutineTester : MonoBehaviour
{
    int numA = 5, numB = 0;

	void Start ()
    {
        StartCoroutine(TestCoroutine());
	}    
    
    IEnumerator TestCoroutine()
    {
        Debug.Log("비교 시작");
        yield return new WaitUntil(()=>numA < numB);
        Debug.Log("비교 끝");
    }
    
    void Update()
    {
        Debug.Log(numA+" "+numB);
        numB++;
    }
}

 yield return new WaitUntil()은 괄호 안의 조건이 만족(결괏값이 true) 하게 되면  yield return new WaitUntil()의 밑의 구문이 실행됩니다. 실행 위치는 Update()와 LateUpdate() 이벤트 사이입니다.

 

7.  yield return new WaitWhile();

public class CoroutineTester : MonoBehaviour
{
    int numA = 5, numB = 0;

	void Start ()
    {
        StartCoroutine(TestCoroutine());
	}    
    
    IEnumerator TestCoroutine()
    {
    
        Debug.Log("비교 시작");
        yield return new WaitWhile(()=>numA < numB);
        Debug.Log("비교 끝");
    }
    
    void Update()
    {
        Debug.Log(numA+" "+numB);
        numB++;
    }
}

 yield return new WaitWhile()은 괄호 안의 조건이 만족하지 (결괏값이 false)  않는다면 yield return new WaitWhile()의 밑의 구문이 실행됩니다. 실행 위치는 Update()와 LateUpdate() 이벤트 사이입니다.

 

8. yield return StartCoroutine();

public class CoroutineTester : MonoBehaviour
{
    int numA, numB = 0;

	void Start ()
    {
        StartCoroutine(TestCoroutine());
	}
    IEnumerator TestCoroutine()
    {
        Debug.Log("비교 시작");
        yield return StartCoroutine(CountUp());
        Debug.Log("비교 끝");
    }
    IEnumerator CountUp()
    {
        yield return new WaitUntil(()=>numA < numB);
    }
    void Update()
    {
        Debug.Log(numA+" "+numB);
        numB++;
    }
}

 yield return new StartCoroutine()은 괄호 안의 쓰신 코루틴이 끝나면 yield return new StartCoroutine()의 밑의 구문이 실행됩니다.

 

 


 

yield return null : 다음 프레임까지 대기

 

yield return new WaitForSeconds(flaot) : 지정한 초 만큼 대기

 

yield return new WaitFixedUpdate() : 다음 FixedUpdate 까지 대기

 

yield return new WaitForEndOfFrame() : 모든 랜더링 작업이 끝날 때까지 대기

 

yield return startCoroutiune(string) : 다른 코루틴이 끝날 때까지 대기

 

yield return new www(string) : 웹 통신 작업이 끝날 때까지 대기

 

yield return new AsyncIoeration : 비동기 작업이 끝날 때까지 대기( 씬 로딩);

저작자표시

'Unity' 카테고리의 다른 글

[Unity] 스크립트 내에서 UnityEvent 클래스 활용하기  (0) 2020.04.10
[Unity3D] Animation - Animation Event 사용법(5.6기준)  (0) 2020.04.10
[Unity] GraphicRaycaster (UGUI 레이캐스팅 하기)  (0) 2020.04.08
[Unity] Delegate 와 Event 설명 모음출처  (0) 2020.04.06
[Unity3D] 트랜스폼(Transform) 크기(Scale)  (0) 2020.04.03
    'Unity' 카테고리의 다른 글
    • [Unity] 스크립트 내에서 UnityEvent 클래스 활용하기
    • [Unity3D] Animation - Animation Event 사용법(5.6기준)
    • [Unity] GraphicRaycaster (UGUI 레이캐스팅 하기)
    • [Unity] Delegate 와 Event 설명 모음출처
    성엽이
    성엽이

    티스토리툴바