Ease() public static method

public static Ease ( double linearStep, double acceleration, EasingType type ) : float
linearStep double
acceleration double
type EasingType
return float
    private void DrawCurveField(Rect position, SerializedProperty property)
    {
        Easing target = property.GetValue <Easing> ();

        position.x     = (position.width - curveFieldHeight) / 2f;
        position.width = curveFieldHeight;
        EditorGUI.DrawRect(position, Color.gray);

        float deltaX_ = 1f / pointNumber;

        for (int i = 0; i < pointNumber; i++)
        {
            float   x1     = deltaX_ * i;
            float   x2     = deltaX_ * (i + 1);
            Vector2 point1 = new Vector2(x1, target.Ease(x1));
            Vector2 point2 = new Vector2(x2, target.Ease(x2));

            point1   *= curveFieldHeight;
            point1.x += position.x;
            point1.y  = position.y + curveFieldHeight - point1.y;
            point2   *= curveFieldHeight;
            point2.x += position.x;
            point2.y  = position.y + curveFieldHeight - point2.y;

            Handles.color = Color.red;
            Handles.DrawLine(point1, point2);
        }
    }
	}//end of FSCallBack

	void Update () {
		if(state == FSState.idle) return;

		float u = (Time.time - timeStart);
		float uC = Easing.Ease (u, easingCurve);
		if (u < 0) {
			state = FSState.pre;
			transform.position = bezierPts [0];
		}//end of if
		else {
			if (u >= 1) {
				uC = 1;
				state = FSState.post;
				if (reportFinishTo != null) {
					reportFinishTo.SendMessage ("FSCallback", this);
					Destroy (gameObject);
				}//end of second nested if
				else {
					state = FSState.idle;
				}//end of second nested else
			}//end of nested if
			else {
				state = FSState.active;
			}//end of nested else
		}//end of else
		Vector3 pos = Utils.Bezier(uC, bezierPts);
		transform.position = pos;
		if (fontSizes != null && fontSizes.Count > 0) {
			int size = Mathf.RoundToInt (Utils.Bezier (uC, fontSizes));
			GetComponent<GUIText> ().fontSize = size;
		}//end of if
	}//end of Update
Beispiel #3
0
        protected override void OnUpdate(float time)
        {
            var lerpColor = color;

            lerpColor.a = Easing.Ease(interpolation, 0, color.a, GetClipWeight(time));
            DirectorGUI.UpdateOverlayText(text, lerpColor, size, anchor, position);
        }
        public override IObservable <IBrush> DoTransition(IObservable <double> progress, IBrush oldValue, IBrush newValue)
        {
            // This strange behavior occurs on every application shutdown with alternating null values for a few calls.
            if (oldValue is null || newValue is null)
            {
                return(progress.Select(p => new SolidColorBrush(default(Color))));
            }

            if (oldValue is not ISolidColorBrush oldBrush)
            {
                throw new ArgumentException("Only instances of ISolidColorBrush are supported", nameof(oldValue));
            }
            if (newValue is not ISolidColorBrush newBrush)
            {
                throw new ArgumentException("Only instances of ISolidColorBrush are supported", nameof(newValue));
            }

            Color oldColor = oldBrush.Color;
            Color newColor = newBrush.Color;

            return(progress.Select(p =>
            {
                double e = Easing.Ease(p);
                int A = (int)(e * (newColor.A - oldColor.A) + 0.5) + oldColor.A;
                int R = (int)(e * (newColor.R - oldColor.R) + 0.5) + oldColor.R;
                int G = (int)(e * (newColor.G - oldColor.G) + 0.5) + oldColor.G;
                int B = (int)(e * (newColor.B - oldColor.B) + 0.5) + oldColor.B;

                return new SolidColorBrush(new Color((byte)A, (byte)R, (byte)G, (byte)B));
            }));
        }
Beispiel #5
0
        protected override void OnUpdate(float deltaTime)
        {
            var lerpColor = color;

            lerpColor.a = Easing.Ease(interpolation, 0, color.a, GetClipWeight(deltaTime));
            DirectorGUI.UpdateSubtitles(text, lerpColor);
        }
        protected override void OnUpdate(float deltaTime)
        {
            var lerpColor = color;

            lerpColor.a = Easing.Ease(interpolation, 0, color.a, GetClipWeight(deltaTime));
            DirectorGUI.UpdateOverlayImage(texture, lerpColor, scale, position);
        }
