private void OnGUI() { GUILayout.Label("コルーチン実行状況 " + _count); if (GUILayout.Button("コルーチン実行")) { EndCoroutine(); _loop_coroutine = Co.Begin(Loop()); // or // _loop_coroutine = Loop().Begin(); } if (_loop_coroutine != null) { if (GUILayout.Button("コルーチン一時停止")) { Co.Pause(_loop_coroutine, true); // or // _loop_coroutine.Pause(true); } if (GUILayout.Button("コルーチン再開")) { Co.Pause(_loop_coroutine, false); // or // _loop_coroutine.Pause(false); } if (GUILayout.Button("コルーチン停止")) { EndCoroutine(); } } if (GUILayout.Button("Tween実行")) { _tweens.Play().Begin(); } }
public static IEnumerator Play(this CoTween[] tweens, string group_name = "", bool is_reverse = false) { foreach (var tween in tweens) { if (string.IsNullOrEmpty(group_name)) { Co.Begin(tween.Play(is_reverse)); } else if (tween.groupName == group_name) { Co.Begin(tween.Play(is_reverse)); } } foreach (var tween in tweens) { if (string.IsNullOrEmpty(group_name)) { while (tween.isPlaying && tween.playType == CoTween.ePlayType.PlayOnce) { yield return(null); } } else if (tween.groupName == group_name) { while (tween.isPlaying && tween.playType == CoTween.ePlayType.PlayOnce) { yield return(null); } } } }
// TODO: add static functions for waitforseconds, waitforcondition, etc. public static Co Start(float duration, System.Action <float> action, System.Action onEnd = null, Func <bool> condition = null) { Co co = new Co(); co.Begin(duration, action, onEnd, condition); return(co); }
IEnumerator _EditorPlay(CoTween[] tweens, string filter) { IEnumerator coroutine = Co.Begin(tweens.Play(filter)); _is_playing = true; while (coroutine.IsUpdating()) { yield return(null); } _is_playing = false; tweens.Reset(filter); }
/// <summary> /// インスペクタ表示をラップ /// </summary> public override void OnInspectorGUI() { base.OnInspectorGUI(); var tween = target as CoTween; if (!_is_playing) { if (GUILayout.Button("Play", GUILayout.ExpandWidth(false))) { Co.Begin(_EditorPlay(tween)); } } else { if (GUILayout.Button("Stop", GUILayout.ExpandWidth(false))) { tween.Reset(false); } } EditorGUILayout.BeginHorizontal(); if (!_is_playing) { if (GUILayout.Button("Play Children", GUILayout.ExpandWidth(false))) { Co.Begin(_EditorPlay(tween.gameObject.GetComponentsInChildren <CoTween>(true), _filter)); } } else { if (GUILayout.Button("Stop Children", GUILayout.ExpandWidth(false))) { tween.gameObject.GetComponentsInChildren <CoTween>(true).Reset(_filter); } } _filter = GUILayout.TextField(_filter); EditorGUILayout.EndHorizontal(); }
static void Test() { Co.Begin(CoroutineTest()); }
/// <summary> /// コルーチン開始 /// </summary> /// <param name="routine">コルーチン</param> /// <param name="type">更新タイプ</param> /// <returns>実行したコルーチン</returns> public static IEnumerator Begin(this IEnumerator routine, CoroutineDispatcher.eUpdateType type = CoroutineDispatcher.eUpdateType.Update) { return(Co.Begin(routine, type)); }
/// <summary> /// コルーチン実行 /// </summary> /// <param name="mono">紐づけるオブジェクト</param> /// <param name="coroutine">コルーチン</param> /// <param name="type">更新タイプ</param> /// <returns></returns> public static IEnumerator BeginCoroutine(this MonoBehaviour mono, IEnumerator coroutine, CoroutineDispatcher.eUpdateType type = CoroutineDispatcher.eUpdateType.Update) { return(Co.Begin(coroutine, mono.gameObject, type)); }