예제 #1
0
        /// <summary>
        /// Applies the TweenerSettings to this tweener, this will clear OnX callbacks <code>e.g. OnStart(<b>action</b>) if the relevant TweenerSetting events have listeners</code>
        /// </summary>
        /// <param name="tweener">This</param>
        /// <param name="settings">Tweener settings to apply</param>
        /// <returns>The modified tweener</returns>
        public static Tweener ApplySettings([NotNull] this Tweener tweener, TweenerSettings settings)
        {
            if (tweener == null)
            {
                throw new ArgumentNullException(nameof(tweener));
            }
            if (settings == null)
            {
                return(tweener);
            }
            tweener.SetDelay(settings.Delay);

            if (settings.StopMotionEase)
            {
                tweener.SetEase(EaseFactory.StopMotion(settings.StopMotionEaseFrameRate, settings.EaseFunction));
            }
            else
            {
                tweener.SetEase(settings.EaseFunction, settings.EaseOvershoot, settings.EasePeriod);
            }

            tweener.SetAutoKill(settings.AutoKill);

            tweener.SetLoops(settings.Loops, settings.LoopType);
            tweener.SetUpdate(settings.UpdateType);

            // Events
            if (settings.OnStart.GetPersistentEventCount() > 0)
            {
                tweener.OnStart(() => settings.OnStart?.Invoke());
            }
            if (settings.OnKill.GetPersistentEventCount() > 0)
            {
                tweener.OnKill(() => settings.OnKill?.Invoke());
            }
            if (settings.OnPlay.GetPersistentEventCount() > 0)
            {
                tweener.OnPlay(() => settings.OnPlay?.Invoke());
            }
            if (settings.OnPause.GetPersistentEventCount() > 0)
            {
                tweener.OnPause(() => settings.OnPause?.Invoke());
            }
            if (settings.OnRewind.GetPersistentEventCount() > 0)
            {
                tweener.OnRewind(() => settings.OnRewind?.Invoke());
            }
            if (settings.OnStepComplete.GetPersistentEventCount() > 0)
            {
                tweener.OnStepComplete(() => settings.OnStepComplete?.Invoke());
            }
            if (settings.OnComplete.GetPersistentEventCount() > 0)
            {
                tweener.OnComplete(() => settings.OnComplete?.Invoke());
            }
            return(tweener);
        }
 void CreateTweenerSettingsIfNull(ref TweenerSettings tweenerSettings)
 {
     if (tweenerSettings == null)
     {
         tweenerSettings = ScriptableObject.CreateInstance <TweenerSettings>();
         Debug.LogWarning(
             $"Warning: A tweener setting has not been set on \"{tweenerSettings}\" a default linear tween with a duration of 1 second will be used",
             this);
     }
 }
예제 #3
0
        /// <summary>Tweens a property or field to the given value using default plugins</summary>
        /// <param name="getter">A getter for the field or property to tween.
        /// <para>Example usage with lambda:</para><code>()=&gt; myProperty</code></param>
        /// <param name="setter">A setter for the field or property to tween
        /// <para>Example usage with lambda:</para><code>x=&gt; myProperty = x</code></param>
        /// <param name="endValue">The end value to reach</param>
        /// <param name="settings">Tweener Settings to use for this tween</param>
        public static TweenerCore <float, float, FloatOptions> To(DOGetter <float> getter, DOSetter <float> setter, float endValue, TweenerSettings settings)
        {
            TweenerCore <float, float, FloatOptions> tweener = DG.Tweening.DOTween.To(getter, setter, endValue, settings.Duration).ApplySettings(settings);

            return(tweener);
        }
예제 #4
0
        private static TweenerCore <T1, T2, TPlugOptions> ApplySettings <T1, T2, TPlugOptions>(this TweenerCore <T1, T2, TPlugOptions> tweenerCore, TweenerSettings settings)
            where TPlugOptions : struct, IPlugOptions
        {
            var tweener = tweenerCore as Tweener;

            tweener.ApplySettings(settings);
            return(tweenerCore);
        }