Exemplo n.º 1
0
    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;
            }
        }
    }
Exemplo n.º 2
0
    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();
        }
Exemplo n.º 4
0
        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;
                }
            }
        }
Exemplo n.º 5
0
        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();
                    }
                }
            }
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
 private void invokeFinished(int id, string text)
 {
     if (OnFinished != null)
     {
         OnFinished.Invoke(id, text);
     }
 }
Exemplo n.º 9
0
        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;
            }
        }
Exemplo n.º 10
0
        /// <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);
                }
            }
        }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 15
0
 /// <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();
         }
     });
 }
Exemplo n.º 16
0
        /// <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();
                }
            }
        }
Exemplo n.º 17
0
    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;
    }
Exemplo n.º 18
0
        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++;
                }
            }
        }
Exemplo n.º 19
0
        public void SetFinished()
        {
            Finished = true;
            Progress = 1.0f;

            OnFinished?.Invoke();
        }
Exemplo n.º 20
0
        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;
        }
Exemplo n.º 21
0
 /// ------------------------------------------------------------------------------------
 void HandleWorkerFinished(object sender, RunWorkerCompletedEventArgs e)
 {
     if (OnFinished != null)
     {
         OnFinished.Invoke(this, new ProgressFinishedArgs(false, _encounteredError));
     }
 }
Exemplo n.º 22
0
        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);
            }
        }
Exemplo n.º 23
0
 private void button1_Click_1(object sender, EventArgs e)
 {
     if (OnFinished != null)
     {
         OnFinished.Invoke(this, textBox1.Text);
     }
     this.Close();
 }
Exemplo n.º 24
0
 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);
 }
Exemplo n.º 27
0
 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);
        }
Exemplo n.º 29
0
 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());
 }
Exemplo n.º 30
0
 public override void IntentFinished()
 {
     if (player.Position == positionToTeleport)
     {
         Finished = true;
         OnFinished?.Invoke(this, new EventArgs());
     }
 }