Esempio n. 1
0
        private void LateUpdate()
        {
            if (!clickVisualFeedTarget || (!_targetDirty && !_mouseDown))
            {
                return;
            }

            if ((Time.time - _mouseDownTime) > maxHoldForClick || ((Input.mousePosition.ToVector2() - _mouseDownPosition).magnitude > maxMousePositionPixOffsetForClick))
            {
                _mouseDown = false;
            }

            if (transition == ClickableElementTransition.Fade)
            {
                var a = clickVisualFeedTarget.color.a;

                var target = _mouseDown ? 0.75f : 1;

                a = LerpUtils.LerpBySpeed(a, target, 5);

                clickVisualFeedTarget.TrySetAlpha(a);

                _targetDirty = (Math.Abs(a - 1) > float.Epsilon);
            }
        }
Esempio n. 2
0
        public void Update()
        {
            if (isFadingAway && pTextMeshPro.enabled)
            {
                float tfd = textFade.CurrentValue;

                tfd = LerpUtils.LerpBySpeed(tfd, tfd > 0.5f ? 1f : 0f, 2f);

                needUpdate = true;

                if (tfd == 0 || tfd == 1)
                {
                    pTextMeshPro.text    = "";
                    pTextMeshPro.enabled = false;
                }

                textFade.CurrentValue = tfd;
            }

            if (needUpdate)
            {
                pTextMeshPro.color = textColor.CurrentValue.Alpha(textFade.CurrentValue);
                needUpdate         = false;
            }
        }
Esempio n. 3
0
        public override void Lerp(LerpData ld, bool canSkipLerp)
        {
            if (!isFadingAway)
            {
                if (gotAnotherText || dirty)
                {
                    textColor.Lerp(ld);
                    textFade.Lerp(ld);

                    dirty = ld.Portion() < 1;

                    if (gotAnotherText && textFade.CurrentValue == 1)
                    {
                        pTextMeshPro.text     = targetText;
                        targetText            = null;
                        textFade.CurrentValue = 0;
                    }
                }
                else if (textFade.CurrentValue < 0.5f)
                {
                    textFade.CurrentValue = LerpUtils.LerpBySpeed(textFade.CurrentValue, 0.5f, 1f);
                }

                needUpdate = true;
            }
        }
Esempio n. 4
0
        // Update is called once per frame
        void Update()
        {
            if (Application.isPlaying)
            {
                bool above = Above;

                _staminaLine = Mathf.Clamp01(_staminaLine + Time.deltaTime * 0.005f);

                if (Above && !above)
                {
                    audioSource.PlayOneShot(onFillCrossTheCenter);
                }

                if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    Use(1);
                }
                if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    Use(2);
                }
                if (Input.GetKeyDown(KeyCode.Alpha3))
                {
                    Use(4);
                }
            }

            //StaminaCurve = 1 + Mathf.Pow(Mathf.Clamp01(_staminaLine * 2),2) * 5;

            _staminaLineInShader.GlobalValue = _staminaLine;

            if (showPreviousTimer > 0)
            {
                if (_staminaLine >= _previousStaminaLine)
                {
                    showPreviousTimer = 0;
                }

                showPreviousTimer -= Time.deltaTime;
            }
            else
            {
                LerpUtils.IsLerpingBySpeed(ref _previousStaminaLine, _staminaLine, 0.1f);
            }

            _previousStaminaLineInShader.GlobalValue = _previousStaminaLine;

            if (_staminaCount)
            {
                _staminaCount.text = ((int)StaminaPoints).ToString();
            }

            _staminaCount.color = Above ? Color.LerpUnclamped(Color.yellow, Color.green, (_staminaLine - 0.5f) * 2) : Color.LerpUnclamped(Color.magenta, Color.blue, _staminaLine * 2);

            centralLine.TrySetAlpha(Above ? 1 : 0);
        }
Esempio n. 5
0
    void Update()
    {
        if (currentScore != targetScore)
        {
            LerpUtils.IsLerpingBySpeed(ref currentScore, targetScore, 75);

            float diff = Mathf.Max(0, targetScore - currentScore);

            faceDialate.SetOn(text.fontSharedMaterial, Mathf.Clamp01(Random.Range(diff * 0.5f, diff) * 0.01f) * 0.6f);
            text.text = ((int)currentScore).ToString();
        }
    }
        public void Update()
        {
            if (highlight)
            {
                float a = highlight.color.a;

                if (LerpUtils.IsLerpingBySpeed(ref a, graphic.ClickPossible ? 1 : 0, 8))
                {
                    highlight.TrySetAlpha_DisableGameObjectIfZero(a);
                }
            }
        }
