Example #1
0
    public IEnumerator UpdateBeamOfLight()
    {
        //yield return new WaitForSeconds(maxCoolDown);
        bool  end  = false;
        float sign = 1;

        while (!end)
        {
            timer += Time.deltaTime * sign * speed;
            float width = Ease.Evaluate(easeFunction, timer) * maxWidth;
            lineRenderer.startWidth = width;
            lineRenderer.endWidth   = width;
            if (timer > 1)
            {
                yield return(new WaitForSeconds(0.5f));

                sign = -1;
            }
            if (timer < 0)
            {
                end = true;
            }
            yield return(null);
        }
        lineRenderer.enabled = false;
        yield return(null);
    }
Example #2
0
    protected IEnumerator SnapCoroutine(Vector2 offset, float time, Ease.Type easeType)
    {
        float elapsed    = 0.0f;
        var   scrollAxis = scrollRect.vertical ? 1 : 0;
        var   startPos   = scrollRect.content.anchoredPosition;
        var   endPos     = startPos + offset;

        while (elapsed < time)
        {
            elapsed = Math.Min(elapsed + Time.unscaledDeltaTime, time);
            var progress = elapsed / time;
            var position = scrollRect.content.anchoredPosition;
            if (m_EaseType == Ease.Type.Custom)
            {
                position[scrollAxis] = Mathf.Lerp(startPos[scrollAxis], endPos[scrollAxis], m_EaseCurve != null ? m_EaseCurve.Evaluate(progress) : progress);
            }
            else
            {
                position[scrollAxis] = Ease.Evaluate(m_EaseType, startPos[scrollAxis], endPos[scrollAxis], progress);
            }
            scrollRect.content.anchoredPosition = position;
            yield return(null);
        }

        scrollRect.content.anchoredPosition = endPos;
        StopSnap();

        m_OnEndSnap.Invoke(GetSnappedTarget());
    }
Example #3
0
        protected float CalculateVerticalSpeed()
        {
            float verticalSpeed = 0f;

            if (jumping)
            {
                float t = ComputeInterpolant(jumpCurve, jumpProgress);
                switch (locomotion)
                {
                case LocomotionMode.Velocity:
                case LocomotionMode.Force:
                    verticalSpeed = jumpSpeed * jumpCurve.Evaluate(t);
                    break;

                case LocomotionMode.CharacterController:
                    verticalSpeed = jumpSpeed * jumpCurve.Evaluate(t);
                    break;

                case LocomotionMode.NavMeshAgent:
                    break;
                }
            }
            else if (!grounded)
            {
                float t = ComputeInterpolant(fallCurve, fallProgress);
                switch (locomotion)
                {
                case LocomotionMode.Velocity:
                case LocomotionMode.Force:
                    break;

                case LocomotionMode.CharacterController:
                    verticalSpeed = fallCurve.Evaluate(t) * gravity.y;
                    break;

                case LocomotionMode.NavMeshAgent:
                    break;
                }
            }
            else
            {
                verticalSpeed = Physics.gravity.y * deltaTime;
            }
            return(verticalSpeed);
        }
Example #4
0
        private IEnumerator EaseCoroutine(Vector3 goalPos)
        {
            Vector3 startPos = m_target.position;
            Vector3 deltaPos = goalPos - startPos;

            Timer timer = new Timer();

            timer.Start();
            float t = 0.0f;

            while (t < m_duration)
            {
                m_target.position = startPos + m_ease.Evaluate(t, m_duration) * deltaPos;
                yield return(null);

                t = timer.Elapsed;
            }

            m_target.position = goalPos;
        }
Example #5
0
 /// <summary>
 /// Computes the intertpolant value 't', to be used in a lerp
 /// </summary>
 /// <param name="progress"></param>
 /// <returns></returns>
 private float ComputeInterpolant(Ease curve, float progress, float min = 0.1f)
 {
     return(curve.Evaluate(Mathf.Max(progress, min)));
 }