Coserp() 공개 정적인 메소드

public static Coserp ( float start, float end, float value ) : float
start float
end float
value float
리턴 float
예제 #1
0
    public override void ApiUpdate()
    {
        base.ApiUpdate();

        if (GetState() == STATE_SPAWN)
        {
            float delta = GetStateTime() / 1f;
            if (delta >= 1)
            {
                _spriteRenderer.color = Color.white;
                SetState(STATE_IDLE);
                return;
            }
            float value = Mathfx.Coserp(0, 1, delta);
            _spriteRenderer.color = new Color(value, value, value, value);
        }
        else if (GetState() == STATE_ATTACK)
        {
            if (_attackAnim.IsFinished())
            {
                SetLocalPos(_attackAnim._initialPos);
                SetState(STATE_DEATH);
            }
        }
        else if (GetState() == STATE_DEATH)
        {
            if (GetStateTime() >= .5f)
            {
                Destroy(gameObject);
            }
        }
    }
    public override void ApiUpdate()
    {
        base.ApiUpdate();

        if (GetState() == STATE_SPAWN)
        {
            float delta = GetStateTime() / 1f;
            if (delta >= 1)
            {
                _spriteRenderer.color = Color.white;
                SetState(STATE_IDLE);
                return;
            }
            float value = Mathfx.Coserp(0, 1, delta);
            _spriteRenderer.color = new Color(value, value, value, value);
        }
        else if (GetState() == STATE_PICKED_UP)
        {
            if (GetStateTime() >= 1f)
            {
                Destroy(gameObject);
            }
        }
        else if (GetState() == STATE_DEATH)
        {
            float delta = GetStateTime() / 1f;
            if (delta >= 1)
            {
                Destroy(gameObject);
                return;
            }
            float value = Mathfx.Coserp(1, 0, delta);
            _spriteRenderer.color = new Color(value, value, value, value);
        }
    }
예제 #3
0
    private IEnumerator OpenOrCloseTerminal(bool isViewing)
    {
        if (isViewing)
        {
            DoBeforeOpenTerminal();
            yield return(new WaitForSeconds(.5f));

            canvas.enabled = true;
        }

        float startHeight  = canvasParentRect.localScale.y;
        float targetHeight = isViewing ? openCanvasHeight : 0f;
        float time         = 0f;
        float duration     = .40f;

        while (canvasParentRect.localScale.y != targetHeight)
        {
            canvasParentRect.localScale = new Vector3(1f, Mathfx.Coserp(startHeight, targetHeight, time / duration), 1f);
            time += Time.deltaTime;
            yield return(null);
        }

        if (!isViewing)
        {
            canvas.enabled = false;
        }
    }
    private IEnumerator FadeAudio(FadeDirection direction, System.Action onComplete)
    {
        const int numFadeSteps = 100;
        float     stepAmount   = 1f / numFadeSteps;

        float easeSpeed = audioFadeDuration / numFadeSteps;
        float easeStart = minVolume;
        float easeGoal  = maxVolume;

        if (direction == FadeDirection.Down)
        {
            easeStart = maxVolume;
            easeGoal  = minVolume;
        }

        for (float pct = 0; pct <= 1f; pct += stepAmount)
        {
            float volumeLevel;
            if (direction == FadeDirection.Down)
            {
                volumeLevel = Mathfx.Sinerp(easeStart, easeGoal, pct);
            }
            else
            {
                volumeLevel = Mathfx.Coserp(easeStart, easeGoal, pct);
            }
            source.volume = volumeLevel;

            yield return(new WaitForSeconds(easeSpeed));
        }
        onComplete();
    }