Esempio n. 7
0
        public static void SHADER_POSITION_AND_PREVIEW_UPDATE(StrokeVector st, bool hidePreview, float size)
        {
            PainterDataAndConfig.BRUSH_POINTED_UV.GlobalValue = st.uvTo.ToVector4(0, _previewAlpha);

            if (hidePreview && Math.Abs(_previewAlpha) < float.Epsilon)
            {
                return;
            }

            LerpUtils.IsLerpingBySpeed(ref _previewAlpha, hidePreview ? 0 : 1, 4f);

            PainterDataAndConfig.BRUSH_WORLD_POS_FROM.GlobalValue = _prevPosPreview.ToVector4(size);
            PainterDataAndConfig.BRUSH_WORLD_POS_TO.GlobalValue   = st.posTo.ToVector4((st.posTo - _prevPosPreview).magnitude); //new Vector4(st.posTo.x, st.posTo.y, st.posTo.z, (st.posTo - prevPosPreview).magnitude));
            _prevPosPreview = st.posTo;
        }
Esempio n. 8
0
    void Update()
    {
        _taravanaTime += Time.deltaTime * 0.1f;

        if (_taravanaTime > resetTimer * 3)
        {
            _taravanaTime = 0;
        }

        _shaderTime.SetGlobal((float)_taravanaTime);

        bool down = Input.GetMouseButton(0);

        if (down || _mouseDownStrength > 0)
        {
            bool downThisFrame = Input.GetMouseButtonDown(0);

            if (downThisFrame)
            {
                _mouseDownStrength = 0;
                _mouseDownStrengthOneDirectional = 0;
                downClickFullyShown = false;
            }

            _mouseDownStrengthOneDirectional = LerpUtils.LerpBySpeed(_mouseDownStrengthOneDirectional,
                                                                     down ? 0 : 1
                                                                     , down ? 4f : (3f - _mouseDownStrengthOneDirectional * 3f));

            _mouseDownStrength = LerpUtils.LerpBySpeed(_mouseDownStrength, downClickFullyShown ?
                                                       0 : (down ? 0.9f : 1f)
                                                       , (down) ? 5 : (downClickFullyShown ? 0.75f : 2.5f));

            if (_mouseDownStrength > 0.99f)
            {
                downClickFullyShown = true;
            }

            if (down)
            {
                var newPosition = Input.mousePosition.XY() / new Vector2(Screen.width, Screen.height);
                _mouseDownPosition = newPosition;//LerpUtils.LerpBySpeed(_mouseDownPosition, newPosition, 4) ;
            }

            UpdatemousePosition();
        }
    }
Esempio n. 9
0
        public static void SHADER_POSITION_AND_PREVIEW_UPDATE(Stroke st, bool hidePreview, float size)
        {
            PainterShaderVariables.BRUSH_UV_POS_FROM.GlobalValue = st.uvFrom.ToVector4(0, _previewAlpha);
            PainterShaderVariables.BRUSH_UV_POS_TO.GlobalValue   = st.uvTo.ToVector4(0, _previewAlpha);

            if (hidePreview && Math.Abs(_previewAlpha) < float.Epsilon)
            {
                return;
            }

            LerpUtils.IsLerpingBySpeed(ref _previewAlpha, hidePreview ? 0 : 1, 4f);

            PainterShaderVariables.BRUSH_WORLD_POS_FROM.GlobalValue = _prevPosPreview.ToVector4(size);
            PainterShaderVariables.BRUSH_WORLD_POS_TO.GlobalValue   = st.posTo.ToVector4((st.posTo - _prevPosPreview).magnitude);

            _prevPosPreview = st.posTo;
        }