Beispiel #7
0
    // Compare two Shots. 1 is a perfect match, while <0 is not valid
    public static float Compare(Shot target, Shot test)
    {
        // Get the postional deviation of both the camera and the Raycast hit
        float posDev = (test.position - target.position).magnitude;
        float tarDev = (test.target - target.target).magnitude;

        float        posAccPct, tarAccPct, posAP2, tarAP2;  // Accuracy percentages
        TargetCamera tc = TargetCamera.S;

        // Get a value for accuracy where 1 is perfect and 0 is barely okay
        posAccPct = 1 - (posDev / tc.maxPosDeviation);
        tarAccPct = 1 - (tarDev / tc.maxTarDeviation);

        // Curve the value so that it's more forgiving. This uses the same
        // Easing that we do for motion. You can curve ANY value between
        // 0 and 1, not just Interpolation values.
        posAP2 = Easing.Ease(posAccPct, tc.deviationEasing);
        tarAP2 = Easing.Ease(tarAccPct, tc.deviationEasing);

        float accuracy = (posAP2 + tarAP2) / 2f;

        // Remember that you can use Utills to format numbers nicely as strings
        string accText = Utils.RoundToPlaces(accuracy * 100).ToString() + "%";

        Utils.tr("Position:", posAccPct, posAP2, "Target:", tarAccPct, tarAP2, "Accuracy:", accText);

        return(accuracy);
    }
        void Update()
        {
            if (!Enabled || _target == null || _target.Destroyed)
            {
                return;
            }

            var targetLocalPos = parent.InverseTransformPoint(_target.Pos);

            var nextPos = targetLocalPos + _offset;

            SetXY(nextPos.x, nextPos.y);

            _shadowText.EasyDraw.alpha = this.EasyDraw.alpha;

            if (_isFading && _offSetAnimTimer <= _fadeInOutDuration)
            {
                float xPos = _offsetAnim.x * Easing.Ease(Easing.Equation.QuadEaseOut, _offSetAnimTimer, 0, 1, _fadeInOutDuration);
                float yPos = _offsetAnim.y * Easing.Ease(Easing.Equation.QuadEaseOut, _offSetAnimTimer, 0, 1, _fadeInOutDuration);

                SetXY(nextPos.x + xPos, nextPos.y + yPos);

                _offSetAnimTimer += Time.deltaTime;
            }

            if (Input.GetKeyDown(Key.L))
            {
                Show(100);
            }
        }
Beispiel #9
0
 void Animate()
 {
     rt = 0f;
     StartCoroutine(Easing.Ease(duration, Easing.Quadratic.Out, (float t) => {
         rt = t;
     }, 0f, 1f));
 }
Beispiel #10
0
    // Сравниваем два снимка. 1 - идеально подходит, <0 не подходит
    public static float Compare(Shot target, Shot test)
    {
        // Считаем отклонение камеры и удара от Raycast
        float posDev = (test.position - target.position).magnitude;
        float tarDev = (test.target - target.target).magnitude;

        float posAccPct, tarAccPct, posAP2, tarAP2; // Степень точности

        TargetCamera tc = TargetCamera.S;

        // Получаем значение точности, где 1 - идеально, 0 - кое как подходит
        posAccPct = 1 - (posDev / tc.maxPosDeviation);
        tarAccPct = 1 - (tarDev / tc.maxTarDeviation);

        // Смягчаем значения чтобы оно было более прощающее
        posAP2 = Easing.Ease(posAccPct, tc.deviationEasing);
        tarAP2 = Easing.Ease(tarAccPct, tc.deviationEasing);

        float accuracy = (posAP2 + tarAP2) / 2f;

        // Используем Utils чтобы оформить числа в хорошенькую строку
        string accText = Utils.RoundToPlaces(accuracy * 100).ToString() + "%";

        Utils.tr("Position:", posAccPct, posAP2, "Target:", tarAccPct, tarAP2, "Accuracy", accuracy);

        return(accuracy);
    }
Beispiel #11
0
        void Update()
        {
            if (!this.Enabled)
            {
                return;
            }

            if (_lifeTimeCounter > _lifeTime)
            {
                //Fall bullet

                _isCollisionEnabled = false;

                float scale = 0.001f + Easing.Ease(Easing.Equation.QuadEaseIn, _lifeTimeCounter - _lifeTime, 0.999f, 0 - 0.999f, 400);
                SetScaleXY(scale, scale);

                if (_lifeTimeCounter > _lifeTime + 400)
                {
                    this.SetActive(false);
                    _isCollisionEnabled = true;
                }
            }
            _lifeTimeCounter += Time.deltaTime;

            Move(_speed * Time.delta, 0);

            if (MyGame.Debug)
            {
                DrawBoundBox();
            }
        }
        static IEnumerator TweenSpriteScaleRoutine(GameObject g, Vector2 from, Vector2 to, int duration,
                                                   Easing.Equation easing,
                                                   int delay = 0, OnFinished onFinished = null)
        {
            if (delay > 0)
            {
                yield return(new WaitForMilliSeconds(delay));
            }

            float durationF = duration * 0.001f;
            float time      = 0;

            g.SetScaleXY(from.x, from.y);

            while (time < durationF)
            {
                float easeVal = Easing.Ease(easing, time, 0, 1, durationF);

                float easeValMapX = Mathf.Map(easeVal, 0, 1, from.x, to.x);
                float easeValMapY = Mathf.Map(easeVal, 0, 1, from.y, to.y);

                float scaleX = easeValMapX;
                float scaleY = easeValMapY;

                g.SetScaleXY(scaleX, scaleY);

                time += Time.delta;

                yield return(null);
            }

            onFinished?.Invoke();
        }