예제 #5
0
    /// <summary>
    /// Return value based on curve from Mathfx class.
    /// </summary>
    /// <returns>The value.</returns>
    /// <param name="animationCurve">Animation curve.</param>
    /// <param name="start">Start.</param>
    /// <param name="end">End.</param>
    /// <param name="t">T.</param>
    public static float CurvedValue(AnimationCurveEnum animationCurve, float start, float end, float t)
    {
        switch (animationCurve)
        {
        case AnimationCurveEnum.Hermite:
            return(Mathfx.Hermite(start, end, t));

        case AnimationCurveEnum.Sinerp:
            return(Mathfx.Sinerp(start, end, t));

        case AnimationCurveEnum.Coserp:
            return(Mathfx.Coserp(start, end, t));

        case AnimationCurveEnum.Berp:
            return(Mathfx.Berp(start, end, t));

        case AnimationCurveEnum.Bounce:
            return(start + ((end - start) * Mathfx.Bounce(t)));

        case AnimationCurveEnum.Lerp:
            return(Mathfx.Lerp(start, end, t));

        case AnimationCurveEnum.Clerp:
            return(Mathfx.Clerp(start, end, t));

        default:
            return(0);
        }
    }
예제 #6
0
 public static Vector3 Coserp(Vector3 start, Vector3 end, float value)
 {
     return(new Vector3(
                Mathfx.Coserp(start.x, end.x, value),
                Mathfx.Coserp(start.y, end.y, value),
                Mathfx.Coserp(start.z, end.z, value)
                ));
 }
예제 #7
0
 void Contract()
 {
     contractionTimeRemaining -= Time.deltaTime;
     transform.localScale      = Mathfx.Coserp(expandedUpTo * Vector3.one, Vector3.one,
                                               1 - contractionTimeRemaining / (expansionTimeElapsed * contractionTimeFactor));
     MoveToEdge();
     if (contractionTimeRemaining <= 0)
     {
         ResetToNeutral();
     }
 }
        private float Evaluate(float timer, MoveType type, bool moveIn)
        {
            switch (type)
            {
            default: return(timer);

            case MoveType.Lerp: return(timer);

            case MoveType.Boing: return(Mathfx.Berp(0f, 1f, timer));

            case MoveType.Ease: return(moveIn ? Mathfx.Sinerp(0f, 1f, timer) : Mathfx.Coserp(0f, 1f, timer));
            }
        }
예제 #9
0
    public IEnumerator Hide()
    {
        float s = 1;

        while (s > 0)
        {
            s -= Time.deltaTime / scaleTime;
            transform.localScale = Mathfx.Coserp(Vector3.zero, originalScale, s);

            yield return(0);
        }
        gameObject.SetActive(false);
    }
예제 #10
0
 /// <summary>
 /// Zwraca obecną wysokość, na jakiej znajduje się kostka
 /// </summary>
 /// <param name="progress">Postęp animacji kostki</param>
 /// <param name="height">Maksymalna wysokość, na jaką może unieść się kostka</param>
 /// <returns></returns>
 private float GetCurrentHeight(float progress, float height)
 {
     //Połowę animcji lecimy w górę, a połowę w dół
     if (progress <= 0.5f)
     {
         float currentProgress = MathExtension.Map(0f, 0.5f, 0f, 1f, progress);
         return(Mathfx.Sinerp(0f, height, currentProgress));
     }
     else
     {
         float currentProgress = MathExtension.Map(0f, 0.5f, 0f, 1f, progress - 0.5f);
         return(Mathfx.Coserp(height, 0f, currentProgress));
     }
 }
