自定义IEnumerator

1、启动脚本

public class IEnumeratorTeset : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.I))
        {
            StartCoroutine(Testtt());
        }
    }
    IEnumerator Testtt()
    {
        Debug.LogError("Go ");
        yield return new Test();
        Debug.LogError("End ");
    }
}

2、自定义迭代器

public class Test : IEnumerator
{
    public object Current => null;
    private bool emmm = true;
    public Test()
    {
        Asy();
    }
    public bool MoveNext()
    {
        Debug.LogWarning("yayayaya  ?");
        return emmm;
    }
    async void Asy()
    {
        await Task.Run(() =>
        {
            for (int i = 0; i < 1000; i++)
            {
               Debug.Log( i+"  ");
            }
        });
        emmm = false;
    }

    public void Reset()
    {
    }
}

3、测试结果

 

 

Guess you like

Origin blog.csdn.net/LM514104/article/details/120732951