// Update is called once per frame void Update() { if (isSet) { if (isRun) { if (!isReturnMin) { if (prevRatio < showRatio) { prevRatio = (int)DataUtil.LimitFloat(Mathf.CeilToInt(prevRatio + upSpeed * Time.deltaTime), showRatio, isReturnMin); text.text = prevRatio.ToString(); } else { text.text = showRatio.ToString(); isRun = false; isSet = false; prevRatio = showRatio; if (onComplete != null) { onComplete.Invoke(); onComplete = null; } } } else { if (prevRatio > showRatio) { prevRatio = (int)DataUtil.LimitFloat(Mathf.CeilToInt(prevRatio + upSpeed * Time.deltaTime), showRatio, isReturnMin); text.text = prevRatio.ToString(); } else { text.text = showRatio.ToString(); isRun = false; isSet = false; prevRatio = showRatio; if (onComplete != null) { onComplete.Invoke(); onComplete = null; } } } } } else { isRun = false; } }
public void SaveToRealm(ItemData[] items) { int current = 0, total = items.Length; using (var trans = realm.BeginWrite()) { //realm.RemoveAll() foreach (var itemData in items) { realm.Add(itemData); if (OnProgress == null) { continue; } if (++current % 10 == 0 || current == total) { OnProgress(current, total); } } trans.Commit(); } Realm.Compact(); realm.Dispose(); OnComplete?.Invoke(); }
private void CheckParamsReady(Parameter parameter) { if (readyParams.Contains(parameter)) { return; } readyParams.Add(parameter); readyAttributesCounter++; if (readyAttributesCounter != parameters.Count) { return; } ClearAttributesEvents(); var dict = ConvertToDictionary(); OnAllReady?.Invoke(dict); OnAllReady = null; OnComplete?.Invoke(); OnComplete = null; mediator.Notify(this, "OnParamsLoaded"); }
public void CheckForComplete() { if (CompleteCondition != null && CompleteCondition(orderTarget) && executed) { OnComplete?.Invoke(); } }
void onCompleteCallback() { if (onComplete != null) { onComplete.Invoke(); } }
//-------------------------------------------------------------------------------------- /// <summary> /// Update - calculates the animation delta and calls the attached animation code /// </summary> //-------------------------------------------------------------------------------------- internal void Update(GameTime gameTime) { if (IsComplete) { return; } if (_animationStartTime == null) { _animationStartTime = gameTime.TotalGameTime; } var animationProgressSeconds = (gameTime.TotalGameTime - _animationStartTime.Value).TotalSeconds; if (_animationDurationSeconds > 0) { Animate(Math.Min(Math.Max(0, animationProgressSeconds / _animationDurationSeconds), 1)); if (animationProgressSeconds >= _animationDurationSeconds) { OnComplete?.Invoke(); IsComplete = true; } } else { Animate(animationProgressSeconds); } }
private void ExecuteNext(IAsyncOperation previous) { if (0 == operationsQueue.Count) { Result = currentOperation?.Result; Done = true; OnComplete?.Invoke(); return; } var nextOperationFunc = operationsQueue.Dequeue(); var nextOperation = nextOperationFunc(previous); if (nextOperation.Done) { ExecuteNext(currentOperation); } else { nextOperation.OnComplete += () => ExecuteNext(currentOperation); } currentOperation = nextOperation; }
private void FixedUpdate() { foreach (var agent in agents) { agent.times[agent.path.WaypointQuery(agent.navigator.Distance).waypoint.index] = Time.time; if (agent.navigator.Lap >= 1) { completed.Add(agent); } } foreach (var agent in completed) { agents.Remove(agent); GameObject.Destroy(agent.navigator.gameObject); Debug.Log("Finish Time: " + agent.path.coefficient + " " + Time.time + " s"); } completed.Clear(); if (agents.Count <= 0) { if (OnComplete != null) { OnComplete.Invoke(this); } } }
/// <summary> /// 在指定目录中查找所有字符串 /// </summary> public void Search(string[] folders, string[] needles, string[] filters, bool ignoreCase) { _files = new List <string>(); _needles = needles; _comparison = ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture; _extensions = new HashSet <string>(filters); //Collect files double prog = 0.0, progAdv = 1.0 / folders.Length; for (int i = 0; i < folders.Length; i++) { CollectInFolders(folders[i], prog, progAdv); ReportProgress(prog += progAdv); } //Check file count if (_files.Count == 0) { OnComplete?.Invoke(); return; } //Search in files ReportProgress(prog = 0.0); progAdv = 1.0 / _files.Count; Parallel.ForEach(_files, SearchInFile); }
public IEnumerator Execute() { var time = 0f; var currentScale = RectTransform.localScale; while (RectTransform.localScale != MaxSize) { time += Time.deltaTime * ScaleSpeed; var scale = Vector3.Lerp(currentScale, MaxSize, time); RectTransform.localScale = scale; yield return(null); } yield return(Wait); currentScale = RectTransform.localScale; time = 0f; while (RectTransform.localScale != Vector3.one) { time += Time.deltaTime * ScaleSpeed; var scale = Vector3.Lerp(currentScale, Vector3.one, time); RectTransform.localScale = scale; yield return(null); } OnComplete?.Invoke(this); }
private IEnumerator UpdateCoroutine() { while (timeLeft > 0 && !isComplete) { yield return(null); _preTime = timeLeft; timeLeft = GetTimeLeft(); if (_preTime != timeLeft) { OnUpdate?.Invoke(timeLeft); } } if (isComplete) { yield break; } Debug.Log(GameTimers.TIMER + id + " Completed!"); isComplete = true; GameTimers.RemoveTimer(id); OnComplete?.Invoke(this); }
IEnumerator GetGameData() { var request = UnityWebRequest.Get(targetUrl); request.SetRequestHeader("Accept", "application/json"); var reqOperation = request.SendWebRequest(); while (!reqOperation.isDone) { yield return(null); } if (request.isNetworkError || request.isHttpError) { print("Error > " + request.error); OnError?.Invoke(); } else { if (request.isDone) { var requestResult = request.downloadHandler.text; print("Load Complete > " + requestResult); root = JsonUtility.FromJson <RootGameData>(requestResult); OnComplete?.Invoke(root.gameData); } } }
public IEnumerator Execute() { var time = 0f; while (SliderFill.color != TakeDamageColor) { time += Time.deltaTime * 20; var color = Color.Lerp(DefaultColor, TakeDamageColor, time); SliderFill.color = color; yield return(null); } yield return(Wait); time = 0f; while (SliderFill.color != DefaultColor) { time += Time.deltaTime * 10; var color = Color.Lerp(TakeDamageColor, DefaultColor, time); SliderFill.color = color; yield return(null); } OnComplete?.Invoke(this); }
public virtual void Complete() { Debug.Log("QuestTask :: Complete -> " + gameObject.name); onComplete?.Invoke(); active = false; GameManager.instance.AddSubtitle(onCompleteSubtitleClip); }
private void pingCompleted(object sender, PingCompletedEventArgs e) { if (!Global.IPAddresses.isCompleted) { lock (_lockObject) { Global.IPAddresses.Increment(); Ping ping = (Ping)sender; ping.SendPingAsync(Global.IPAddresses.Current, Timeout); } } else { OnComplete?.Invoke(); (sender as Ping).Dispose(); } if (e.Reply.Status == IPStatus.Success) { Insert(e.Reply); lock (_lockObject) { Global.IPAddresses.RepliedCount++; } OnPingReply?.Invoke(e.Reply, Global.IPAddresses.RepliedCount); } OnProgress?.Invoke(Global.IPAddresses.Current, Global.IPAddresses.PingedCount); }
public void OnEat() { if (OnComplete != null) { OnComplete.Invoke(this); } }
private IEnumerator DoWork() { while (IsRunning) { if (IsPaused) { yield return(null); } else { if (coroutine.MoveNext()) { yield return(coroutine.Current); } else { if (null != childJobStack && childJobStack.Count > 0) { BehaviourJob childJob = childJobStack.Pop(); coroutine = childJob.coroutine; } else { isRunning = false; } } } } OnComplete?.Invoke(isJobKilled); yield return(null); }
//在当前文件中查找 private void SearchInFile(string filename) { string[] lines = GetLines(filename); var needles = _needles; var comparison = _comparison; for (int i = 0; i < needles.Length; i++) { var needle = needles[i]; for (int lineNumber = 0; lineNumber < lines.Length; lineNumber++) { var line = lines[lineNumber]; if (line.IndexOf(needle, comparison) >= 0) { // found OnFound?.Invoke(needle, filename, line, lineNumber); } } } //Report progress int searched = Interlocked.Increment(ref _searched); if (searched < _files.Count) { ReportProgress((double)searched / _files.Count); } //All files are searched, complete else { OnComplete?.Invoke(); } }
static void Main(string[] args) { int[] array = new int[] { 4, 7, 9, 7, 10 }; Thread process1 = new Thread( () => { Sort(array); OnComplete?.Invoke(); int[] sorted = Sort(array); PrintMass(sorted); } ); Thread process2 = new Thread( () => { Sort(array); OnComplete?.Invoke(); int[] sorted = Sort(array); PrintMass(sorted); } ); OnComplete += PrintStatus; process1.Start(); process2.Start(); Console.ReadKey(); }
/// <inheritdoc /> public async Task WriteToAsync(Stream responseStream, CancellationToken cancellationToken) { try { var bytes = SourceBytes; if (bytes != null) { await responseStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken).ConfigureAwait(false); } else { using (var src = SourceStream) { await src.CopyToAsync(responseStream, cancellationToken).ConfigureAwait(false); } } } catch { OnError?.Invoke(); throw; } finally { OnComplete?.Invoke(); } }
private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { Scrapper.Scrapper.Init(browser.DocumentText); this.IsBusy = false; OnBusyStatusChange?.Invoke(this.IsBusy, new EventArgs()); OnComplete?.Invoke(browser.DocumentText, new EventArgs()); }
public override void Tick() { if (!IsRun || !_isStart) { return; } if (_commandsBuffer.Count == 0 && _currentCommand.IsDone) { //all commands complete PauseSystem(); _currentCommand.Dispose(); _currentCommand = null; UpdateProgression(); OnComplete?.Invoke(); return; } if (_currentCommand == null) { //start first command _currentCommand = _commandsBuffer.Dequeue(); _currentCommand.Execute(); return; } if (!_currentCommand.IsDone) { //_currentCommand in progress UpdateProgression(); return; } //_currentCommand Complete _currentCommand.Dispose(); _currentCommand = _commandsBuffer.Dequeue(); _currentCommand.Execute(); }
public void Copy() { byte[] buffer = new byte[1024 * 1024]; // 1MB buffer bool cancel = false; using (FileStream oldFile = new FileStream(oldPath, FileMode.Open, FileAccess.Read)) { long fileLength = oldFile.Length; using (FileStream newFile = new FileStream(newPath, FileMode.CreateNew, FileAccess.Write)) { long totalBytes = 0; int currentBlockSize = 0; while ((currentBlockSize = oldFile.Read(buffer, 0, buffer.Length)) > 0) { totalBytes += currentBlockSize; double persentage = (double)totalBytes * 100.0 / fileLength; newFile.Write(buffer, 0, currentBlockSize); cancel = false; OnProgressChanged?.Invoke(persentage, ref cancel); if (cancel) { break; } } OnComplete?.Invoke(); } } }
public IEnumerator Execute() { var rotateTo = new Quaternion { eulerAngles = new Vector3(0, 0, MaxRotation) }; var currentRotation = RectTransform.rotation.z; var nextRotation = MaxRotation * -1f; var time = 0f; while (Mathf.Abs(nextRotation) > 0.15f) { time += Time.deltaTime * WiggleSpeed; var newRotation = Mathf.Lerp(currentRotation, nextRotation, time); rotateTo.eulerAngles = new Vector3(0, 0, newRotation); RectTransform.rotation = rotateTo; if (time >= 1) { currentRotation = nextRotation; nextRotation = (nextRotation * 0.9f) * -1; time = 0; } yield return(null); } rotateTo.eulerAngles = new Vector3(0, 0, 0); RectTransform.rotation = rotateTo; OnComplete?.Invoke(this); }
public override void iTweenPlay() { Hashtable ht = new Hashtable(); ht.Add("from", this.valueFrom); ht.Add("to", this.valueTo); ht.Add("time", this.tweenTime); ht.Add("delay", this.waitTime); ht.Add("looptype", this.loopType); ht.Add("easetype", this.easeType); ht.Add("onstart", (Action <object>)(newVal => { _onUpdate(this.valueFrom); if (onStart != null) { onStart.Invoke(); } })); ht.Add("onupdate", (Action <object>)(newVal => { _onUpdate((float)newVal); })); ht.Add("oncomplete", (Action <object>)(newVal => { if (onComplete != null) { onComplete.Invoke(); } })); ht.Add("ignoretimescale", ignoreTimescale); iTween.ValueTo(this.gameObject, ht); }
private void CopyCompleted() { if (--_copyInProgress == 0) { OnComplete?.Invoke(); } }
public void Init() { SerialiseParams(parameterItems.items); foreach (Parameter param in parameters) { SetParamDependencies(param); param.Init(GlobalFacade.MonoBehaviour); if (param.IsReady()) { CheckParamsReady(param); } else { param.onError += StopParametersChecking; param.onReady += CheckParamsReady; param.onUnReady += RemoveFromReadyParams; } } if (parameters.Count == 0) { OnComplete?.Invoke(); mediator.Notify(this, "OnParamsLoaded"); } }
public async Task CopyAsync() { const int bufferSize = 1024 * 1024; var buffer = new byte[bufferSize]; foreach (var fileInfo in _sourceFiles) { var sourceFilePath = fileInfo.FullName; var referenceSourcePath = sourceFilePath.Replace(_sourcePath, ""); var checkChars = new[] { @"\", "/" }; if (checkChars.Any(x => referenceSourcePath.StartsWith(x))) { referenceSourcePath = referenceSourcePath.Substring(1); } var targetFilePath = Path.Combine(_targetPath, referenceSourcePath); var prevCopiedSize = 0L; var fileCopy = new FileCopy(sourceFilePath, targetFilePath); fileCopy.OnProgressChanged += (copiedSize, totalSize, progress) => { Interlocked.Add(ref TotalCopiedSize, copiedSize - prevCopiedSize); OnProgressChanged?.Invoke(TotalCopiedSize, TotalSize, TotalProgress); prevCopiedSize = copiedSize; }; await fileCopy.CopyAsync(); } OnComplete?.Invoke(); }
public async Task WriteToAsync(IResponse response, CancellationToken cancellationToken) { try { // Headers only if (IsHeadRequest) { return; } var path = Path; var offset = RangeStart; var count = RangeLength; if (string.IsNullOrWhiteSpace(RangeHeader) || RangeStart <= 0 && RangeEnd >= TotalContentLength - 1) { var extension = System.IO.Path.GetExtension(path); if (extension == null || !SkipLogExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase)) { Logger.LogDebug("Transmit file {0}", path); } offset = 0; count = 0; } await response.TransmitFile(path, offset, count, FileShare, _fileSystem, _streamHelper, cancellationToken).ConfigureAwait(false); } finally { OnComplete?.Invoke(); } }
private void Process() { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var localVersion = Directory.GetDirectories(dir) .Select(x => { long datetime; string name = Path.GetFileName(x); string time = name.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries)[0]; bool success = long.TryParse(time, out datetime); return(new { success, dir = x, datetime }); }) .Where(x => x.success) .Prepend(new { success = false, dir = "", datetime = 0L }) .OrderBy(x => x.datetime) .Last(); // リポジトリ上の最新版を調べる前に、ローカルのバージョンを通知 if (localVersion.success) { OnComplete?.Invoke(false, localVersion.dir); } Task.Run(() => { var req = (HttpWebRequest)HttpWebRequest.Create(latestReleaseURL); req.ContentType = "application/json;charset=UTF-8"; req.UserAgent = "Mozilla/5.0"; WebResponse res; try { res = req.GetResponse(); } catch (Exception e) { OnFailed?.Invoke(e.Message); return; } var serializer = new DataContractJsonSerializer(typeof(GithubRelease)); // releases/latest に変える GithubRelease release = (GithubRelease)serializer.ReadObject(res.GetResponseStream()); long latestTicks = release.PublishedAt.Ticks; if (localVersion.datetime < latestTicks) { var dst = dir + "\\" + latestTicks + "_" + release.TagName; var cli = new WebClient(); var tempFile = Path.GetTempFileName(); cli.DownloadFile(release.Assets[0].DownloadUrl, tempFile); ZipFile.ExtractToDirectory(tempFile, dst); new DirectoryInfo(dst).CreationTime = release.PublishedAt; OnComplete?.Invoke(true, dst); } }); }