Beispiel #13
0
        private static IEnumerator TweenAlphaRoutine(Sprite sprite, float from, float to, int duration, int delay,
                                                     OnTweenComplete onComplete,
                                                     Easing.Equation equation)
        {
            //TODO: remove this call to WaitForMilliSeconds and implement it in the while loop to prevent another instantiation of a yield
            if (delay > 0)
            {
                yield return(new WaitForMilliSeconds(delay));
            }

            int time = 0;

            sprite.alpha = from;

            float fromDir = from > to ? from : 0;
            float toDir   = from > to ? 0 : from;

            while (time < duration)
            {
                sprite.alpha = toDir + Easing.Ease(equation, time, fromDir, to - from, duration);

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

            sprite.alpha = to;

            if (onComplete != null)
            {
                onComplete.Invoke(sprite);
            }
        }
Beispiel #14
0
        /// <inheritdocs/>
        public override IObservable <double> DoTransition(IObservable <double> progress, double oldValue, double newValue)
        {
            var delta = newValue - oldValue;

            return(progress
                   .Select(p => Easing.Ease(p) * delta + oldValue));
        }
 public float GetAxis()
 {
     if (type == VirtualInputChannelType.Axis)
     {
         if (isAxisToAxisRemapped)
         {
             float value = UnInput.GetAxisRaw(name);
             if (value < 0)
             {
                 return(-Easing.Ease(axisToAxisRemapType, axisToAxisRemapPhase, -value) * axisToAxisRemapScale);
             }
             else
             {
                 return(Easing.Ease(axisToAxisRemapType, axisToAxisRemapPhase, value) * axisToAxisRemapScale);
             }
         }
         else
         {
             return(UnInput.GetAxisRaw(name));
         }
     }
     else if (type == VirtualInputChannelType.Button)
     {
         if (negName != null)
         {
             bool pos = UnInput.GetButton(name), neg = UnInput.GetButton(negName);
             if (pos ^ neg)
             {
                 return(pos ? buttonToAxisValue : -buttonToAxisValue);
             }
             else
             {
                 return(0);
             }
         }
         else
         {
             return(UnInput.GetButton(name) ? buttonToAxisValue : 0);
         }
     }
     else              // Key
     {
         if (negKey != UnKeyCode.None)
         {
             bool pos = UnInput.GetKey(key), neg = UnInput.GetKey(negKey);
             if (pos ^ neg)
             {
                 return(pos ? buttonToAxisValue : -buttonToAxisValue);
             }
             else
             {
                 return(0);
             }
         }
         else
         {
             return(UnInput.GetKey(key) ? buttonToAxisValue : 0);
         }
     }
 }
Beispiel #16
0
        public float GetValue(float time)
        {
            //Only have one keyframe? Just return it.
            if (Data.Length == 1)
            {
                return(Data [0].Item2);
            }
            //Locate the keyframes to interpolate between
            float t1 = float.NegativeInfinity;
            float t2 = 0, v1 = 0, v2 = 0;

            for (int i = 0; i < Data.Length - 1; i++)
            {
                if (time >= Data [i].Item1 && time <= Data [i + 1].Item1)
                {
                    t1 = Data [i].Item1;
                    t2 = Data [i + 1].Item1;
                    v1 = Data [i].Item2;
                    v2 = Data [i + 1].Item2;
                    break;
                }
            }
            //Time wasn't between any values. Return max.
            if (t1 == float.NegativeInfinity)
            {
                return(Data [Data.Length - 1].Item2);
            }
            //Interpolate!
            return(Easing.Ease(Type, time, t1, t2, v1, v2));
        }
Beispiel #17
0
        /// <inheritdocs/>
        public override IObservable <int> DoTransition(IObservable <double> progress, int oldValue, int newValue)
        {
            var delta = newValue - oldValue;

            return(progress
                   .Select(p => (int)(Easing.Ease(p) * delta + oldValue)));
        }
Beispiel #18
0
        private async Task AnimateAsync(double startValue, double value, Easing easing, int duration, int rate, int animationId)
        {
            int lastTime = 0;
            int i;

            for (i = rate; i <= duration; i += rate)
            {
                await Task.Delay(rate);

                var time     = (double)i / duration;
                var newValue = startValue + easing.Ease(time) * (value - startValue);

                if (!UpdateIndicatorValue(newValue, animationId))
                {
                    return;
                }

                lastTime = i;
            }

            if (lastTime < duration)
            {
                await Task.Delay(duration - lastTime);

                if (!UpdateIndicatorValue(value, animationId))
                {
                    return;
                }
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                this.AnimationCompleted?.Invoke(this, EventArgs.Empty);
            });
        }
Beispiel #19
0
        public override IObservable <Vector4> DoTransition(IObservable <double> progress, Vector4 oldValue, Vector4 newValue)
        {
            var delta = newValue - oldValue;

            return(progress
                   .Select(p => (float)Easing.Ease(p) * delta + oldValue));
        }
Beispiel #20
0
        protected override void OnUpdate(float time)
        {
            var value = Easing.Ease(interpolation, wasSpeed, speed, GetClipWeight(time));

            value = Mathf.Clamp(value, 0.01f, 100);
            root.playbackSpeed = value;
        }
Beispiel #21
0
        protected override void OnUpdate(float time, float previousTime)
        {
            if (_PlayOver)
            {
                return;
            }
            if (audioClip == null)
            {
                return;
            }
            if (source != null && !_PlayLoop)
            {
                float currentTimeLength = time - clipOffset;
                if (currentTimeLength > audioClip.length)
                {
                    _PlayOver = true;
                    return;
                }
                var weight      = Easing.Ease(EaseType.QuadraticInOut, 0, 1, GetClipWeight(time));
                var totalVolume = weight * volume * track.weight;

                AudioSampler.Sample(source, audioClip, currentTimeLength, previousTime - clipOffset, totalVolume, track.ignoreTimeScale);
                source.panStereo = Mathf.Clamp01(stereoPan + track.stereoPan);
                source.loop      = _PlayLoop;
                if (!string.IsNullOrEmpty(subtitlesText))
                {
                    var lerpColor = subtitlesColor;
                    lerpColor.a = weight;
                    DirectorGUI.UpdateSubtitles(string.Format("{0}{1}", parent is ActorAudioTrack? (actor.name + ": ") : "", subtitlesText), lerpColor);
                }
            }
        }
