A brief analysis of the Unity3d in the continuous management of the chaotic yield

Source: Internet
Author: User

Excerpt from: http://www.unitymanual.com/thread-23724-1-1.html

First, let's look at the following code.

void Start () {     startcoroutine (Destroy ());} IEnumerator Destroy () {     yield return waitforseconds (3.0f);     Destroy (gameobject);}

This function is simple: Call the Startcoroutine function to open the process, yield wait for a period of time after the destruction of the object, because the process is waiting, so does not affect the main thread operation. Generally, the time to see here is not faint, yield is delayed after a period of time to continue to execute Bai, en, learned, and looked very useful.

Of course, yield can do much more than this simple specific time delay, for example, the next frame can continue to execute the code (yield return null), the next time the execution of Fixedupdate will continue to execute this code (yield new Waitforfixedupdate ();), you can let an asynchronous operation (such as Loadlevelasync) continue after completion, you can ... Can make you see dizziness.

Unity3d official interpretation of the process is that a synergistic program can use the yield statement anywhere during execution. The return value of yield controls when the recovery of the synergistic program executes downward. The Synergy program is excellent during the execution of the object's own frame. The synergistic program has no more overhead in performance. The Startcoroutine function is returned immediately, but yield can delay the result. Until the execution of the collaboration program is complete. (Original: The execution of a coroutine can be paused on any point using the yield statement. The yield return value specifies when the coroutine is resumed. Coroutines is excellent when modelling behaviour over several frames. Coroutines has virtually no performance overhead. Startcoroutine function always returns immediately, however you can yield the result. This'll wait until the coroutine has finished execution.)

If you just think yield for delay, then it can be used very smoothly, but if you see yield and so many functions, visual instantaneous messy, not to mention ingenious. However, if the principle of understanding, it is easy to clarify the various functions of yield.

public static ienumerable<int> Generatefibonacci () {     yield return 0;     Yield return 1;      int last0 = 0, Last1 = 1, current;      while (true)     {current         = last0 + last1;         yield return current;          Last0 = Last1;         Last1 = current;     } }

A brief analysis of the Unity3d in the continuous management of the chaotic yield

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.