°ÔÀÓ±â¼úÀÚ·á
¤ýÀÛ¼ºÀÚ ¹èÀçȯ
¤ýÀÛ¼ºÀÏ 2011-09-22 (¸ñ) 11:47
¤ýȨÆäÀÌÁö http://ugame.tu.ac.kr/webboard
¤ýÃßõ: 0  ¤ýÁ¶È¸: 1047      
¤ýIP: 210.xxx.56
Unity3D-Overview: Coroutines & Yield
°ÔÀÓ Äڵ带 ¾µ ¶§, Çϳª´Â À̺¥Æ®ÀÇ ¼ø¼­¸¦ ½ºÅ©¸³Æ®¸¦ ÇÊ¿äÇØ ÇÏ¸é ³¡³»¾ßÇÑ´Ù. ÀÌ°ÍÀº ´ÙÀ½°ú °°ÀÌ Äڵ忡¼­ °á°ú¸¦ ³¾ ¼ö ÀÖ´Ù.

1. JavaScript
private var state = 0;

function Update() {
if (state == 0) {
// do step 0
state = 1;
return;
}
if (state == 1) {
// do step 1
state = 2;
return;
}
// ...
}

2. C#
using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
private int state = 0;
void Update() {
if (state == 0) {
state = 1;
return;
}
if (state == 1) {
state = 2;
return;
}
}
}

±×°ÍÀº yield statement¸¦ »ç¿ëÇÏ´Â °ÍÀÌ ´õ Æí¸®ÇÏ´Ù. yield statement´Â Ưº°ÇÑ Á¾·ùÀÌ´Ù return, ±â´ÉÀº ´ÙÀ½ ½Ã°£¿¡ ºÒ¸®´Â yield statementÈÄ¿¡ ¶óÀο¡¼­ °è¼Ó µÇ¾îÁú °ÍÀÌ È®½ÇÇÏ´Ù.

1. JavaScrpit
while(true) {
// ½ºÅÜ 0À» Ç϶ó
yield; //ÇÑ ÇÁ·¹ÀÓÀ» ±â´Ù·Á¶ó
// ½ºÅÜ 1À» Ç϶ó
yield; // ÇÑ ÇÁ·¹ÀÓÀ» ±â´Ù·Á¶ó
// ...
}

2. C#
using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
IEnumerator Awake() {
while (true) {
yield return null;
yield return null;
}
}
}

´ç½ÅÀº ¶ÇÇÑ ½ÇÇàÀÌ Áö¿¬µÇ¾î yield statement¿¡ ´ëÇÑ Æ¯º°ÇÑ °ªÀ» Åë°ú ÇÒ ¼ö ÀÖ´Ù Update ƯÁ¤ÇÑ À̺¥Æ®°¡ ¹ß»ýµÉ¶§ ±îÁö ±â´É.
  0
2500
    N     ºÐ·ù     Á¦¸ñ    ±Û¾´ÀÌ ÀÛ¼ºÀÏ Á¶È¸
14 ÀÏ¹Ý Unity3D-Overview: The most important classes(3) ¹èÀçȯ 2011-09-22 1166
13 ÀÏ¹Ý Unity3D-Overview: The most important classes(2) ¹èÀçȯ 2011-09-22 1079
12 ÀÏ¹Ý Unity3D-Overview: The most important classes(1) ¹èÀçȯ 2011-09-22 953
11 ÀÏ¹Ý Unity3D-Overview: Writing Scripts in C# ¹èÀçȯ 2011-09-22 1926
10 ÀÏ¹Ý Unity3D-Overview: Coroutines & Yield ¹èÀçȯ 2011-09-22 1047
9 ÀÏ¹Ý UnIty3D-Overview: Instantiate ¹èÀçȯ 2011-09-22 870
8 ÀÏ¹Ý Unity3D-Overview: Member Variables & Global Variables ¹èÀçȯ 2011-09-22 944
7 ÀÏ¹Ý Unity3D-Overview: Vectors ¹èÀçȯ 2011-09-22 928
6 ÀÏ¹Ý Unity3D-Overview: Accessing Other Game Objects ¹èÀçȯ 2011-09-22 988
5 ÀÏ¹Ý Unity3D-Overview: Accessing Other Components ¹èÀçȯ 2011-09-22 897
4 ÀÏ¹Ý Unity3D-Overview: Keeping Track of Time ¹èÀçȯ 2011-09-22 931
3 ÀÏ¹Ý Unity3D-Overview: Common Operations ¹èÀçȯ 2011-09-22 879
2 ÀÏ¹Ý ³Í ÇÒ ¼ö ÀÖ¾î °­»ó¿¡ 2011-03-22 907
1 ÀÏ¹Ý ÀϾ ±è±¤¼® 2011-03-22 872
123