mrtk_developmentreleases/2.0.0releases/2.1.0releases/2.2.0

    Show / Hide Table of Contents

    进度指示器 Progress Indicators

    Progress Indicators

    示例场景

    如何使用进度指示器的例子可以在ProgressIndicatorExamples场景中找到。这个场景演示了SDK中包含的每个进度指示器预置。

    示例:打开、更新和关闭进度指示器

    执行IProgressIndicator 界面。这个接口可以使用GetComponent从GameObject中获取。

    [SerializedField]
    private GameObject indicatorObject;
    private IProgressIndicator indicator;
    
    private void Start()
    {
        indicator = indicatorObject.GetComponent<IProgressIndicator>();
    }
    

    IProgressIndicator.OpenAsnyc() 和 IProgressIndicator.CloseAsync() 方法返回 Tasks。我们建议在aync方法中等待这些任务。

    将指示器的Progress属性设置为0-1,以更新其显示的进度。设置它的Message 属性来更新它显示的消息。不同的实现可能以不同的方式显示此内容。

    private async void OpenProgressIndicator()
    {
        await indicator.OpenAsync();
    
        float progress = 0;
        while (progress < 1)
        {
            progress += Time.deltaTime;
            indicator.Message = "Loading...";
            indicator.Progress = progress;
            await Task.Yield();
        }
    
        await indicator.CloseAsync();
    }
    

    指示器状态

    指示符的State属性决定哪些操作是有效的。调用无效方法通常会导致指示符报告错误而不采取任何行动。

    状态(State) 有效操作(Valid Operations)
    ProgressIndicatorState.Opening AwaitTransitionAsync()
    ProgressIndicatorState.Open CloseAsync()
    ProgressIndicatorState.Closing AwaitTransitionAsync()
    ProgressIndicatorState.Closed OpenAsync()

    AwaitTransitionAsync() 可以用来在使用指示器之前确保它是完全打开或关闭的。

    private async void ToggleIndicator(IProgressIndicator indicator)
    {
        await indicator.AwaitTransitionAsync();
        
        switch (indicator.State)
        {
            case ProgressIndicatorState.Closed:
                await indicator.OpenAsync();
                break;
    
            case ProgressIndicatorState.Open:
                await indicator.CloseAsync();
                break;
            }
        }
    
    • Improve this Doc
    In This Article
    • 示例场景
    • 示例:打开、更新和关闭进度指示器
    • 指示器状态
    Back to top Generated by DocFX