Esempio n. 1
0
    float linearTime;     //= 1f - smoothInTime - smoothOutTime;
    void Update()
    {
        if (moving)
        {
            //velocity = Mathf.Clamp(velocity + 2f*Time.deltaTime, 0, maxVelocity);
            if (blend < 1)
            {
                blend = Mathf.Clamp01(blend + currentTarget.MovementSpeed * Time.deltaTime / distance);
            }
            //float smoothedBlend = blend;//Smoothing.CubicEaseInOut(blend);
            if (blend < smoothInTime)
            {
                //if(!SceneManager.Instance.PendingTransition){
                //	Blackout.Instance.TargetBlackoutValue = 1;
                //	Blackout.Instance.SetFogFade(true);
                //}
                //v = 3x^2
                //smoothedBlend = 0;
                smoothedBlend = smoothInTime * Smoothing.CubicEaseIn(blend / smoothInTime);
            }
            else if (blend > (1f - smoothOutTime))
            {
                smoothedBlend = smoothInTime + (linearTime) * 3f + smoothOutTime * Smoothing.CubicEaseOut((blend - (1 - smoothOutTime)) / smoothOutTime);
                //smoothedBlend = 0.9f + 0.1f*Smoothing.CubicEaseOut(10f*(blend-0.9f));
            }
            else
            {
                smoothedBlend = smoothInTime + (blend - smoothInTime) * 3f;
            }

            if (blend > 1.5f * smoothInTime || blend > 0.5)
            {
                //if(!SceneManager.Instance.PendingTransition){
                //	Blackout.Instance.TargetBlackoutValue = 0;
                //	Blackout.Instance.SetFogFade(true);
                //}
            }

            smoothedBlend = smoothedBlend / (smoothInTime + smoothOutTime + 3f * linearTime);

            if (smoothedBlend < 0.001f)
            {
                smoothedBlend = 0;
            }
            else if (smoothedBlend > 0.999f)
            {
                smoothedBlend = 1;
            }

            transform.position = (1 - smoothedBlend) * previousPosition + smoothedBlend * targetPosition;

            if (blend >= 1)
            {
                moving           = false;
                previousPosition = targetPosition;
                //velocity = 0;
            }
        }
    }