• Coroutine 复习


    https://docs.unity.cn/cn/current/ScriptReference/Coroutine.html

    https://docs.unity.cn/cn/current/ScriptReference/YieldInstruction.html

    https://docs.unity.cn/cn/current/ScriptReference/AsyncOperation.html

    https://www.cnblogs.com/revoid/p/6663922.html

    https://docs.unity.cn/cn/current/ScriptReference/WaitUntil.html

    https://docs.unity.cn/cn/current/ScriptReference/WaitWhile.html

    using System;
    using System.Runtime.InteropServices;
    
    namespace System.Collections
    {
        /// <summary>Supports a simple iteration over a nongeneric collection.</summary>
        /// <filterpriority>1</filterpriority>
        // Token: 0x02000011 RID: 17
        [ComVisible(true)]
        [Guid("496B0ABF-CDEE-11d3-88E8-00902754C43A")]
        public interface IEnumerator
        {
            /// <summary>Advances the enumerator to the next element of the collection.</summary>
            /// <returns>true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.</returns>
            /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception>
            /// <filterpriority>2</filterpriority>
            // Token: 0x060000A9 RID: 169
            bool MoveNext();
    
            /// <summary>Gets the current element in the collection.</summary>
            /// <returns>The current element in the collection.</returns>
            /// <exception cref="T:System.InvalidOperationException">The enumerator is positioned before the first element of the collection or after the last element.</exception>
            /// <filterpriority>2</filterpriority>
            // Token: 0x17000010 RID: 16
            // (get) Token: 0x060000AA RID: 170
            object Current { get; }
    
            /// <summary>Sets the enumerator to its initial position, which is before the first element in the collection.</summary>
            /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception>
            /// <filterpriority>2</filterpriority>
            // Token: 0x060000AB RID: 171
            void Reset();
        }
    }
    IEnumerator
    public class CustomIEnumerator : IEnumerator {
        public object Current { get; }
    
        // true if the enumerator was successfully advanced to the next element; 
        // false if the enumerator has passed the end of the collection
        public bool MoveNext() {
            return false;
        }
    
        public void Reset() {
            throw new System.NotImplementedException();
        }
    }
    
    private IEnumerator IE_Test() {
        Debug.Log("1");
        // MoveNext() 返回 false 时, 才能执行后续语句
        yield return new CustomIEnumerator();
        Debug.Log("2");
    }
    CustomIEnumerator

    private IEnumerator IE_Test() {
        AsyncOperation ao = SceneManager.LoadSceneAsync("Game");
        while(!ao.isDone) {
            Debug.Log(ao.progress);
            yield return null;
        }
    }
    AsyncOperation
    private IEnumerator IE_Test() {
        yield return new WaitForEndOfFrame();
        Debug.Log("AfterEndOfFrame");
        // e.g. 2
        Debug.Log(Time.frameCount);
    
        yield return new WaitForFixedUpdate();
        Debug.Log("AfterFixedUpdate");
        // e.g. 3
        Debug.Log(Time.frameCount);
    }
    WaitForEndOfFrame&WaitForFixedUpdate
    private IEnumerator IE_Test() {
        yield return new WaitForSeconds(5);
        Debug.Log("After5Seconds");
    }
    WaitForSeconds
    private IEnumerator IE_Test() {
        ResourceRequest rr = Resources.LoadAsync("Image");
        while (!rr.isDone) {
            Debug.Log(rr.progress);
            yield return null;
        }
    }
    ResourceRequest
    private IEnumerator IE_Test() {
        UnityWebRequest uwr = new UnityWebRequest("https://www.baidu.com");
        UnityWebRequestAsyncOperation async = uwr.SendWebRequest();
        yield return async;
        Debug.Log(async.progress);
        while (!async.isDone) {
            Debug.Log(async.progress);
        }
        Debug.Log(async.isDone);
    }
    UnityWebRequestAsyncOperation
    private IEnumerator IE_Test() {
        WWW www = new WWW("");
        AssetBundleRequest abr = www.assetBundle.LoadAssetAsync("");
        yield return abr;
    }
    AssetBundleRequest
    private IEnumerator IE_Test() {
        AssetBundleCreateRequest abcr = AssetBundle.LoadFromFileAsync("");
    }
    AssetBundleCreateRequest
    private IEnumerator IE_Test() {
        yield return new WaitForSeconds(1);
        Debug.Log("WaitForSeconds");
    }
    WaitForSeconds
    private IEnumerator IE_Test() {
    
        yield return new WaitUntil(Test);
        Debug.Log("True");
    }
    
    bool Test() {
        Debug.Log(Time.frameCount);
        return Time.frameCount > 1000;
    }
    WaitUntil
    private IEnumerator IE_Test() {
    
        yield return new WaitWhile(Test);
        Debug.Log("False");
    }
    
    bool Test() {
        Debug.Log(Time.frameCount);
        return Time.frameCount < 1000;
    }
    WaitWhile
  • 相关阅读:
    AOP 学习
    微服务架构理解[架构图](转)
    C# TSC打印二维码和条形码(转)
    C#注册表操作类--完整优化版(转)
    C#调用TSC条码打印机打印二维码(转)
    C#调用TSC条码打印机打印条码(转)
    TSC打印机使用教程终极版(转)
    海尔电商峰值系统架构设计最佳实践(转)
    亿级Web系统搭建——单机到分布式集群(转)
    数据库扩展性设计:使用二进制解决一条记录关联多个状态的问题(转),可以尝试一下
  • 原文地址:https://www.cnblogs.com/revoid/p/14376407.html
Copyright © 2020-2023  润新知