Esempio n. 10
0
 public bool LerpBySpeed(float targetValue, float speed) => LerpUtils.IsLerpingBySpeed(ref colorAlpha, targetValue, speed);
        public void Lerp(LerpData ld, bool canSkipLerp = false)
        {
            #region Drag

            UpdateCoverImage();

            if (this == _dragging)
            {
                if (isFading || !Shortcuts.editingNodes || !Input.GetMouseButton(0))
                {
                    _dragging = null;
                }
                else
                {
                    Vector3 pos;
                    if (UpPlane.MouseToPlane(out pos, MainCamera))
                    {
                        transform.localPosition          = pos + _dragOffset;
                        ActiveConfig.targetLocalPosition = transform.localPosition;
                    }
                }

                SetDirty();
            }


            #endregion

            #region Lerp Visual
            if (includedInLerp)
            {
                var ac = ActiveConfig;

                var needShaderUpdate = false;

                if (!lerpsFinished && (this != _dragging))
                {
                    needShaderUpdate = true;

                    _shBlur = Mathf.Lerp(_shBlur,
                                         Mathf.Clamp01((transform.localPosition - _localPos.targetValue).magnitude * 5),
                                         Time.deltaTime * 10);

                    fadePortion = Mathf.Lerp(fadePortion, isFading ? 0 : 1, ld.MinPortion);

                    var scale = _localScale.CurrentValue;

                    if (scale.x > 0)
                    {
                        _shSquare.x = scale.x > scale.y ? ((scale.x - scale.y) / scale.x) : 0;
                    }
                    else
                    {
                        _shSquare.x = 0;
                    }
                    if (scale.y > 0)
                    {
                        _shSquare.y = scale.y > scale.x ? ((scale.y - scale.x) / scale.y) : 0;
                    }
                    else
                    {
                        _shSquare.y = 0;
                    }

                    var textSize = new Vector2(17 + scale.x * 3, 5f + Mathf.Max(0, (scale.y - 1f) * 3f));

                    textA.rectTransform.sizeDelta = textSize;
                    textB.rectTransform.sizeDelta = textSize;
                }

                if (!lerpsFinished && (this != _dragging) && ld.MinPortion == 1 && LerpPosition)
                {
                    lerpsFinished = true;
                }

                if (newText != null || _activeTextAlpha < 1)
                {
                    lerpsFinished = false;

                    _activeTextAlpha = newText == null
                        ? Mathf.Lerp(_activeTextAlpha, 1, ld.Portion())
                        : LerpUtils.LerpBySpeed(_activeTextAlpha, 1, 4);

                    if (_activeTextAlpha == 1 && newText != null)
                    {
                        _activeTextIsA   = !_activeTextIsA;
                        ActiveText.text  = newText;
                        gameObject.name  = newText;
                        _activeTextAlpha = 0;
                        newText          = null;
                    }

                    needShaderUpdate = true;
                }

                bool skipLerpPossible = (_canJumpToPosition && fadePortion < 0.1f && !isFading);

                bgColor = Color.Lerp(bgColor, ac.targetColor, ld.Portion(skipLerpPossible));
                _textColor.Lerp(ld, skipLerpPossible);

                if (LerpPosition)
                {
                    _localPos.Lerp(ld);
                }

                _localScale.Lerp(ld, skipLerpPossible);
                _shadeCorners.Lerp(ld, skipLerpPossible);
                _shadeSelected.Lerp(ld, skipLerpPossible);
                _textureFadeIn.Lerp(ld, skipLerpPossible);
                _texTransition.Lerp(ld, skipLerpPossible);

                if (needShaderUpdate)
                {
                    OnShaderParametersChanged();
                }


                if (fadePortion == 0 && isFading && Application.isPlaying)
                {
                    BoxButtons.inst.Deactivate(this);
                }
            }
            #endregion

            #region Link

            bool gotLinkTarget = false;

            if (!_latestParent)
            {
                if (source != null && source.parentNode != null && source.parentNode == CurrentNode)
                {
                    _latestParent = source.parentNode.visualRepresentation as NodeCircleController;
                }
            }

            if (_latestParent)
            {
                if (_latestParent.gameObject.activeSelf)
                {
                    if (!_latestParent.isFading && (_latestParent.source != null) &&
                        (source != null) && (_latestParent.source == source.parentNode))
                    {
                        linkRenderer.startColor = linkRenderer.startColor.LerpBySpeed(bgColor, 5);
                        linkRenderer.endColor   = linkRenderer.endColor.LerpBySpeed(_latestParent.bgColor, 5);

                        if (!linkRenderer.gameObject.activeSelf)
                        {
                            linkRenderer.gameObject.SetActive(true);
                        }

                        gotLinkTarget = true;
                    }

                    linkRenderer.SetPosition(0, transform.position + Vector3.down * 0.1f);
                    linkRenderer.SetPosition(1, _latestParent.transform.position + Vector3.down * 0.1f);
                }
            }

            if (!gotLinkTarget)
            {
                linkRenderer.LerpAlpha_DisableIfZero(0, 1);
            }

            #endregion

            if (LevelArea)
            {
                LevelArea.Lerp(ld, false);
            }

            if (_mouseDown && ((Time.time - _overDownTime) > 0.2f))
            {
                _mouseDown    = false;
                lerpsFinished = false;
                audioSource.Stop();
                Debug.Log("Stopping on leave");
                audioSource.PlayOneShot(Shortcuts.Assets.onMouseLeaveSound);
            }
        }
