public static CoroutineObj StartSceneCoroutineTimer(CoroutineAction co) { GameObject go = new GameObject(); CoroutineObj obj = go.AddComponent <CoroutineObj>(); obj.StartCoroutine(co()); go.name = "_Timer" + co.Target.ToString(); return(obj); }
public static void Stop(CoroutineObj obj) { if (obj == null) { return; } Instance.coroutineList.Remove(obj); }
//开始一个非Monobehavour的协程,CoroutineDelegate内的CoroutineObj成员代表各种可用的协程yield指令 //有boxing和alloc,慎用 public static CoroutineObj Start(CoroutineDelegate func) { var obj = new CoroutineObj(); obj.Enumerator = func(obj); Instance.coroutineList.Add(obj); return(obj); }
// Start is called before the first frame update IEnumerator Start() { var cor = new CoroutineObj(); cor.SetRunner(this); cor.StartCoroutine(E1()); yield return(new WaitForSeconds(2)); cor.StartCoroutine(E2()); }
/// <summary> /// 会随着场景切换而清理的coroutine /// </summary> /// <param name="co">Co.</param> public static CoroutineObj StartSceneCoroutine <T1, T2>(CoroutineAction <T1, T2> co, T1 t1, T2 t2, bool destory = true) { GameObject go = new GameObject(); CoroutineObj obj = go.AddComponent <CoroutineObj>(); obj.StartCoroutine(co(t1, t2)); go.name = "_co" + co.Target.ToString(); if (destory) { optimized_Destory(go, 3f); } //else // SceneManager.instance.clearOnChangeScene.Add(go); return(obj); }
public static CoroutineObj StartSceneCoroutine(CoroutineAction_Params co, bool destory = true, params object[] args) { GameObject go = new GameObject(); CoroutineObj obj = go.AddComponent <CoroutineObj>(); obj.StartCoroutine(co(args)); go.name = "_co" + co.Target.ToString(); if (destory) { optimized_Destory(go, 3f); } else { SceneManager.instance.clearOnChangeScene.Add(go); } return(obj); }
/// <summary> /// Async Load perfabs /// </summary> /// <param name="path"></param> /// <param name="Callback"></param> public void LoadGameObjectAsync(string path, Action <UnityEngine.GameObject> Callback) { if (SceneManager.couroutineObj == null) { Debug.Log(" 场景切换中,终止场景内的异步加载执行!"); return; } CoroutineObj obj = SceneManager.couroutineObj.GetComponent <CoroutineObj>(); obj.StartCoroutine(LoadAsync(path, (asset) => { if (asset == null) { throw new UnityException("can not load game object:" + path); } GameObject go = (GameObject)Instantiate(asset); Callback(go); })); }