/// <summary> /// Enqueue the persistant routine provided as the parameter /// OnSceneLoaded, Call the implementation of Invoke exposed by the IPersistantRoutine interface /// Then remove the routine from the list of active routines /// The "Enqueue" part of the name is to let the user know that the invocations will happen in the order they were provided. /// </summary> /// <param name="routine"></param> public void EnqueuePersistantRoutine(IPersistantRoutine routine) { if (_routines == null) { Debug.LogError("PersistantRoutineManager not initialized yet. Please wait until its Awake function is Invoked before Adding a routine"); return; } _routines?.Add(routine); }
public void Awake() { _initializedRoutines = new IPersistantRoutine[RoutinesToEnqueue.Length]; IPersistantRoutine r = null; for (int i = 0; i < RoutinesToEnqueue.Length; ++i) { r = OnSceneLoadedPersistantRoutineFactory.GetPersistantRoutine(RoutinesToEnqueue[i]); _initializedRoutines[i] = r; } }
private static IPersistantRoutine GetPersistantRoutine(PersistantRoutineType type, MethodInfo toInvoke, params string[] _scenesToInvokeOn) { IPersistantRoutine toReturn = null; switch (type) { case PersistantRoutineType.OneShot: { if (_scenesToInvokeOn == null || _scenesToInvokeOn.Length == 0) { Debug.LogWarning("Cannot create a OneShot routine if no scene name is specified"); } else { OneShotPersistantRoutine routine = new OneShotPersistantRoutine(); routine.Initialize(_scenesToInvokeOn[0]); toReturn = routine; } } break; case PersistantRoutineType.BlindOneShot: { BlindOneShotPersistantRoutine routine = new BlindOneShotPersistantRoutine(); toReturn = routine; } break; default: { throw new System.NotImplementedException(); } } toReturn?.AssignRoutine(toInvoke); if (!toReturn.IsValid) { Debug.Log("Invalid PersistantRoutine. It will not invoke."); } return(toReturn); }