예제 #11
0
    /// <summary>
    /// fires rockets while rotating from startHinge to endHinge
    /// </summary>
    /// <param name="startHinge"></param>
    /// <param name="endHinge"></param>
    /// <param name="easeOut"></param>
    /// <returns></returns>
    private IEnumerator DoFireRockets(Vector3 startHinge, Vector3 endHinge, bool easeOut = true)
    {
        float time = 0f;

        RocketFire.Play();
        RocketSmoke.Play();
        rocketSource.Play();

        if (easeOut)
        {
            //ease-out
            //landing
            //copied and pasted by below
            while (time < LandingStageTimeSeconds)
            {
                rocketSource.volume = Mathf.Min(1f, LandingStageTimeSeconds - time);

                LanderHinge.localRotation = Quaternion.Euler(
                    Mathfx.Sinerp(startHinge, endHinge, time / LandingStageTimeSeconds)
                    );
                yield return(null);

                time += Time.deltaTime;
            }
        }
        else
        {
            //ease-in
            //take-off
            //copied and pasted from above, just using coserp
            while (time < LandingStageTimeSeconds)
            {
                rocketSource.volume = Mathf.Max(0f, time);

                LanderHinge.localRotation = Quaternion.Euler(
                    Mathfx.Coserp(startHinge, endHinge, time / LandingStageTimeSeconds)
                    );
                yield return(null);

                time += Time.deltaTime;
            }
        }
        RocketFire.Stop();
        RocketSmoke.Stop();
        rocketSource.Stop();
    }
    private void Update()
    {
        Vector3 endDir = endPoint - transform.position;

        endDir.Normalize();
        lerpVal             = Mathf.Clamp01(lerpVal + (lerpDelta * Time.deltaTime));
        velocity            = Mathfx.Coserp(velocity, endDir, lerpVal);
        transform.position += velocity * speed * Time.deltaTime;
        if (Vector3.Distance(endPoint, transform.position) < 1f)
        {
            if (OnFinishLerpEvent != null)
            {
                OnFinishLerpEvent();
                Destroy(gameObject);
            }
        }
    }
예제 #13
0
    public IEnumerator LerpRotation(Vector3 end, float time, Action whenDone = null)
    {
        float   i     = 0f;
        Vector3 start = transform.localRotation.eulerAngles;

        isLerping = true;
        while (i < time)
        {
            transform.localRotation = Quaternion.Euler(Mathfx.Coserp(start, end, i / time));
            i += Time.deltaTime;
            yield return(null);
        }
        isLerping = false;
        if (whenDone != null)
        {
            whenDone();
        }
    }
예제 #14
0
    public IEnumerator LerpScale(Vector3 end, float time, Action whenDone = null)
    {
        float   i     = 0f;
        Vector3 start = transform.localScale;

        isLerping = true;
        while (i < time)
        {
            transform.localScale = Mathfx.Coserp(start, end, i / time);
            i += Time.deltaTime;
            yield return(null);
        }
        isLerping = false;
        if (whenDone != null)
        {
            whenDone();
        }
    }
    public virtual void RecTransformUpdate()
    {
        if (_rectTf == null)
        {
            return;
        }
        if (_animate)
        {
            _elapsedAnimTime += Time.deltaTime;
            if (!_finishedDelay && _elapsedAnimTime > _delayTime)
            {
                _elapsedAnimTime = 0;
                _finishedDelay   = true;
            }
            if (_elapsedAnimTime >= _animationTime)
            {
                _rectTf.anchoredPosition3D = _endPos;
                _animate = false;
                return;
            }

            float time = _elapsedAnimTime / _animationTime;
            if (_evaluationType == AnimationFunction.EASE_IN)
            {
                _rectTf.anchoredPosition3D = Mathfx.Coserp(_initialPos, _endPos, time);
            }
            else if (_evaluationType == AnimationFunction.EASE_OUT)
            {
                _rectTf.anchoredPosition3D = Mathfx.Sinerp(_initialPos, _endPos, time);
            }
            else if (_evaluationType == AnimationFunction.EASE_IN_OUT)
            {
                _rectTf.anchoredPosition3D = Mathfx.Hermite(_initialPos, _endPos, time);
            }
            else if (_evaluationType == AnimationFunction.BOING)
            {
                _rectTf.anchoredPosition3D = Mathfx.Berp(_initialPos, _endPos, time);
            }
            else if (_evaluationType == AnimationFunction.CUSTOM_CURVE)
            {
                _rectTf.anchoredPosition3D = Vector3.Lerp(_initialPos, _endPos, _customCurve.Evaluate(time));
            }
        }
    }