Esempio n. 12
0
        public void Update()
        {
            switch (step)
            {
            case BlurStep.Requested:

                if (allowScreenGrabToRt)
                {
                    step = BlurStep.ReturnedFromCamera;

                    MyCamera.enabled       = false;
                    MyCamera.targetTexture = ScreenReadRenderTexture;

                    MyCamera.Render();
                    MyCamera.targetTexture = null;
                    MyCamera.enabled       = true;

                    if (useSecondBufferForRenderTextureScreenGrab)
                    {
                        Blit(ScreenReadRenderTexture, ScreenReadSecondBufferRt, copyShader);
                    }

                    goto case BlurStep.ReturnedFromCamera;
                }
                break;

            case BlurStep.ReturnedFromCamera:

                BlitToEffectBuffer(CurrentScreenReadTexture, copyShader);

                screenGradTexture.GlobalValue      = CurrentScreenReadTexture;
                processedScreenTexture.GlobalValue = CurrentScreenReadTexture;

                step          = BlurStep.Blurring;
                blurIteration = 0;

                InvokeOnCaptured();

                if (command == ProcessCommand.Nothing)
                {
                    step = BlurStep.Off;
                }

                break;

            case BlurStep.Blurring:

                blurIteration++;

                BlitBetweenEffectBuffers(postProcessShader);

                if (blurIteration > postProcessIteration)
                {
                    step = BlurStep.Off;
                }

                if (blurIteration == 1)
                {
                    InvokeOnCaptured();
                }

                break;
            }

            #region Press Position

            if (mousePositionToShader)
            {
                bool down = Input.GetMouseButton(0);

                if (down || mouseDownStrength > 0)
                {
                    bool downThisFrame = Input.GetMouseButtonDown(0);

                    if (downThisFrame)
                    {
                        mouseDownStrength = 0;
                        mouseDownStrengthOneDirectional = 0;
                        downClickFullyShown             = false;
                    }

                    mouseDownStrengthOneDirectional = LerpUtils.LerpBySpeed(mouseDownStrengthOneDirectional,
                                                                            down ? 0 : 1,
                                                                            down ? 4f : (3f - mouseDownStrengthOneDirectional * 3f));

                    mouseDownStrength = LerpUtils.LerpBySpeed(mouseDownStrength,
                                                              downClickFullyShown ? 0 :
                                                              (down ? 0.9f : 1f),
                                                              (down) ? 5 : (downClickFullyShown ? 0.75f : 2.5f));

                    if (mouseDownStrength > 0.99f)
                    {
                        downClickFullyShown = true;
                    }

                    if (down)
                    {
                        mouseDownPosition = Input.mousePosition.XY() / new Vector2(Screen.width, Screen.height);
                    }

                    mousePosition.GlobalValue = mouseDownPosition.ToVector4(mouseDownStrength, ((float)Screen.width) / Screen.height);
                }
            }
            #endregion
        }
