From 9d786ab096ed36ea384e03ee5cea498790e31eec Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Sun, 17 Jul 2022 20:26:28 +0200 Subject: wip --- Samples/AnimTest/Animation/FloatAnimation2.cs | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Samples/AnimTest/Animation/FloatAnimation2.cs (limited to 'Samples/AnimTest/Animation/FloatAnimation2.cs') diff --git a/Samples/AnimTest/Animation/FloatAnimation2.cs b/Samples/AnimTest/Animation/FloatAnimation2.cs new file mode 100644 index 00000000..1d5c9193 --- /dev/null +++ b/Samples/AnimTest/Animation/FloatAnimation2.cs @@ -0,0 +1,60 @@ +// Copyright (c) 2015-2021 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + +using System; + +namespace vke +{ + public class FloatAnimation2 : Animation + { + + public float TargetValue; + protected float initialValue; + int stepCount, currentStep; + + #region CTOR + public FloatAnimation2(Object instance, string _propertyName, float Target, int _stepCount = 20) + : base(instance, _propertyName) + { + + TargetValue = Target; + + float value = getValue(); + initialValue = value; + + stepCount = _stepCount; + } + #endregion + + bool smooth = true; + + float smoothedStep (float step) => (-MathF.Cos (step * MathF.PI) + 1)/2.0f; + + public override void Process() + { + + currentStep++; + + float t = (float)currentStep / (float)stepCount; + if (smooth) + t = smoothedStep (t); + + setValue (initialValue + t * (TargetValue - initialValue)); + + if (currentStep < stepCount) + return; + + setValue(TargetValue); + AnimationList.Remove(this); + RaiseAnimationFinishedEvent (); + } + + public override string ToString () + { + return string.Format ("{0}:->{1}:{2}",base.ToString(),TargetValue,stepCount); + } + } + +} + -- cgit v1.3.1-4-g156e