/// <summary> /// Start a coroutine on a new gameObject /// </summary> /// <returns></returns> /// <param name="coroutine"></param> public static OneShotCoroutine PlayCoroutine(IEnumerator coroutine) { #if NET_4_6 string coroutineName = (useEmptyNames) ? string.Empty : $"Coroutine: {coroutine.ToString()}"; #else string coroutineName = (useEmptyNames) ? string.Empty : string.Format("Coro: {0}", coroutine.ToString()); #endif GameObject coroutinePlayer = new GameObject(coroutineName); #if UNITY_EDITOR if (hiddenInHierarchy) { coroutinePlayer.hideFlags = underTheHoodFlags; } #endif OneShotCoroutine oneShotCoroutineComponent = coroutinePlayer.AddComponent <OneShotCoroutine>(); oneShotCoroutineComponent.LaunchCoroutine(coroutine); return(oneShotCoroutineComponent); }
/// <summary> /// Invokes an action after the specified time with a coroutine on a new GameObject. /// </summary> /// <returns></returns> /// <param name="action"></param> /// <param name="delay"></param> public static OneShotCoroutine PlayDelayedAction(Action action, WaitForSeconds delay) { #if NET_4_6 string actionName = (useEmptyNames) ? string.Empty : $"Action: {action.ToString()}"; #else string actionName = (useEmptyNames) ? string.Empty : string.Format("Action: {0}", action.ToString()); #endif GameObject coroutinePlayer = new GameObject(actionName); #if UNITY_EDITOR if (hiddenInHierarchy) { coroutinePlayer.hideFlags = underTheHoodFlags; } #endif OneShotCoroutine oneShotCoroutineComponent = coroutinePlayer.AddComponent <OneShotCoroutine>(); oneShotCoroutineComponent.LaunchDelayedAction(action, delay); return(oneShotCoroutineComponent); }