Created
August 22, 2014 00:47
-
-
Save baobao/9da895015ada1938a31e to your computer and use it in GitHub Desktop.
コルーチンを一括管理するマネージャークラスをつくろうとしたけど、IEnumratorのAPIが少なくて、断念したソース
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| public class CoroutineManager : MonoBehaviour { | |
| private static int coroutineID = 0; | |
| private Dictionary<int, IEnumerator> _dic; | |
| public object GretCurrent (int id) | |
| { | |
| IEnumerator cor = GetCoroutine (id); | |
| if (cor != null) | |
| { | |
| return cor.Current; | |
| } | |
| } | |
| public int Register (IEnumerator coroutine) | |
| { | |
| _dic.Add (coroutineID, coroutine); | |
| coroutineID++; | |
| } | |
| public void Pause (int id) | |
| { | |
| IEnumerator cor = GetCoroutine (id); | |
| if (cor != null) | |
| { | |
| StopCoroutine (cor); | |
| } | |
| } | |
| void Awake () { | |
| coroutineID = 0; | |
| DontDestroyOnLoad (gameObject); | |
| } | |
| private IEnumerator GetCoroutine (int id) | |
| { | |
| IEnumerator cor = null; | |
| _dic.TryGetValue (id, out cor); | |
| return cor; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment