Beispiel #1
0
    public virtual void Fire(GameObject objStart, Vector3 endPosition, float duration, string easeName = null)
    {
        this.BindGameLoop();

        _transStart    = objStart.transform;
        _startUnit     = null;
        _startUnitId   = 0;
        _startPosition = _transStart.position;
        _startAngle    = -1.0f;

        _transEnd        = null;
        _endUnit         = null;
        _endUnitId       = 0;
        _endPosition     = endPosition;
        _endTeleportFlag = -1;

        _duration  = duration <= 0 ? _duration : duration;
        _startTime = GetMSTime();
        _easeName  = string.IsNullOrEmpty(easeName) ? _easeName : easeName;
        _easeFunc  = EaseFunc.GetFunction(easeName);

        _transform          = this.transform;
        _transform.position = _startPosition;

        _isEnded          = false;
        _delayTimeCounter = _delayTime;

        this.OnEffectStart();
    }
Beispiel #2
0
    public virtual void Fire(UBattleUnit startUnit, Vector3 endPosition, float duration, string easeName = null)
    {
        this.BindGameLoop();

        _transStart    = startUnit.GetBoneTransform("missile");
        _startUnit     = startUnit;
        _startUnitId   = startUnit.unitId;
        _startPosition = _transStart.position;
        _startAngle    = _startUnit.curDirectionAngle;

        _transEnd        = null;
        _endUnit         = null;
        _endUnitId       = 0;
        _endPosition     = endPosition;
        _endTeleportFlag = -1;

        _duration  = duration <= 0 ? _duration : duration;
        _startTime = GetMSTime();
        _easeName  = string.IsNullOrEmpty(easeName) ? _easeName : easeName;
        _easeFunc  = EaseFunc.GetFunction(easeName);

        _transform          = this.transform;
        _transform.position = _startPosition;

        _isEnded          = false;
        _delayTimeCounter = _delayTime;

        this.OnEffectStart();
    }
Beispiel #3
0
        /// <summary>
        /// Calculate the new value using the Ease and Lerp functions
        /// </summary>
        /// <param name="start">Value to start at</param>
        /// <param name="end">Target Value</param>
        /// <param name="percent">Progress along ease function where 0-1 is 0%-100%</param>
        /// <param name="easeFunc">Function to use when Easing</param>
        /// <param name="lerpFunc">Function to use when Interpolating</param>
        /// <returns>Eased value</returns>
        private static T Calculate(T start, T end, float percent, EaseFunc easeFunc, LerpFunc <T> lerpFunc)
        {
            // Scale the percent based on the ease
            float scaledPercent = easeFunc(percent);

            // Pass in scaled percent to interpolation
            return(lerpFunc(start, end, scaledPercent));
        }
        public static System.Collections.Generic.IEnumerable <float> Go(EaseFunc f, float duration)
        {
            var startTime = Time.timeSinceLevelLoad;

            for (var t = 0f; t < duration; t = (Time.timeSinceLevelLoad - startTime))
            {
                yield return(f(t, 0f, 1f, duration));
            }
            yield return(1f);
        }
Beispiel #5
0
 public ChainItem(T destination, float duration, EaseFunc scaleFunc, TweenAccessors <T> accessors,
                  LerpFunc <T> lerp)
 {
     this.destination = destination;
     this.duration    = duration;
     this.scaleFunc   = scaleFunc;
     this.accessors   = accessors;
     this.lerpFunc    = lerp;
     this.tween       = new Tween <T>(this.lerpFunc);
 }
Beispiel #6
0
            /// <summary>
            /// Transform an ease function by reversing it and appending it to itself to create an InOut from an Out
            /// </summary>
            /// <param name="percent">Progress along ease function where 0-1 is 0%-100%</param>
            /// <param name="Out">Out Ease function to create InOut from (must be OUT)</param>
            /// <returns>An InOut ease function</returns>
            public static float InOut(float percent, EaseFunc Out)
            {
                // If less than halfway
                if (percent < 0.5)
                {
                    // Reverse the Out to create an In, and scale it down by half
                    return(Reverse(percent * 2, Out) / 2);
                }

                // Shift over the out to the halfway point and scale it down by half
                return((Out(percent * 2 - 1) / 2) + 0.5f);
            }
Beispiel #7
0
        /// <summary>
        /// Create a new Tweener
        /// </summary>
        /// <param name="start">Value to start at</param>
        /// <param name="end">Target value</param>
        /// <param name="duration">Time (in seconds) to get to the target</param>
        /// <param name="easeFunc">Ease function to use (defaults to linear if unspecified)</param>
        /// <param name="lerpFunc">Lerp function to use (defaults to generic if unspecified)</param>
        public Tweener(T start, T end, double duration, EaseFunc easeFunc = null, LerpFunc <T> lerpFunc = null)
        {
            _elapsed  = 0.0f;
            _start    = start;
            _end      = end;
            _duration = duration;

            // If there's no ease function specified, use Linear
            _easeFunc = easeFunc ?? Ease.Linear;

            // If there's no lerp function specified, use Generic Default
            _lerpFunc = lerpFunc ?? LerpFuncDefault;

            Value   = _start;
            Running = true;
        }
Beispiel #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericEaseImpl"/> class.
        /// </summary>
        /// <param name="easeInFunc">The ease in function.</param>
        /// <param name="easeOutFunc">The ease out function.</param>
        /// <param name="easeInOutFunc">The ease in out function.</param>
        /// <exception cref="Exception">Both in and out arguments none, this should not happen! This is bad.</exception>
        private GenericEaseImpl(EaseFunc easeInFunc, EaseFunc easeOutFunc, EaseFunc easeInOutFunc)
        {
            if (easeInFunc == null && easeOutFunc == null)
            {
                throw new Exception("Both in and out arguments none, this should not happen! This is bad.");
            }

            // If there's no In function, create one generically (from Out)
            _easeInFunc = easeInFunc ?? GenericIn;

            // If there's no Out function, create one generically (from In)
            _easeOutFunc = easeOutFunc ?? GenericOut;

            // If there's no InOut function, create one generically (from Out)
            _easeInOutFunc = easeInOutFunc ?? GenericInOut;
        }
Beispiel #9
0
    private void OnParabolaStart()
    {
        if (_maxParabolaHeight == 0)
        {
            _parabolaAutoRotate = false;
            _parabolaOffset     = Vector3.zero;
            return;
        }
        _parabolaEaseFunc = _parabolaEase.hasFunc ? _parabolaEase.func : EaseFunc.GetFunction("EaseOutCubic");
        var endPosition    = GetEndPosition();
        var parabolaHeight = _maxParabolaHeight;
        var distance       = UGameTools.GetPosDistance(_startPosition, endPosition);

        if (endPosition.y > _startPosition.y)
        {
            var normalLineLength = Mathf.Abs((endPosition.x - _startPosition.x) * distance * 0.5f / (endPosition.y - _startPosition.y));
            if (normalLineLength <= _maxParabolaHeight)
            {
                parabolaHeight = normalLineLength * 0.5f;
            }
        }
        var heightLimit = distance * _parabolaLimitFactor;

        parabolaHeight = parabolaHeight > heightLimit ? heightLimit : parabolaHeight;
        if (endPosition.x - _startPosition.x > 0)
        {
            _parabolaOffset.x = (endPosition.y - _startPosition.y) * parabolaHeight * -1 / distance;
            _parabolaOffset.y = (endPosition.x - _startPosition.x) * parabolaHeight / distance;
        }
        else
        {
            _parabolaOffset.x = (endPosition.y - _startPosition.y) * parabolaHeight / distance;
            _parabolaOffset.y = (endPosition.x - _startPosition.x) * parabolaHeight * -1 / distance;
        }

        if (_parabolaAutoRotate)
        {
            var nextPosition = GetPosition(0.03f, EaseValue(0.03f), _startPosition, endPosition);
            _transform.localEulerAngles = new Vector3(0, 0, UGameTools.GetPosAngle(_startPosition, nextPosition));
        }
    }
Beispiel #10
0
        /// <summary>
        ///     Starts a tween.
        /// </summary>
        /// <param name="start">The start value.</param>
        /// <param name="end">The end value.</param>
        /// <param name="duration">The duration of the tween.</param>
        /// <param name="easeFunc">A function used to scale progress over time.</param>
        public void Start(T start, T end, float duration, EaseFunc easeFunc)
        {
            if (duration <= 0)
            {
                throw new ArgumentException("duration must be greater than 0");
            }

            if (easeFunc == null)
            {
                throw new ArgumentNullException("easeFunc");
            }

            CurrentTime   = 0;
            Duration      = duration;
            this.easeFunc = easeFunc;
            State         = TweenState.Running;

            StartValue = start;
            EndValue   = end;

            UpdateValue();
        }
Beispiel #11
0
 public TweenChainComponent AddLocalMoveTween(Vector2 targetPos, float duration, EaseFunc easeFunc)
 {
     return(AddTween(targetPos, duration, easeFunc, this.actor.LocalPositionTweenAccessors(), Vector2.Lerp));
 }
Beispiel #12
0
 public TweenChainComponent AddTween <T>(T target, float duration, EaseFunc easeFunc, TweenAccessors <T> accessors,
                                         LerpFunc <T> lerp) where T : struct
 {
     this.chain.Append(new TweenChain.ChainItem <T>(target, duration, easeFunc, accessors, lerp));
     return(this);
 }
Beispiel #13
0
 public static IEase Create(EaseFunc easeInFunc, EaseFunc easeOutFunc, EaseFunc easeInOutFunc = null)
 {
     return(GenericEaseImpl.From(easeInFunc, easeOutFunc, easeInOutFunc));
 }
Beispiel #14
0
    /// <summary>
    /// Easing function range map using Fastest smooth function
    /// </summary>
    /// <param name="x">val</param>
    /// <param name="inStart">In range start</param>
    /// <param name="inEnd">In range end</param>
    /// <param name="outStart">Out range start</param>
    /// <param name="outEnd">out range end</param>
    /// <param name="easingFunc"></param>
    /// <returns></returns>
    public static float RangeMap(float val, float inStart, float inEnd, float outStart, float outEnd, EaseFunc <float, float> easingFunc)
    {
        float res = val - inStart;

        res /= (inEnd - inStart);
        res  = easingFunc(res);
        res *= (outEnd - outStart);
        return(res - outStart);
    }
Beispiel #15
0
 public static float Mix(EaseFunc <float, float> func1, EaseFuncN <float, int, float> funcN, int n, float blend, float x)
 {
     return(((1f - blend) * func1(x)) + (blend * funcN(x, n)));
 }
Beispiel #16
0
 public TweenChain AppendPointTween(Point targetVal, float duration, EaseFunc easeFunc,
                                    TweenAccessors <Point> accessors)
 {
     return(Append(new ChainItem <Point>(targetVal, duration, easeFunc, accessors, TweenChain.PointLerp)));
 }
Beispiel #17
0
 public void AddVectorTween(Vector2 targetVal, float duration, EaseFunc easeFunc,
                            TweenAccessors <Vector2> accessors)
 {
     this.chain.AppendVectorTween(targetVal, duration, easeFunc, accessors);
 }
Beispiel #18
0
 public TweenChain AppendVectorTween(Vector2 targetVal, float duration, EaseFunc easeFunc,
                                     TweenAccessors <Vector2> accessors)
 {
     return(Append(new ChainItem <Vector2>(targetVal, duration, easeFunc, accessors, Vector2.Lerp)));
 }
Beispiel #19
0
 public static System.Collections.Generic.IEnumerable<float> Go(EaseFunc f, float duration)
 {
     var startTime = Time.timeSinceLevelLoad;
     for (var t = 0f; t < duration; t = (Time.timeSinceLevelLoad - startTime))
         yield return f(t, 0f, 1f, duration);
     yield return 1f;
 }
Beispiel #20
0
 public static float CrossFade(EaseFunc <float, float> func1, EaseFuncN <float, int, float> funcN, int n, float x)
 {
     return(((1 - x) * func1(x)) + (x * funcN(x, n)));
 }
Beispiel #21
0
 /// <summary>
 /// To use with SmoothStart2 (exemple) & SmoothStop2 (exemple)
 /// </summary>
 public static float CrossFade(EaseFunc <float, float> func1, EaseFunc <float, float> func2, float x)
 {
     return(((1 - x) * func1(x)) + (x * func2(x)));
 }
Beispiel #22
0
 public TweenChainComponent AddFloatTween(float targetVal, float duration, EaseFunc easeFunc,
                                          TweenAccessors <float> accessors)
 {
     this.chain.AppendFloatTween(targetVal, duration, easeFunc, accessors);
     return(this);
 }
Beispiel #23
0
 /// <summary>
 /// Create a new Generic Implementation set from an Out ease, and an optional InOut ease.
 /// </summary>
 /// <param name="easeOutFunc">Out ease function</param>
 /// <param name="easeInOutFunc">Optional InOut ease function</param>
 /// <returns>A new Generic Ease Set</returns>
 public static GenericEaseImpl FromOut(EaseFunc easeOutFunc, EaseFunc easeInOutFunc = null)
 {
     return(new GenericEaseImpl(null, easeOutFunc, easeInOutFunc));
 }
Beispiel #24
0
 public void AddIntTween(int targetVal, int duration, EaseFunc easeFunc, TweenAccessors <int> accessors)
 {
     this.chain.AppendIntTween(targetVal, duration, easeFunc, accessors);
 }
Beispiel #25
0
 /// <summary>
 /// Create a new Tweener
 /// </summary>
 /// <param name="start">Value to start at</param>
 /// <param name="end">Target value</param>
 /// <param name="duration">Time (in seconds) to get to the target</param>
 /// <param name="easeFunc">Ease function to use (defaults to linear if unspecified)</param>
 /// <param name="lerpFunc">Lerp function to use (defaults to generic if unspecified)</param>
 public Tweener(T start, T end, float duration, EaseFunc easeFunc = null, LerpFunc <T> lerpFunc = null)
     : this(start, end, (double)duration, easeFunc, lerpFunc)
 {
 }
Beispiel #26
0
 /// <summary>
 /// Create a new Tweener
 /// </summary>
 /// <param name="start">Value to start at</param>
 /// <param name="end">Target value</param>
 /// <param name="duration">How long to get to the target</param>
 /// <param name="easeFunc">Ease function to use (defaults to linear if unspecified)</param>
 /// <param name="lerpFunc">Lerp function to use (defaults to generic if unspecified)</param>
 public Tweener(T start, T end, TimeSpan duration, EaseFunc easeFunc = null, LerpFunc <T> lerpFunc = null)
     : this(start, end, duration.TotalSeconds, easeFunc, lerpFunc)
 {
 }
Beispiel #27
0
 public static float FlipScale(EaseFunc <float, float> func, float x, float scale)
 {
     return((1 - x) * func(x) * scale);
 }
Beispiel #28
0
 /// <summary>
 /// Create a new Generic Implementation set from an In ease, and an optional InOut ease.
 /// </summary>
 /// <param name="easeInFunc">In ease function</param>
 /// <param name="easeInOutFunc">Optional InOut ease function</param>
 /// <returns>A new Generic Ease Set</returns>
 public static GenericEaseImpl FromIn(EaseFunc easeInFunc, EaseFunc easeInOutFunc = null)
 {
     return(new GenericEaseImpl(easeInFunc, null, easeInOutFunc));
 }
Beispiel #29
0
 /// <summary>
 /// SmoothStart^A.B = Mix(SmoothStartA, SmoothStartA+1, B)
 /// </summary>
 public static float Mix(EaseFunc <float, float> func1, EaseFunc <float, float> func2, float blend, float x)
 {
     return(((1f - blend) * func1(x)) + (blend * func2(x)));
 }
Beispiel #30
0
 /// <summary>
 /// Reverse an ease function to go from Out -> In, or In -> Out
 /// </summary>
 /// <param name="percent">Progress along ease function where 0-1 is 0%-100%</param>
 /// <param name="easeFunc">Ease function to reverse</param>
 /// <returns>The reverse of the usual output from easeFunc</returns>
 public static float Reverse(float percent, EaseFunc easeFunc)
 {
     return(1 - easeFunc(1 - percent));
 }
Beispiel #31
0
 public static float Scale(EaseFunc <float, float> func, float x, float scale)
 {
     return(scale * func(x));
 }