Beispiel #22
0
    /**
     * Metodo invocado una vez por frame. Segun la accion actual, ejecuta el movimiento
     * dependiendo del tiempo en el que estamos
     **/
    public void Update()
    {
        if (this.isMoving)
        {
            float u = (1f / timeDuration) * (Time.time - timeStart);

            this.transform.position = (1 - u) * this.orgPosition + u * this.poi;

            if (u >= 1)            //fin del movimiento
            {
                this.transform.position = this.poi;
                isMoving = false;                 //fin del movimiento
                Director.S.Next();
                Robot.S.updatePosition();
                //this.animationController.setIdle ();
            }
        }

        if (this.isRotating)
        {
            float u = (Time.time - timeStart) / timeDuration;

            this.transform.rotation = Quaternion.Euler((1 - u) * this.orgRotation + u * this.rotPoi);

            if (u >= 1)
            {
                this.transform.rotation = Quaternion.Euler(this.rotPoi);
                this.rotAct             = this.rotPoi;
                isRotating = false;                 //fin del giro
                Director.S.Next();
                //this.animationController.setIdle ();
            }
        }

        if (this.isJumping)
        {
            float u = (Time.time - timeStart) / timeDuration;

            // Use Easing class from Utils to curve the u value
            float uC = Easing.Ease(u, Easing.InOut);

            if (u >= 1)             // If u>=1, we're finished moving
            {
                uC = 1;             // Set uC=1 so we don't overshoot

                // Move to the final position
                transform.position = bezierPts[bezierPts.Count - 1];
                this.isJumping     = false;
                Director.S.Next();
                Robot.S.updatePosition();
                //this.animationController.setIdle ();
            }
            else                 // 0<=u<1, which means that this is interpolating now
                                 // Use Bezier curve to move this to the right point
            {
                Vector3 pos = Utils.Bezier(uC, bezierPts);
                transform.position = pos;
            }
        }
    }
Beispiel #23
0
 protected override void OnUpdate(float time)
 {
     if (instance != null)
     {
         instance.transform.localScale = Easing.Ease(popupInterpolation, Vector3.zero, wasScale, GetClipWeight(time));
     }
 }
