Exemplo n.º 1
0
        private static Vector3 InterpolatePosition(TweenStep from, TweenStep to, float t, bool useBezier)
        {
            t = from.curve.Evaluate(Mathf.Clamp01(t));

            if (useBezier)
            {
                var p0 = from.transform.position;
                var p1 = from.transform.position + from.tangent;
                var p2 = to.transform.position - to.tangent;
                var p3 = to.transform.position;

                var p01 = Vector3.Lerp(p0, p1, t);
                var p12 = Vector3.Lerp(p1, p2, t);
                var p23 = Vector3.Lerp(p2, p3, t);

                var p012 = Vector3.Lerp(p01, p12, t);
                var p123 = Vector3.Lerp(p12, p23, t);

                return(Vector3.Lerp(p012, p123, t));
            }
            else
            {
                return(Vector3.Lerp(from.transform.position, to.transform.position, t));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Stops the tween and samples it at index and value t (range 0 to 1).
        /// 0 means TweenStep at index, 1 TweenStep at index + 1 and 0.5 means halfway both.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="t"></param>
        public void SampleAt(int index, float t)
        {
            from = steps[Mathf.Clamp(index, 0, steps.Count - 1)];
            to   = steps[Mathf.Clamp(index + 1, 0, steps.Count - 1)];

            Interpolate(t);
            enabled = false;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Play tween at this setp index.
        /// </summary>
        /// <param name="index"></param>
        public void PlayForward(int index)
        {
            from  = steps[Mathf.Clamp(index, 0, steps.Count - 1)];
            to    = steps[Mathf.Clamp(index + 1, 0, steps.Count - 1)];
            timer = 0.0f;

            enabled = true;
        }
Exemplo n.º 4
0
        private void SetupFromIndex(int index, int offset)
        {
            from      = steps[Mathf.Clamp(index, 0, steps.Count - 1)];
            to        = steps[Mathf.Clamp(index + offset, 0, steps.Count - 1)];
            direction = offset;

            from.onEnter.Invoke();
            enabled = true;
        }
Exemplo n.º 5
0
 private static Quaternion InterpolateRotation(TweenStep from, TweenStep to, float t)
 {
     t = from.rotationCurve.Evaluate(Mathf.Clamp01(t));
     return(Quaternion.Slerp(from.transform.rotation, to.transform.rotation, t));
 }