예제 #16
0
    void Update()
    {
        if (doorCloseTimer < 1.0f)
        {
            doorCloseTimer += Time.deltaTime * 3f;
            if (doorCloseTimer > 1.0f)
            {
                doorCloseTimer = 1.0f;
            }

            float y = Mathfx.Coserp(beginScale, targetScale, doorCloseTimer);
            doorCollider.transform.localScale = new Vector3(1f, y, 1f);

            if (transform.rotation.eulerAngles.z == 0f && !particleEffectPlayed && doorCollider.transform.localScale.y >= 0.9f)
            {
                Instantiate(Resources.Load("FloorHit") as GameObject, transform.position + new Vector3(0f, -collider.bounds.extents.y - 0.5f, -1f), Quaternion.identity);
                particleEffectPlayed = true;
            }
        }

        if (open && !isPossessed())
        {
            closeTimer -= Time.deltaTime;
            if (closeTimer <= 0f)
            {
                if (Vector3.Distance(transform.position, GameManager.gameManager.Robot.gameObject.transform.position) > 5.2f)
                {
                    closeTimer          = closeTime;
                    open                = false;
                    targetScale         = 1f;
                    beginScale          = doorCollider.transform.localScale.y;
                    doorCloseTimer      = 0f;
                    boxCollider.enabled = true;
                    if (closeSound != null)
                    {
                        AudioSource.PlayClipAtPoint(closeSound, transform.position);
                    }
                    particleEffectPlayed = false;
                }
            }
        }
    }
    private float DoLerp()
    {
        switch (this._currentLerpType)
        {
        case LerpType.Lerp: return(Mathfx.Lerp(this.From, this.To, this.LerpZeroToOne));

        case LerpType.Hermite: return(Mathfx.Lerp(this.From, this.To, this.LerpZeroToOne));

        case LerpType.Sinerp: return(Mathfx.Sinerp(this.From, this.To, this.LerpZeroToOne));

        case LerpType.Coserp: return(Mathfx.Coserp(this.From, this.To, this.LerpZeroToOne));

        case LerpType.Berp: return(Mathfx.Berp(this.From, this.To, this.LerpZeroToOne));

        case LerpType.Smoothstep: return(Mathfx.SmoothStep(this.From, this.To, this.LerpZeroToOne));

        case LerpType.Clerp: return(Mathfx.Clerp(this.From, this.To, this.LerpZeroToOne));

        default: throw new ArgumentOutOfRangeException();
        }
    }
예제 #18
0
        private float ApplyEasing(float erpPos)
        {
            switch (EaseType)
            {
            case EaseType.In:
                return(Mathfx.Coserp(0, 1, erpPos));

            case EaseType.Out:
                return(Mathfx.Sinerp(0, 1, erpPos));

            case EaseType.InOut:
                return(Mathfx.Hermite(0, 1, erpPos));

            case EaseType.Boing:
                return(Mathfx.Berp(0, 1, erpPos, .5f));

            case EaseType.Bounce:
                return(Mathfx.Bounce(erpPos));
            }

            return(erpPos);
        }
예제 #19
0
    private IEnumerator MoveRoutine(float toX, float toY, float duration, string ease)
    {
        float   time          = 0f;
        Vector2 startPosition = transform.position;
        Vector2 to            = Spawner.ScaleToAspectRatio(toX, toY);

        while (time < duration)
        {
            if (!paused)
            {
                time += Time.deltaTime;

                Vector2 newPos;
                switch (ease)
                {
                case "InOut":
                    newPos = Mathfx.Hermite(startPosition, to, time / duration);
                    break;

                case "Out":
                    newPos = Mathfx.Sinerp(startPosition, to, time / duration);
                    break;

                case "In":
                    newPos = Mathfx.Coserp(startPosition, to, time / duration);
                    break;

                default:
                    newPos = Vector2.Lerp(startPosition, to, time / duration);
                    break;
                }
                transform.position = newPos;
            }

            yield return(null);
        }
    }
