public static Ev.CoroutineUnit StartCoroutineEx(this GameObject obj, IEnumerator fiber, System.Action f = null, System.Action c = null) { if (fiber == null) { return(null); } Ev.CoroutineUnit corutineUnit = obj.AddComponent <Ev.CoroutineUnit>() as Ev.CoroutineUnit; corutineUnit.Initialize(fiber, f, c); return(corutineUnit); }
public static Ev.CoroutineUnit StartCoroutineEx(this MonoBehaviour behaviour, string func, object[] param, System.Action finish = null, System.Action cancel = null) { if (null == behaviour) { return(null); } //Debug.Log("StartCoroutineEx " + behaviour.gameObject.name + " + " + func ); if (string.IsNullOrEmpty(func)) { NGUIDebug.Log("string.IsNullOrEmpty(func)"); Debug.LogError("string.IsNullOrEmpty(func)"); return(null); } MethodInfo m = behaviour.GetType().GetMethod(func, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); if (null == m) { NGUIDebug.Log("null == m " + func); Debug.LogError("null == m " + func); return(null); } if (m.ReturnType == typeof(IEnumerator)) { IEnumerator fiber = m.Invoke(behaviour, param) as IEnumerator; if (null == fiber) { Debug.LogError("null == fiber " + behaviour.gameObject.name + " + " + func); return(null); } Ev.CoroutineUnit corutineUnit = behaviour.gameObject.AddComponent <Ev.CoroutineUnit>() as Ev.CoroutineUnit; if (null == corutineUnit) { Debug.LogError("null == corutineUnit " + behaviour.gameObject.name + " + " + func); return(null); } corutineUnit.Initialize(fiber, func, finish, cancel); return(corutineUnit); } //Debug.Log("Not Found Coroutine " + behaviour.gameObject.name + " + " + func ); return(null); }
// Update is called once per frame void Update() { //Debug.Log( "Coroutine " + m_FunctionName + " Start"); if (m_Next != null) { bool isCancel = m_Next.cancel; if (false == isCancel) { bool isFinishNext = m_Next.finish; if (false == isFinishNext) { return; } //Debug.Log( "Stop Coroutine " + m_FunctionName + " Start"); m_Next.Stop(); //Debug.Log( "Stop Coroutine " + m_FunctionName + " End"); } else { //Debug.Log( "Cancel Coroutine " + m_FunctionName + " End"); m_Next.Cancel(); } m_Next = null; } if (m_Cancel) { Cancel(); return; } if (m_Condition != null && !m_Condition.check) { return; } if (null == m_Fiber) { Cancel(); return; } if (!m_Fiber.MoveNext()) { Stop(); return; } object res = m_Fiber.Current ?? "null"; if (res is string) { if ((string)res == "break") { //Debug.Log( "Breaking functuion " + m_FunctionName ); Cancel(); //Debug.Log( "Breaking functuion End " + m_FunctionName ); } else if ((string)res == "end") { Stop(); } } else if (res is CoroutineUnit) { m_Next = (CoroutineUnit)res; } else if (res is CoroutineCondition) { m_Condition = (CoroutineCondition)res; } else if (res is Breaking) { Cancel(); } else { UnityEngine.Debug.LogError("Unexpected coroutine yield type: " + res.GetType()); } }