用户工具

站点工具


侧边栏



Unity3D中文文档

script:unityengine:classes:waituntil:waituntil

WaitUntil 等待直到为真

class in UnityEngine / Inherits from: CustomYieldInstruction

Description 描述

Suspends the coroutine execution until the supplied delegate evaluates to true.

直到提供的委托计算为真,挂起协程执行。

WaitUntil can only be used with a yield statement in coroutines.

WaitUntil只能在协程的yield语句使用。

Supplied delegate will be executed each frame after script MonoBehaviour.Update and before MonoBehaviour.LateUpdate. When the delegate finally evaluates to true, the coroutine will proceed with its execution.

提供的委托在MonoBehaviour.Update之后并在MonoBehaviour.LateUpdate之前每帧执行。当委托最终计算为true时,协程将继续执行。

C#:

using UnityEngine;
using System.Collections;
 
public class WaitUntilExample: MonoBehaviour {
    public int frame;
 
    void Start() {
        StartCoroutine(Example());
    }
 
    IEnumerator Example() {
        Debug.Log("Waiting for princess to be resqued...");
        yield return new WaitUntil(() => frame >= 10);
        Debug.Log("Princess was resqued!");
    }
 
    void Update() {
        if (frame <= 10)
        {
            Debug.Log("Frame: " + frame);
            frame++;
        }
    }
}

Constructors 构造器

WaitUntil.WaitUntilInitializes a yield instruction with a given delegate to be evaluated.
用给定的委托计算来初始化一个yield指令。
script/unityengine/classes/waituntil/waituntil.txt · 最后更改: 2016/08/02 05:27 (外部编辑)