public static NatCamDispatch Prepare(DispatchMode Mode, MonoBehaviour TimesliceProvider = null, int Rate = 15) { NatCamDispatch dispatch = new NatCamDispatch { mode = Mode, mainThread = Thread.CurrentThread, timesliceProvider = TimesliceProvider, invocation = new Queue(), update = new Queue(), execution = new Queue(), running = true }; dispatch.workerThread = Mode == DispatchMode.Asynchronous ? new Thread(() => dispatch.Routine <Camera>(dispatch.Update, Rate)) : null; dispatch.targetThread = Mode == DispatchMode.Asynchronous ? dispatch.workerThread : dispatch.mainThread; if (Mode == DispatchMode.Synchronous) { if (dispatch.timesliceProvider) { dispatch.routine = Routine <Camera>(dispatch.Update, new WaitForEndOfFrame()).Invoke(dispatch.timesliceProvider); } else { Camera.onPostRender += dispatch.Update; } } else { dispatch.workerThread.Start(); } Ext.Log("NatCam: Initialized " + Mode + " Dispatcher"); return(dispatch); }
public static void Release(NatCamDispatch dispatch) { if (dispatch == null || !dispatch.running) { return; } dispatch.running = false; if (dispatch.mode == DispatchMode.Synchronous) { if (dispatch.routine != null) { dispatch.routine.Terminate(dispatch.timesliceProvider); } else { Camera.onPostRender -= dispatch.Update; } } else { dispatch.workerThread.Join(); } Ext.Log("NatCam: Released " + dispatch.mode + " Dispatcher"); }