用户工具

站点工具


侧边栏



Unity3D中文文档

script:unityengine:classes:waitwhile:waitwhile

WaitWhile 等待直到为假

class in UnityEngine / Inherits from: CustomYieldInstruction

Description 描述

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

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

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

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

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

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

C#:

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

Constructors 构造器

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