private IEnumerator stopAll_VerifyDidStop() { CoroutineOwnerMap <RadicalCoroutine> map = new CoroutineOwnerMap <RadicalCoroutine>(); bool testerDidFinish = false; bool testerDidCancel = false; ICoroutine coroutine = CoroutineRunner.Start(testerCoroutine(), this, "testerCoroutine"); coroutine.ECompleted += delegate { testerDidFinish = true; }; coroutine.ECancelled += delegate { testerDidCancel = true; }; map.Add(this, (RadicalCoroutine)coroutine); IntegrationTestEx.FailIf(map.GetCountForOwner(this) != 1); map.StopAll(); yield return(coroutine); IntegrationTestEx.FailIf(testerDidCancel); IntegrationTestEx.FailIf(testerDidFinish); IntegrationTestEx.FailIf(!coroutine.Disposed); IntegrationTestEx.FailIf(map.GetCountForOwner(this) != 0); }
public IEnumerator StartCoroutine(string script, ICoroutine coroutine) { var token = env.ParserToken(script); //词法分析 var expr = env.Expr_CompileToken(token, false); //语法分析,语法块 yield return(coroutine.StartNewCoroutine(env.Expr_Coroutine(expr, content, coroutine))); }
void Enable() { if (TimerSub == null && TimerCoroutine == null) { if (InitialDelay > 0.0f || RandomInitialDelayMax > 0.0f) { initialDelayTimeSpan = TimeSpan.FromSeconds(InitialDelay + RandomZeroToOne() * RandomInitialDelayMax); } intervalTimeSpan = TimeSpan.FromSeconds(Interval + RandomZeroToOne() * RandomIntervalMax); bool hasRegularInterval = (Interval > 0.0f) && (RandomIntervalMax == 0.0f); bool hasRandomInterval = (RandomIntervalMax > 0.0f); if (hasRegularInterval && Repeats) { TimerSub = Sansar.Script.Timer.Create(initialDelayTimeSpan, intervalTimeSpan, () => { SendToAll(OnTimer, thisObjectData); }); } else if (hasRandomInterval && Repeats) { TimerCoroutine = StartCoroutine(RepeatingRandomTimer); } else { TimerCoroutine = StartCoroutine(NonRepeatingTimer); } } }
public override void Begin() { base.Begin(); animator.Play("Walking"); StopWalk = Core.StartCoroutine(StopTimer()); direction = Utility.RandomPointOnCircle(); }
public override void Init() { // start a quick job ICoroutine quickWork = StartCoroutine(DoWork, 0.2); // Start up a couple of coroutines that will "work" for 10s ICoroutine worker1 = StartCoroutine(DoWork, 10.0); ICoroutine worker2 = StartCoroutine(DoWork, 10.0); worker1.Name = "WorkerOne"; // Default name would be "DoWork" worker2.Name = "WorkerTwo"; // Wait for quickWork to have finished. WaitFor(quickWork); // quickWork.IsAlive will now be false // Abort worker1. worker1.Abort(); // worker1.IsAlive will now be false // Note that it will never log "has finished" // Start up a coroutine that won't do anything until it gets a signal. ICoroutine signalWaiter = StartCoroutine(WaitUntilSignal); // Start a coroutine that will do some "work" then send a signal to signalWaiter. StartCoroutine(WorkThenSignal, 2.0, signalWaiter); WaitForAllCoroutines(); }
private void stopCoroutine(ICoroutine coroutine) { if (!(coroutine?.Disposed ?? true)) { coroutine.Stop(); } }
public void SetVisible(bool isVisible, bool instant = false) { if (base.gameObject.IsDestroyed() || (isVisible == _isVisible && !instant)) { return; } _isVisible = isVisible; fishCollider.enabled = _isVisible; UpdateParticleState(); if (_visibleRoutine != null) { _visibleRoutine.Stop(); _visibleRoutine = null; } if (instant) { float scale = 0f; if (isVisible) { scale = 1f; } SetScale(scale); } else { _visibleRoutine = CoroutineRunner.Start(ExecuteVisible(isVisible), this, "ExecuteVisible"); } }
public IEnumerator CoroutineCompute(CQ_Content content, ICoroutine coroutine) { #if CQUARK_DEBUG content.InStack(this); #endif content.DepthAdd(); CQ_Value value = null; foreach (ICQ_Expression i in _expressions) { ICQ_Expression e = i as ICQ_Expression; if (e != null) { if (e.hasCoroutine) { yield return(coroutine.StartNewCoroutine(e.CoroutineCompute(content, coroutine))); } else { value = e.ComputeValue(content); if (value != null && value.breakBlock != 0) { break; } } } } content.DepthRemove(); #if CQUARK_DEBUG content.OutStack(this); #endif yield break; }
private IEnumerator waitForLayoutGroupAdjustments(GameObject elementItemPrefab, int cellCount, bool isAsync) { LayoutRebuilder.MarkLayoutForRebuild(base.transform as RectTransform); yield return(new WaitForEndOfFrame()); contentStartBound = 0f - rectSize * 1.1f; contentEndBound = rectSize * 1.1f; this.elementItemPrefab = elementItemPrefab; if (ElementPoolOverride == null) { setUpElementPool(cellCount, isAsync); } else { elementPool = ElementPoolOverride; resizePoolForItemCount(cellCount); } scrollRect.onValueChanged.AddListener(onScrollRectUpdate); if (!isAsync) { for (int i = 0; i < cellCount; i++) { RectTransform rectTransform = createEmptyCell(); rectTransform.SetParent(scrollRect.content, worldPositionStays: false); } LayoutRebuilder.MarkLayoutForRebuild(base.transform as RectTransform); yield return(new WaitForEndOfFrame()); checkAllCells(ScrollDirection.beginning); } scrollRect.horizontalNormalizedPosition = Mathf.Clamp(customStartPosition / (0f - sizeDelta), 0f, 1f); scrollRect.verticalNormalizedPosition = 1f; isInitialized = true; waitForLayoutCoroutine = null; }
public DefaultAssetManager( IKernel kernel, IAssetLoader[] assetLoaders, IAssetSaver[] assetSavers, IProfiler[] profilers, IRawAssetLoader rawAssetLoader, IRawAssetSaver rawAssetSaver, ITransparentAssetCompiler transparentAssetCompiler, ICoroutine coroutine, IConsoleHandle consoleHandle) { _kernel = kernel; _assetLoaders = assetLoaders; _assetSavers = assetSavers; _profiler = profilers.Length > 0 ? profilers[0] : null; _rawAssetLoader = rawAssetLoader; _rawAssetSaver = rawAssetSaver; _transparentAssetCompiler = transparentAssetCompiler; _consoleHandle = consoleHandle; _assets = new Dictionary <string, ISingleAssetReference <IAsset> >(); _assetsToLoad = new ConcurrentQueue <ISingleAssetReference <IAsset> >(); _assetsToFinalize = new ConcurrentQueue <ISingleAssetReference <IAsset> >(); coroutine.Run(FinalizeAssets); }
void ApplyImpulse() { if (_resetCoroutine != null) { _resetCoroutine.Abort(); _resetCoroutine = null; } // Apply linear impulse force if (_applyLinearImpulse) { _rb.AddLinearImpulse(LinearImpulseDirection * LinearForce); } // Apply angular impulse force if (_applyAngularImpulse) { // Generate a new random angular impulse Vector angularImpulse = new Vector((float)_rng.NextDouble() * AngularVariance.X, (float)_rng.NextDouble() * AngularVariance.Y, (float)_rng.NextDouble() * AngularVariance.Z); // Apply the angular impulse if it is non-zero if (angularImpulse.LengthSquared() > 0.0f) { _rb.AddAngularImpulse(angularImpulse.Normalized() * AngularForce); } } if ((ResetTimeout > 0.0) && (_applyLinearImpulse || _applyAngularImpulse)) { _resetCoroutine = StartCoroutine(ResetAfterTimeout); } }
private void addCoroutineToGroup(ICoroutine coroutine, CoroutineGroup group) { if (!coroutine.Disposed && !coroutine.Cancelled && !coroutine.Completed) { group.Add(coroutine); } }
/// <summary> /// Only provided constructor needs a iterator block of course /// </summary> public Coroutine(IEnumerable <Instruction> source) { // Start processing right away _Source = source; _StateData = source.GetEnumerator(); _ExecutionState = CoroutineState.Running; _Subroutine = null; }
void Disable() { if (TimerCoroutine != null) { TimerCoroutine.Abort(); TimerCoroutine = null; } }
public CoroutineStack(IEnumerator <Step> root, ICoroutine rootCoroutine) { _stack = new List <EnumeratorWrapper>(); _stack.Add(new EnumeratorWrapper { Enum = root }); _rootCoroutine = rootCoroutine; }
private void StopFadeCoroutine() { if (fadeCoroutine != null) { fadeCoroutine.Abort(); fadeCoroutine = null; } }
public IEnumerator Expr_Coroutine(ICQ_Expression expr, CQ_Content content, ICoroutine coroutine) { if (content == null) { content = CreateContent(); } yield return(coroutine.StartNewCoroutine(expr.CoroutineCompute(content, coroutine))); }
void StopTimer() { if (TimerCoroutine != null) { TimerCoroutine.Abort(); TimerCoroutine = null; } }
private void StopInterpolation() { if (interpolationCoroutine != null) { interpolationCoroutine.Abort(); interpolationCoroutine = null; } }
public IEnumerator CoroutineCompute(CQ_Content content, ICoroutine coroutine) { content.InStack(this); content.DepthAdd(); ICQ_Expression expr_switch = listParam[0] as ICQ_Expression; CQ_Content.Value switchVal = null; // CQ_Content.Value vrt = null; if (expr_switch != null) { switchVal = expr_switch.ComputeValue(content); //switch// } for (int i = 1; i < listParam.Count - 1; i += 2) { if (listParam[i] != null) { //case xxx:// if (switchVal.value.Equals(listParam[i].ComputeValue(content).value)) { while (listParam[i + 1] == null) { i += 2; } content.DepthAdd(); if (listParam[i + 1].hasCoroutine) { yield return(coroutine.StartNewCoroutine(listParam[i + 1].CoroutineCompute(content, coroutine))); } else { listParam[i + 1].ComputeValue(content); } break; } else { continue; } } else { //default: content.DepthAdd(); if (listParam[i + 1].hasCoroutine) { yield return(coroutine.StartNewCoroutine(listParam[i + 1].CoroutineCompute(content, coroutine))); } else { listParam[i + 1].ComputeValue(content); } break; } } content.DepthRemove(); content.OutStack(this); }
private void startMoving() { setIsMoving(isMoving: true); if (movingCooldownTimer != null && !movingCooldownTimer.Disposed) { movingCooldownTimer.Stop(); } movingCooldownTimer = CoroutineRunner.Start(waitForMovingTimeout(), this, "waitForMovingTimeout"); }
public void CoroutineCall(string methodName, ICoroutine coroutine) { SType cclass = type.function as SType; if (cclass.functions.ContainsKey(methodName) || cclass.members.ContainsKey(methodName)) { coroutine.StartNewCoroutine(type.function.CoroutineCall(content, inst, methodName, null, coroutine)); } }
private void onTubeSelected(int tubeId) { slideController.DoAction(LocomotionController.LocomotionAction.Jump); if (loadTubeCoroutine != null && !loadTubeCoroutine.Cancelled && !loadTubeCoroutine.Completed && !loadTubeCoroutine.Disposed) { loadTubeCoroutine.Stop(); } loadTubeCoroutine = CoroutineRunner.Start(loadTube(tubeId), this, ""); }
public ProjectManagerMenuProvider( IProjectManager projectManager, IProjectManagerUi projectManagerUi, ICoroutine coroutine) { _projectManager = projectManager; _projectManagerUi = projectManagerUi; _coroutine = coroutine; }
public ConsoleLogShippingEngineHook( IRemoteClient remoteClient, ICoroutine coroutine, ILogShipping logShipping) { _remoteClient = remoteClient; _coroutine = coroutine; _logShipping = logShipping; }
public static bool Enqueue(ICoroutine coroutine) { if (IsQueued(coroutine)) return false; _queue.Enqueue(coroutine); return true; }
/// <summary> /// Returns the synchronous task that will complete after an internal <see cref="ICoroutine"/> is completed. /// </summary> /// <param name="coroutine">Implementation of the coroutine.</param> /// <exception cref="ArgumentNullException"> /// The <paramref name="coroutine"/> parameter is null. /// </exception> /// <example> /// <code> /// static IEnumerator<IRoutineAction> DoSomething() /// { /// var coroutine = new Coroutine(...); /// /// // Wait for the coroutine to complete. /// // At this point, execution pass to another routine. /// yield return Routine.Await(coroutine); /// /// Console.WriteLine("Completed!"); /// } /// </code> /// </example> public static ICoroutine Await(ICoroutine coroutine) { if (coroutine == null) { throw new ArgumentNullException(nameof(coroutine)); } return(new SyncWaitCoroutine(coroutine)); }
private IEnumerator runTestWrapper() { testCoroutine = testCoroutineRunner.StartTestCoroutine(runTest(), this, "runTest"); yield return(testCoroutine); while (isWaiting) { yield return(null); } }
void WorkThenSignal(double seconds, ICoroutine other) { // Add the seconds and name of what we are waiting for to this coroutine's name. CurrentCoroutine.Name += " " + seconds.ToString() + " " + other.Name; // simulate working with a Wait Wait(TimeSpan.FromSeconds(seconds)); other.Signal(); Wait(TimeSpan.FromSeconds(seconds)); Log.Write(CurrentCoroutine.Name + " has finished"); }
public static bool Enqueue(ICoroutine coroutine) { if (IsQueued(coroutine)) { return(false); } Queue.Enqueue(coroutine); return(true); }
public void Add(ICoroutine co) { if (co.LastKnownState == CoroutineState.Stopped) { co.Start(); } lock (_lock) { _queue.Enqueue(co); Monitor.PulseAll(_lock); } }
void NonRepeatingTimer() { Wait(initialDelayTimeSpan); SendToAll(OnTimer, thisObjectData); Wait(intervalTimeSpan); SendToAll(OnTimerAlt, thisObjectData); TimerCoroutine = null; }
public void Remove(ICoroutine co) { lock (_lock) { Queue<ICoroutine> copy = new Queue<ICoroutine>(_queue.Count * 2); while (_queue.Count != 0) { ICoroutine checkCo = _queue.Dequeue(); if (!checkCo.Equals(co)) { copy.Enqueue(co); } } _queue = copy; } }
public Scheduler() { MaxWaitTime = 1000.0f; MinWaitTime = 100.0f; m_coroutine = null; MaxTasksPerUpdate = 100; MaxFinishPerUpdate = 100; m_scheduledTasks = new LinkedList<IThreadedTask>(); m_finishedTasks = new LinkedList<IThreadedTask>(); m_runningTasks = new LinkedList<IThreadedTask>(); m_waitingTasks = new LinkedList<IThreadedTask>(); m_haveRan = new LinkedList<IThreadedTask>(); }
public Scheduler(int maxTasksPerUpdate, int maxFinishPerUpdate, ICoroutine coroutine) { MaxWaitTime = 1000.0f; MinWaitTime = 100.0f; m_coroutine = coroutine; MaxTasksPerUpdate = Math.Max(1, maxTasksPerUpdate); MaxFinishPerUpdate = Math.Max(1, maxFinishPerUpdate); m_scheduledTasks = new LinkedList<IThreadedTask>(); m_finishedTasks = new LinkedList<IThreadedTask>(); m_runningTasks = new LinkedList<IThreadedTask>(); m_waitingTasks = new LinkedList<IThreadedTask>(); m_haveRan = new LinkedList<IThreadedTask>(); }
private static async Task<bool> BotBehaviorTask() { while (_queue.Any()) { var coroutine = _queue.Dequeue(); CurrentTask = coroutine; bool result = false; coroutine.Reset(); while (!result) { result = await coroutine.GetCoroutine(); await Coroutine.Yield(); } CurrentTask = null; var disposable = coroutine as IDisposable; if (disposable != null) { disposable.Dispose(); } } return false; }
public static bool IsQueued(ICoroutine task) { return CurrentTask != null && CurrentTask.Id == task.Id || _queue.Any(i => i.Id == task.Id); }