Esempio n. 13
0
    public void Update()
    {
        ld.Reset();

        int activeCount = 0;

        foreach (var op in optionsPool)
        {
            activeCount += op.isFadingOut ? 0 : 1;
        }

        singlePhraseBoxHeight.Portion(ld, activeCount > 0 ? 0 : 1);
        historyPool.active.Portion(ld);
        optionsPool.active.Portion(ld);

        bool lerpSeparator = false;

        if (Math.Abs(separatorPosition.TargetValue - separatorPosition.CurrentValue) > 0.00001f || poolsDirty)
        {
            lerpSeparator = true;
            poolsDirty    = false;
            separatorPosition.Portion(ld, Mathf.Min(0.6f, 0.3f + activeCount * 0.2f));
        }

        // LERP:

        singlePhraseBoxHeight.Lerp(ld);
        historyPool.active.Lerp(ld);
        optionsPool.active.Lerp(ld);

        if (lerpSeparator)
        {
            separatorPosition.Lerp(ld);
        }

        //ld.LerpAndReset();

        var   tf           = singlePhraseBg.rectTransform;
        var   size         = tf.sizeDelta;
        float curBoxFadeIn = singlePhraseBoxHeight.CurrentValue;

        size.y = curBoxFadeIn * 400;
        singlePhraseBg.TrySetAlpha_DisableGameObjectIfZero(curBoxFadeIn * 20);
        singlePhraseText.TrySetAlpha_DisableGameObjectIfZero((curBoxFadeIn - 0.9f) * 10);
        tf.sizeDelta = size;

        if (lerpSeparator)
        {
            UpdateCourners();
        }

        const float scrollbackSpeed = 1000;

        if (state == ScrollingState.None)
        {
            if (Input.GetMouseButton(0))
            {
                state = (Input.mousePosition.y / Screen.height) > separatorPosition.CurrentValue
                    ? ScrollingState.ScrollingHistory
                    : ScrollingState.ScrollingOptions;

                prevousMousePos = Input.mousePosition;

                scrollSoundPlayed = false;
            }
        }
        else
        {
            if (!Input.GetMouseButton(0))
            {
                state = ScrollingState.None;
            }
            else
            {
                float diff = Input.mousePosition.y - prevousMousePos.y;

                bool up = diff > 0;

                if ((!scrollSoundPlayed || (up != scrollSoundPlayedUp)) && Mathf.Abs(diff) > 10)
                {
                    scrollSoundPlayedUp = up;
                    scrollSoundPlayed   = true;
                }

                (state == ScrollingState.ScrollingHistory ? historyScroll : optionsScroll).AddOffset(diff);

                prevousMousePos = Input.mousePosition;
            }
        }

        if (scrollHistoryUpRequested && state != ScrollingState.None)
        {
            scrollHistoryUpRequested = false;
        }

        float pos = historyScroll.offset;

        foreach (var h in historyPool.active)
        {
            var rt   = h.rectTransform;
            var anch = rt.anchoredPosition;
            anch.y = pos;
            rt.anchoredPosition = anch;
            pos += historyScroll.gap;
        }

        if (state != ScrollingState.ScrollingHistory)
        {
            historyScroll.ApplyInnertia();

            bool outOfList = true;

            if (historyScroll.offset > 0 || scrollHistoryUpRequested)
            {
                LerpUtils.IsLerpingBySpeed(ref historyScroll.offset, 0, scrollbackSpeed);
            }
            else if (pos < historyScroll.gap)
            {
                LerpUtils.IsLerpingBySpeed(ref historyScroll.offset, historyScroll.offset + historyScroll.gap - pos, scrollbackSpeed);
            }
            else
            {
                outOfList = false;
            }

            if (outOfList)
            {
                historyScroll.FadeInnertia();
            }
        }

        pos = optionsScroll.offset;

        foreach (var h in optionsPool.active)
        {
            if (!h.isFadingOut)
            {
                var rt   = h.rectTransform;
                var anch = rt.anchoredPosition;
                anch.y = pos;
                rt.anchoredPosition = anch;
                pos -= optionsScroll.gap;
            }
        }

        if (state != ScrollingState.ScrollingOptions)
        {
            optionsScroll.ApplyInnertia();

            bool outOfTheList = true;

            if (optionsScroll.offset < 0)
            {
                LerpUtils.IsLerpingBySpeed(ref optionsScroll.offset, 0, scrollbackSpeed);
            }
            else if (pos > -optionsScroll.gap)
            {
                LerpUtils.IsLerpingBySpeed(ref optionsScroll.offset, optionsScroll.offset - optionsScroll.gap - pos, scrollbackSpeed);
            }
            else
            {
                outOfTheList = false;
            }

            if (outOfTheList)
            {
                optionsScroll.FadeInnertia();
            }
        }
    }
Esempio n. 14
0
        public void ApplyInnertia()
        {
            offset += innertia * Time.deltaTime;

            LerpUtils.IsLerpingBySpeed(ref innertia, 0, 5000);
        }