예제 #20
0
    public IEnumerator LerpZoom(List <Vector3> vStart, List <Vector3> vEnd, List <float> fStart, List <float> fEnd, float time, Action whenDone = null)
    {
        float elapsed = 0f;

        isLerping = true;

        // orbit lines
        BuildCircleMesh[] lines = FindObjectsOfType(typeof(BuildCircleMesh)) as BuildCircleMesh[];

        // lights
        Light starLight = new List <Light>(star.GetComponentsInChildren <Light>()).Find(x => x.flare == null);

        // player ship
        Ship ship = ((SolarSystemScene)scene).playerShip;

        int   v;
        int   f;
        float progress = 0f;

        while (time > 0f && progress < 1f)
        {
            v        = 0;
            f        = 0;
            progress = elapsed / time;

            // lights
            starLight.range = Mathfx.Hermite(fStart[f], fEnd[f], progress);
            f++;

            // this planet scale
            transform.localScale = Mathfx.Hermite(vStart[v], vEnd[v], progress);
            v++;

            // all planets
            foreach (Planet planet in star.planets)
            {
                planet.transform.position = Mathfx.Hermite(vStart[v], vEnd[v], progress);
                v++;
            }

            // orbit lines
            foreach (BuildCircleMesh line in lines)
            {
                line.innerRadius = Mathfx.Hermite(fStart[f], fEnd[f], progress);
                f++;
            }

            // camera
            Camera.main.transform.position = Mathfx.Hermite(vStart[v], vEnd[v], progress);
            v++;
            Camera.main.orthographicSize = Mathfx.Hermite(fStart[f], fEnd[f], progress);
            f++;

            // player ship
            ship.rigidbody.velocity        = Vector3.zero;
            ship.rigidbody.angularVelocity = Vector3.zero;
            ship.transform.position        = Mathfx.Hermite(vStart[v], vEnd[v], progress);
            v++;

            elapsed += Time.deltaTime;
            yield return(null);
        }

        // make sure the end is exact
        v = 0;
        f = 0;

        // lights
        starLight.range = fEnd[f];
        f++;

        // this planet scale
        transform.localScale = vEnd[v];
        v++;

        // all planets
        foreach (Planet planet in star.planets)
        {
            planet.transform.position = vEnd[v];
            v++;
        }

        // orbit lines
        foreach (BuildCircleMesh line in lines)
        {
            line.innerRadius = fEnd[f];
            f++;
        }

        // camera
        Camera.main.transform.position = vEnd[v];
        v++;
        Camera.main.orthographicSize = fEnd[f];
        f++;

        // player ship
        ship.rigidbody.velocity        = Vector3.zero;
        ship.rigidbody.angularVelocity = Vector3.zero;
        ship.transform.position        = Mathfx.Coserp(vStart[v], vEnd[v], progress);
        v++;

        // orbit lines
        foreach (BuildCircleMesh line in lines)
        {
            line.gameObject.renderer.enabled = true;
        }

        isLerping = false;
        if (whenDone != null)
        {
            whenDone();
        }
    }
 public virtual void TransformUpdate()
 {
     if (_animate)
     {
         if (_unscaledDeltaTime)
         {
             _elapsedAnimTime += Time.unscaledDeltaTime;
         }
         else
         {
             _elapsedAnimTime += Time.deltaTime;
         }
         if (!_finishedDelay)
         {
             if (_elapsedAnimTime > _delayTime)
             {
                 _elapsedAnimTime = 0;
                 _finishedDelay   = true;
             }
             return;
         }
         if (_elapsedAnimTime >= _animationTime)
         {
             if (_loop)
             {
                 _elapsedAnimTime = 0;
                 _returning       = !_returning;
             }
             else
             {
                 transform.localPosition = _endPos;
                 _animate = false;
                 return;
             }
         }
         float time = _elapsedAnimTime / _animationTime;
         if (!_returning)
         {
             if (_evaluationType == AnimationFunction.EASE_IN)
             {
                 transform.localPosition = Mathfx.Coserp(_initialPos, _endPos, time);
             }
             else if (_evaluationType == AnimationFunction.EASE_OUT)
             {
                 transform.localPosition = Mathfx.Sinerp(_initialPos, _endPos, time);
             }
             else if (_evaluationType == AnimationFunction.EASE_IN_OUT)
             {
                 transform.localPosition = Mathfx.Hermite(_initialPos, _endPos, time);
             }
             else if (_evaluationType == AnimationFunction.BOING)
             {
                 transform.localPosition = Mathfx.Berp(_initialPos, _endPos, time);
             }
             else if (_evaluationType == AnimationFunction.CUSTOM_CURVE)
             {
                 transform.localPosition = Vector3.Lerp(_initialPos, _endPos, _customCurve.Evaluate(time));
             }
         }
         else
         {
             if (_evaluationType == AnimationFunction.EASE_IN)
             {
                 transform.localPosition = Mathfx.Coserp(_endPos, _initialPos, time);
             }
             else if (_evaluationType == AnimationFunction.EASE_OUT)
             {
                 transform.localPosition = Mathfx.Sinerp(_endPos, _initialPos, time);
             }
             else if (_evaluationType == AnimationFunction.EASE_IN_OUT)
             {
                 transform.localPosition = Mathfx.Hermite(_endPos, _initialPos, time);
             }
             else if (_evaluationType == AnimationFunction.BOING)
             {
                 transform.localPosition = Mathfx.Berp(_endPos, _initialPos, time);
             }
             else if (_evaluationType == AnimationFunction.CUSTOM_CURVE)
             {
                 transform.localPosition = Vector3.Lerp(_endPos, _initialPos, _customCurve.Evaluate(time));
             }
         }
     }
 }
