php yield 携程,重新封装携程等待执行的方法 – WaitForSeconds

我在用携程等待执行的方法的时候,因为是多个方法调用,所以每执行一次,都要写一次携程等待的方法,麻烦更不好管理,在这里,我重新封装了一遍携程等待的方法,可以将要等待的方法传递给等待的携程,并且可以给传递的方法传递参数。

下面贴出我整理的代码

using System;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class TestSprite : MonoBehaviour {

// Use this for initialization

void Start() {

WaitSeconds(2f, TestMethod);

WaitSeconds(4f, TestMethod, "string", 1);

}

// Update is called once per frame

void Update() {

}

void TestMethod()

{

print("run TestMethod()");

}

void TestMethod(string name, int a)

{

print("run TestMethod()"+" name = " +name + " int = " + a);

}

void WaitSeconds(float time, Action method)

{

StartCoroutine(IEWaitSeconds(time, method));

}

void WaitSeconds(float time, Action method, string name, int a)

{

StartCoroutine(IEWaitSeconds(time, method,name,a));

}

IEnumerator IEWaitSeconds(float time,Action method)

{

yield return new WaitForSeconds(time);

method();

}

IEnumerator IEWaitSeconds(float time, Action method,string name,int a)

{

yield return new WaitForSeconds(time);

method(name,a);

}

}

以上代码便是我整理的方法,有什么意见欢迎进群一起讨论。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值