Beispiel #24
0
        private IEnumerator PlaySmallSmokeRoutine(GameObject parentObj, float px, float py, int duration,
                                                  int depthIndex)
        {
            if (depthIndex < 0)
            {
                parentObj.AddChild(_smallBlackSmoke00);
            }
            else
            {
                parentObj.AddChildAt(_smallBlackSmoke00, depthIndex);
            }

            _smallBlackSmoke00.visible = true;
            _smallBlackSmoke00.SetXY(px, py);

            _smallBlackSmoke00.alpha = 1;

            float time = 0;

            while (time < duration)
            {
                float fFrame = Mathf.Map(time, 0, duration, 0, _smallBlackSmoke00.frameCount - 1);
                int   frame  = Mathf.Round(fFrame) % _smallBlackSmoke00.frameCount;

                _smallBlackSmoke00.alpha = 1 - Easing.Ease(Easing.Equation.CubicEaseIn, time, 0, 1, duration);

                _smallBlackSmoke00.SetFrame(frame);

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

            _smallBlackSmoke00.visible = false;
            parentObj?.RemoveChild(_smallBlackSmoke00);
        }
Beispiel #25
0
        protected override void OnUpdate(float deltaTime)
        {
            var color = outColor;

            color.a = Easing.Ease(interpolation, 0, 1, GetClipWeight(deltaTime) * fade);
            DirectorGUI.UpdateFade(color);
        }
Beispiel #26
0
        protected override void OnUpdate(float time, float previousTime)
        {
            if (source != null)
            {
                var weight   = Easing.Ease(EaseType.QuadraticInOut, 0, 1, GetClipWeight(time));
                var settings = track.sampleSettings;
                settings.volume *= weight * volume;
                settings.pitch  *= pitch;
                settings.pan    += stereoPan;

                AudioSampler.Sample(source, audioClip, time - clipOffset, previousTime - clipOffset, settings);

                if (AutoJawSync != null)
                {
                    AutoJawSync.SyncUpdate();
                }

                if (!string.IsNullOrEmpty(subtitlesText))
                {
                    var lerpColor = subtitlesColor;
                    lerpColor.a = weight;
                    DirectorGUI.UpdateSubtitles(string.Format("{0}{1}", parent is ActorAudioTrack ? (actor.name.Replace("(Clone)", "") + ": ") : "", subtitlesText), lerpColor);
                }
            }
        }
Beispiel #27
0
        protected override void OnUpdate(float time)
        {
            var value = Easing.Ease(interpolation, wasScale, timeScale, GetClipWeight(time));

            value          = Mathf.Clamp(value, 0.01f, 100);
            Time.timeScale = value;
        }
        private static IEnumerator TweenIntegerRoutine(IHasTweenInteger tweened, int @from, int to, int duration, int delay, Easing.Equation equation)
        {
            if (delay > 0)
            {
                yield return(new WaitForMilliSeconds(delay));
            }

            int time = 0;

            float fromDir = from > to ? from : 0;
            float toDir   = from > to ? 0 : from;

            while (time < duration)
            {
                tweened.IntValue = Mathf.Round(toDir + Easing.Ease(equation, time, fromDir, to - from, duration));

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

            tweened.IntValue = to;

            if (_tweenMap.ContainsKey(tweened))
            {
                _tweenMap.Remove(tweened);
            }
        }
Beispiel #29
0
    // Update is called once per frame
    void Update()
    {
        // If this is not moving, just return
        if (state == eFSState.idle)
        {
            return;
        }

        // Get u from the current time and duration
        // u ranges from 0 to 1 (usually)
        float u = (Time.time - timeStart) / timeDuration;
        // Use Easing class from Utils to curve the u value
        float uC = Easing.Ease(u, easingCurve);

        if (u < 0)
        {                        // If u<0, then we shouldn't move yet.
            state       = eFSState.pre;
            txt.enabled = false; // Hide the score initially
        }
        else
        {
            if (u >= 1)
            {              // If u>=1, we're done moving
                uC    = 1; // Set uC=1 so we don't overshoot
                state = eFSState.post;
                if (reportFinishTo != null)
                { //If there's a callback GameObject
                  // Use SendMessage to call the FSCallback method
                  //  with this as the parameter.
                    reportFinishTo.SendMessage("FSCallback", this);
                    // Now that the message has been sent,
                    //  Destroy this gameObject
                    Destroy(gameObject);
                }
                else
                { // If there is nothing to callback
                  // ...then don't destroy this. Just let it stay still.
                    state = eFSState.idle;
                }
            }
            else
            {
                // 0<=u<1, which means that this is active and moving
                state       = eFSState.active;
                txt.enabled = true; // Show the score once more
            }
            // Use Bézier curve to move this to the right point
            Vector2 pos = Utils.Bezier(uC, bezierPts);
            // RectTransform anchors can be used to position UI objects relative
            //  to total size of the screen
            rectTrans.anchorMin = rectTrans.anchorMax = pos;
            if (fontSizes != null && fontSizes.Count > 0)
            {
                // If fontSizes has values in it
                // ...then adjust the fontSize of this GUIText
                int size = Mathf.RoundToInt(Utils.Bezier(uC, fontSizes));
                GetComponent <Text>().fontSize = size;
            }
        }
    }
Beispiel #30
0
        public float GetValue(float sparam, float time)
        {
            //1 item, 1 value
            if (Items.Count == 1)
            {
                return(Items [0].GetValue(time));
            }
            //Find 2 keyframes to interpolate between
            AlchemyFloats f1 = null, f2 = null;

            for (int i = 0; i < Items.Count - 1; i++)
            {
                if (sparam >= Items [i].SParam && sparam <= Items [i + 1].SParam)
                {
                    f1 = Items [i];
                    f2 = Items [i + 1];
                    break;
                }
            }
            //We're at the end
            if (f1 == null)
            {
                return(Items [Items.Count - 1].GetValue(time));
            }
            //Interpolate between SParams
            var v1 = f1.GetValue(time);
            var v2 = f2.GetValue(time);

            return(Easing.Ease(Type, sparam, f1.SParam, f2.SParam, v1, v2));
        }