예제 #22
0
    private IEnumerator OrbitCamera()
    {
        inAnimation = true;
        float duration        = 5.0f;
        float initTime        = Time.unscaledTime;
        float endTSZero       = 0.1f;
        float initTSOne       = 0.8f;
        float initFieldOfView = cam.fieldOfView;
        float distance        = (playerT.position - myTrans.position).magnitude;


        Quaternion tR  = Quaternion.AngleAxis(playerC.sideOfBuilding * 90.0f, Vector3.up) * Quaternion.AngleAxis(90.0f, Vector3.right);
        Vector3    off = tR * Vector3.up * offsetAirUp;



        while (true)
        {
            //calculate duration(0-1)
            float percent = Mathf.Min(1, (Time.unscaledTime - initTime) / duration);

            //rotation animation
            //myTrans.rotation = Quaternion.AngleAxis( Mathf.Lerp(playerC.sideOfBuilding*90, playerC.sideOfBuilding*90 + 360 + 90 + 45, percent), Vector3.up ) *
            //	Quaternion.AngleAxis( (percent < 0.5f ) ? Mathfx.Sinerp(90, 0, percent * 2) : Mathfx.Coserp(0, 60, (percent-0.5f) * 2), Vector3.right );
            float      orbitAngle = Mathfx.Sinerp(playerC.sideOfBuilding * 90, playerC.sideOfBuilding * 90 + 180 + 45, percent);
            Quaternion forOrbit   = Quaternion.AngleAxis(orbitAngle, Vector3.up);

            float heightAngle = (percent < 0.5f) ?
                                Mathfx.Hermite(90, 35, LertEndModify(percent, 0.5f)) :
                                Mathfx.Hermite(35, 60, LerpInitModify(percent, 0.5f));
            Quaternion forHeight = Quaternion.AngleAxis(heightAngle, Vector3.right);

            myTrans.rotation = forOrbit * forHeight;

            //position animation
            GoToPosition(playerT.position + off - myTrans.forward * (distance + percent * 15));

            //TimeScale Animation
            if (percent < endTSZero)
            {
                Time.timeScale = Mathfx.Hermite(1.0f, 0.0f, LertEndModify(percent, endTSZero));
            }
            else if (percent > initTSOne)
            {
                Time.timeScale = Mathfx.Coserp(0.0f, 1.0f, LerpInitModify(percent, initTSOne));
            }

            cam.fieldOfView = Mathfx.Hermite(initFieldOfView, 60, percent);

            //check finish animation
            if (percent == 1)
            {
                break;
            }
            yield return(null);
        }

        animationComplete = true;

        inAnimation = false;
    }