private void Update() { var deltaTime = !ignoreTimeScale ? Time.deltaTime : UpdateRealTimeDelta(); if (worldSpace) { if (mThreshold == 0f) { var vector = target - mTrans.position; mThreshold = vector.magnitude * 0.001f; } mTrans.position = NGUIMath.SpringLerp(mTrans.position, target, strength, deltaTime); var vector2 = target - mTrans.position; if (mThreshold >= vector2.magnitude) { mTrans.position = target; onFinished?.Invoke(this); if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished)) { eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver); } enabled = false; } } else { if (mThreshold == 0f) { var vector3 = target - mTrans.localPosition; mThreshold = vector3.magnitude * 0.001f; } mTrans.localPosition = NGUIMath.SpringLerp(mTrans.localPosition, target, strength, deltaTime); var vector4 = target - mTrans.localPosition; if (mThreshold >= vector4.magnitude) { mTrans.localPosition = target; onFinished?.Invoke(this); if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished)) { eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver); } enabled = false; } } }
private IEnumerator RunSequence() { OnStart?.Invoke(); for (int i = 0; i < nodeHolders.Count; i++) { if (nodeHolders[i].currentNode == null) { nodeHolders[i].currentNode = nodeHolders[i].head; } bool _run = true; while (_run) { yield return(new WaitUntil(() => Time.timeScale != 0)); yield return(StartCoroutine(nodeHolders[i].currentNode.Act())); nodeHolders[i].currentNode = nodeHolders[i].currentNode.NextNode(); if (nodeHolders[i].currentNode == null) { _run = false; } } } _isRunning = false; OnFinished?.Invoke(); yield return(0); }
static IEnumerator TweenSpriteScaleRoutine(GameObject g, Vector2 from, Vector2 to, int duration, Easing.Equation easing, int delay = 0, OnFinished onFinished = null) { if (delay > 0) { yield return(new WaitForMilliSeconds(delay)); } float durationF = duration * 0.001f; float time = 0; g.SetScaleXY(from.x, from.y); while (time < durationF) { float easeVal = Easing.Ease(easing, time, 0, 1, durationF); float easeValMapX = Mathf.Map(easeVal, 0, 1, from.x, to.x); float easeValMapY = Mathf.Map(easeVal, 0, 1, from.y, to.y); float scaleX = easeValMapX; float scaleY = easeValMapY; g.SetScaleXY(scaleX, scaleY); time += Time.delta; yield return(null); } onFinished?.Invoke(); }
public override void Update(float elapsedSeconds, float totalSeconds) { if (!IsRunning) { return; } elapsedSecondsSinceStart += elapsedSeconds; if (elapsedSecondsSinceStart >= delay) { float withoutDelay = elapsedSecondsSinceStart - delay; float inAnimation = withoutDelay / duration; inAnimation = easingFunction?.Invoke(inAnimation) ?? inAnimation; onTick(MathHelper.Lerp(start, end, inAnimation)); if (withoutDelay >= duration) { if (!IsLooping) { IsFinished = true; OnFinished?.Invoke(); // we allow to reset it if (IsFinished) { poolItem.Dispose(); } } delay = 0; elapsedSecondsSinceStart -= duration; } } }
public void Update(float deltaTime) { if (_delayPerFrame == 0 || !IsPlaying) { return; } if ((_timer += deltaTime) >= _delayPerFrame) { _timer -= _delayPerFrame; _index++; if (IsPlaying) { _randomIndex = RandomEX .Current.Next(_frames.Length); } if (_index >= MaxFrames) { _loops++; if (Loop) { _index -= MaxFrames; OnLoop?.Invoke(); } else { _index = MaxFrames - 1; OnFinished?.Invoke(); } } } }
private void T_DismantleChanged(object sender, EventArgs e) { Tile s = (Tile)sender; if (s.IsDismantled) { if (s.IsMine) { dismantledMines++; } else { incorrectDismantled++; } } else { if (s.IsMine) { dismantledMines--; } else { incorrectDismantled--; } } PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TotalDismantledMines))); if (dismantledMines == TotalMines) { timer.Stop(); OnFinished?.Invoke(this, null); } }
public void Rotate(float dt) { var x = (RunTime + dt) / Time; x = TimeFunction(x); var lastX = RunTime / Time; lastX = TimeFunction(lastX); if (x >= 1) { x = 1; var dx = (x - lastX) / (1 - lastX); var dv = (TargetRotation - GameObject.transform.rotation.eulerAngles) * dx; GameObject.transform.Rotate(dv); if (OnFinished != null) { OnFinished.Invoke(this, new EventArgs()); } } else { var dx = (x - lastX) / (1 - lastX); var dv = (TargetRotation - GameObject.transform.rotation.eulerAngles) * dx; GameObject.transform.Rotate(dv); } RunTime += dt; }
private void invokeFinished(int id, string text) { if (OnFinished != null) { OnFinished.Invoke(id, text); } }
public void BeginRun() { if (State == JobsManagerState.Bussy) { return; } State = JobsManagerState.Bussy; OnStart?.Invoke(this, new EventArgs()); try { jobs = jobsProvider.GetJobs(GetJobsContext()); AttachEvents(jobs); tasks = jobs.Select(x => x.GetTask()).Union(jobs.Select(x => x.GetBackTask())).ToArray(); Task.Factory.ContinueWhenAll(tasks, x => { OnFinished?.Invoke(this, new EventArgs()); State = JobsManagerState.Ready; }); } catch (AggregateException) { OnFailed?.Invoke(this, new EventArgs()); State = JobsManagerState.Ready; } }
/// <summary> /// Stop the core routine, make sure <paramref name="isFinished"/> is used internally to invoke event <see cref="OnFinished"/>. /// </summary> /// <param name="isFinished"></param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="InvalidOperationException"></exception> public void Stop(bool isFinished = false) { try { if (source.IsCancellationRequested || GetFlag == AutomatedRestarterFlag.Stopped) { throw new InvalidOperationException("AutomatedRestarter instance is already stopped."); } if (OnFinished == null) { throw new ArgumentNullException("OnFinished", "Event must be raised once routine finish its execution."); } source.Cancel(); if (isFinished) { OnFinished.Invoke(this, null); } GetFlag = AutomatedRestarterFlag.Stopped; } catch (Exception e) { if (e is InvalidCastException || e is ArgumentNullException) { onError.Invoke(null, e); } } }
void FixedUpdate() { if (_isDone) { return; } var currentPos = (float3)transform.position; float distanceToTarget = math.distance(currentPos, CurrentTarget); float maxMove = Time.fixedDeltaTime * Speed; if (distanceToTarget <= maxMove) { transform.position = CurrentTarget; _currentNode++; if (_currentNode == NodePoints.Count) { //DOne _isDone = true; OnFinished?.Invoke(); return; } } else { //MOve in direction var toTarget = math.normalize(CurrentTarget - currentPos); transform.position += (Vector3)(toTarget * maxMove); } }
public async Task StartGetAsyncSystemDate(string url, int connections = 1, int durationInSeconds = 1, CancellationToken token = default) { _url = url; try { var ctk = token; IsBusy = true; _localStopwatch.Reset(); await Task.Run(() => { GC.Collect(); Duration = TimeSpan.FromSeconds(durationInSeconds); var proccessCount = Environment.ProcessorCount; var events = new List <ManualResetEventSlim>(); var threads = new Thread[connections]; SetupClients(connections); OnStart?.Invoke(this, EventArgs.Empty); for (int i = 0; i < connections; i++) { var thread = new Thread(async(index) => await StartGetClient(Clients[(int)index], Duration, _localStopwatch, ctk)); threads[i] = thread; } Parallel.ForEach(threads, (thread) => { var index = Array.IndexOf(threads, thread); thread.Start(index); }); _localStopwatch.Restart(); foreach (var item in threads) { item.Join(); } }); _localStopwatch.Stop(); Elapsed = _localStopwatch.Elapsed; } catch (Exception) { } finally { IsBusy = false; } OnFinished?.Invoke(this, EventArgs.Empty); }
public void FadeInOut(GameObject parent, int duration = 1400, OnTransition onTransition = null, OnFinished onFinished = null, CenterMode centerMode = CenterMode.Min) { parent.AddChild(this); if (centerMode == CenterMode.Center) { SetXY(-width * 0.5f, -height * 0.5f); } else { SetXY(0, 0); } SetActive(true); SpriteTweener.TweenAlpha(this, 0, 1, duration / 2, o => { onTransition?.Invoke(); SpriteTweener.TweenAlpha(this, 1, 0, duration / 2, go => { onFinished?.Invoke(); SetActive(false); this.parent.RemoveChild(this); }); }); //CoroutineManager.StartCoroutine(instance.FadeInOutRoutine(time, onFinished)); }
private void ProcessableBusiness_OnFinished(object sender, ProcessorEventArgs e) { var process = sender as IProcessable; Value = e.Progress; OnFinished?.Invoke(process, e); }
/// <summary> /// 保存程序(新建程序需要调用SaveTo, 指定要保存的路径) /// </summary> /// <param name="onSaving"></param> /// <param name="onFinished"></param> /// <param name="onError"></param> /// <param name="onFinally"></param> public void Save(string filePath, Action onSaving, OnFinished onFinished, OnError onError, Action onFinally) { ThreadUtils.Run(() => { Stream fstream = null; try { onSaving?.Invoke(); fstream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); BinaryFormatter binFormat = new BinaryFormatter(); binFormat.Serialize(fstream, this); onFinished?.Invoke(); } catch (Exception e) { //throw e; onError?.Invoke(-1, e.ToString()); } finally { if (fstream != null) { fstream.Close(); } onFinally?.Invoke(); } }); }
/// <summary> /// 加载程序 /// </summary> /// <param name="programName">程序名称</param> /// <param name="onFinished"></param> /// <param name="onError"></param> public static void Load(string programPath, OnFinished <FluidProgram> onFinished, OnError onError) { Stream fstream = null; try { FluidProgram program = GetProgram(fstream, programPath); current = program; //传递程序中的速度重量键值对 SvOrGearValveSpeedWeightValve.VavelSpeedWeightDic = FluidProgram.CurrentOrDefault().runtimeSettings.VavelSpeedDic; onFinished?.Invoke(program); } catch (Exception e) { onError?.Invoke(-1, e.ToString()); } finally { if (fstream != null) { fstream.Close(); } } }
private void Update() { if (photonView.IsMine) { if (Input.GetKey(keyCode)) { currentHoldTime += Time.deltaTime; } else { currentHoldTime -= decayTime * Time.deltaTime; } currentHoldTime = Mathf.Clamp(currentHoldTime, 0, holdTime); if (currentHoldTime >= holdTime) { if (onFinished != null) { onFinished.Invoke(); } } } progressBar.currentPercent = currentHoldTime / holdTime * 100; }
public async Task RunAsync(CancellationToken cancellationToken) { var showRepository = unitOfWorkFactory .CreateUnitOfWork() .ShowRepository; var maxShowId = await showRepository.AnyAsync() ? await showRepository.GetMaxShowIdAsync() : 0; var pageToAsk = (int)maxShowId / TvMazePageSize; while (!cancellationToken.IsCancellationRequested) { OnNextPageGrabbing?.Invoke(this, pageToAsk); var moreShowsExist = await grabPageOfShowsScenario.RunAsync(pageToAsk, cancellationToken); if (!moreShowsExist) { OnFinished?.Invoke(this, pageToAsk); await Task.Delay(PauseWhenNoShowsLeftInMs, cancellationToken); } else { pageToAsk++; } } }
public void SetFinished() { Finished = true; Progress = 1.0f; OnFinished?.Invoke(); }
public void Move(float dt) { var x = (RunTime + dt) / Time; x = TimeFunction(x); var lastX = RunTime / Time; lastX = TimeFunction(lastX); if (x >= 1) { x = 1; var dx = (x - lastX) / (1 - lastX); var dv = (Destination - GameObject.transform.position) * dx; GameObject.transform.Translate(dv); if (OnFinished != null) { OnFinished.Invoke(this, new EventArgs()); } } else { var dx = (x - lastX) / (1 - lastX); var dv = (Destination - GameObject.transform.position) * dx; GameObject.transform.Translate(dv); } RunTime += dt; }
/// ------------------------------------------------------------------------------------ void HandleWorkerFinished(object sender, RunWorkerCompletedEventArgs e) { if (OnFinished != null) { OnFinished.Invoke(this, new ProgressFinishedArgs(false, _encounteredError)); } }
public async Task ExtractFiles() { try { IsExtracting = true; if (ExtractAll) { await ArchiveInfo.ExtractAllAsync(DestinationFolder, cancellationToken.Token, ExtractionProgress); } else { await ArchiveInfo.ExtractFilesAsync(FilesToExtract, DestinationFolder, ExtractionProgress, Timeout.InfiniteTimeSpan, cancellationToken.Token); } ExtractionState = ExtractionFinishedState.Succeed; } catch (OperationCanceledException) { ExtractionState = ExtractionFinishedState.Canceled; } catch (BA2ExtractionException) { ExtractionState = ExtractionFinishedState.Failed; } finally { IsExtracting = false; OnFinished?.Invoke(this, ExtractionState); } }
private void button1_Click_1(object sender, EventArgs e) { if (OnFinished != null) { OnFinished.Invoke(this, textBox1.Text); } this.Close(); }
private void Start(object o) { Visit(m_startNode); if (OnFinished != null) { OnFinished.Invoke(); } }
private void Button_Click(object sender, System.Windows.RoutedEventArgs e) { if (OnFinished != null) { OnFinished.Invoke(this, null); } IPageNavigatorHost.DockControl.Content = null; }
public bool Finish() { OnFinished?.Invoke(); UnityEngine.Object.Destroy(_model); UnityEngine.Object.Destroy(_obj); UnityEngine.Object.Destroy(_probe.gameObject); return(true); }
void FadeInAndFinish() { DrawableTweener.TweenSpriteAlpha(_fader, 0, 1, Settings.Default_AlphaTween_Duration, () => { Destroy(); _onFinished?.Invoke(); }); }
public bool Finish() { UnityEngine.Object.Destroy(_obj); UnityEngine.Object.Destroy(_spriteRenderer.gameObject); OnFinished?.Invoke(); return(true); }
public IGraphPath FindPath() { OnStarted?.Invoke(this, new AlgorithmEventArgs()); OnVertexVisited?.Invoke(this, new AlgorithmEventArgs()); OnVertexEnqueued?.Invoke(this, new AlgorithmEventArgs()); OnFinished?.Invoke(this, new AlgorithmEventArgs()); return(new NullGraphPath()); }
public override void IntentFinished() { if (player.Position == positionToTeleport) { Finished = true; OnFinished?.Invoke(this, new EventArgs()); } }