// Author: Daniele Giardini - http://www.demigiant.com // Created: 2014/05/05 16:36 // // License Copyright (c) Daniele Giardini. // This work is subject to the terms at http://dotween.demigiant.com/license.php #if COMPATIBLE using DOVector2 = DG.Tweening.Core.Surrogates.Vector2Wrapper; using DOVector3 = DG.Tweening.Core.Surrogates.Vector3Wrapper; using DOVector4 = DG.Tweening.Core.Surrogates.Vector4Wrapper; using DOQuaternion = DG.Tweening.Core.Surrogates.QuaternionWrapper; using DOColor = DG.Tweening.Core.Surrogates.ColorWrapper; #else using DOVector2 = UnityEngine.Vector2; using DOVector3 = UnityEngine.Vector3; using DOVector4 = UnityEngine.Vector4; using DOQuaternion = UnityEngine.Quaternion; using DOColor = UnityEngine.Color; #endif using DG.Tweening.Core; using DG.Tweening.Core.Easing; using DG.Tweening.Plugins; using DG.Tweening.Plugins.Core.PathCore; using DG.Tweening.Plugins.Options; using UnityEngine; #pragma warning disable 1573 namespace DG.Tweening { /// /// Methods that extend Tween objects and allow to set their parameters /// public static class TweenSettingsExtensions { #region Tweeners + Sequences /// Sets the autoKill behaviour of the tween to TRUE. /// Has no effect if the tween has already started or if it's added to a Sequence public static T SetAutoKill(this T t) where T : Tween { if (t == null || !t.active || t.creationLocked) return t; t.autoKill = true; return t; } /// Sets the autoKill behaviour of the tween. /// Has no effect if the tween has already started or if it's added to a Sequence /// If TRUE the tween will be automatically killed when complete public static T SetAutoKill(this T t, bool autoKillOnCompletion) where T : Tween { if (t == null || !t.active || t.creationLocked) return t; t.autoKill = autoKillOnCompletion; return t; } /// Sets an ID for the tween (), which can then be used as a filter with DOTween's static methods. /// The ID to assign to this tween. Can be an int, a string, an object or anything else. public static T SetId(this T t, object objectId) where T : Tween { if (t == null || !t.active) return t; t.id = objectId; return t; } /// Sets a string ID for the tween (), which can then be used as a filter with DOTween's static methods. /// Filtering via string is 2X faster than using an object as an ID (using the alternate obejct overload) /// The string ID to assign to this tween. public static T SetId(this T t, string stringId) where T : Tween { if (t == null || !t.active) return t; t.stringId = stringId; return t; } /// Sets an int ID for the tween (), which can then be used as a filter with DOTween's static methods. /// Filtering via int is 4X faster than via object, 2X faster than via string (using the alternate object/string overloads) /// The int ID to assign to this tween. public static T SetId(this T t, int intId) where T : Tween { if (t == null || !t.active) return t; t.intId = intId; return t; } /// Allows to link this tween to a GameObject /// so that it will be automatically killed when the GameObject is destroyed. /// Has no effect if the tween is added to a Sequence /// The link target (unrelated to the target set via SetTarget) public static T SetLink(this T t, GameObject gameObject) where T : Tween { if (t == null || !t.active || t.isSequenced || gameObject == null) return t; TweenManager.AddTweenLink(t, new TweenLink(gameObject, LinkBehaviour.KillOnDestroy)); return t; } /// Allows to link this tween to a GameObject and assign a behaviour depending on it. /// This will also automatically kill the tween when the GameObject is destroyed. /// Has no effect if the tween is added to a Sequence /// The link target (unrelated to the target set via SetTarget) /// The behaviour to use ( is always evaluated even if you choose another one) public static T SetLink(this T t, GameObject gameObject, LinkBehaviour behaviour) where T : Tween { if (t == null || !t.active || t.isSequenced || gameObject == null) return t; TweenManager.AddTweenLink(t, new TweenLink(gameObject, behaviour)); return t; } /// Sets the target for the tween, which can then be used as a filter with DOTween's static methods. /// IMPORTANT: use it with caution. If you just want to set an ID for the tween use SetId instead. /// When using shorcuts the shortcut target is already assigned as the tween's target, /// so using this method will overwrite it and prevent shortcut-operations like myTarget.DOPause from working correctly. /// The target to assign to this tween. Can be an int, a string, an object or anything else. public static T SetTarget(this T t, object target) where T : Tween { if (t == null || !t.active) return t; t.target = target; return t; } /// Sets the looping options for the tween. /// Has no effect if the tween has already started /// Number of cycles to play (-1 for infinite - will be converted to 1 in case the tween is nested in a Sequence) public static T SetLoops(this T t, int loops) where T : Tween { if (t == null || !t.active || t.creationLocked) return t; if (loops < -1) loops = -1; else if (loops == 0) loops = 1; t.loops = loops; // if (t.tweenType == TweenType.Tweener) t.fullDuration = loops > -1 ? t.duration * loops : Mathf.Infinity; // Mysteriously Unity doesn't like this form if (t.tweenType == TweenType.Tweener) { if (loops > -1) t.fullDuration = t.duration * loops; else t.fullDuration = Mathf.Infinity; } return t; } /// Sets the looping options for the tween. /// Has no effect if the tween has already started /// Number of cycles to play (-1 for infinite - will be converted to 1 in case the tween is nested in a Sequence) /// Loop behaviour type (default: LoopType.Restart) public static T SetLoops(this T t, int loops, LoopType loopType) where T : Tween { if (t == null || !t.active || t.creationLocked) return t; if (loops < -1) loops = -1; else if (loops == 0) loops = 1; t.loops = loops; t.loopType = loopType; // if (t.tweenType == TweenType.Tweener) t.fullDuration = loops > -1 ? t.duration * loops : Mathf.Infinity; if (t.tweenType == TweenType.Tweener) { if (loops > -1) t.fullDuration = t.duration * loops; else t.fullDuration = Mathf.Infinity; } return t; } /// Sets the ease of the tween. /// If applied to Sequences eases the whole sequence animation public static T SetEase(this T t, Ease ease) where T : Tween { if (t == null || !t.active) return t; t.easeType = ease; if (EaseManager.IsFlashEase(ease)) t.easeOvershootOrAmplitude = (int)t.easeOvershootOrAmplitude; t.customEase = null; return t; } /// Sets the ease of the tween. /// If applied to Sequences eases the whole sequence animation /// /// Eventual overshoot to use with Back or Flash ease (default is 1.70158 - 1 for Flash). /// In case of Flash ease it must be an intenger and sets the total number of flashes that will happen. /// Using an even number will complete the tween on the starting value, while an odd one will complete it on the end value. /// public static T SetEase(this T t, Ease ease, float overshoot) where T : Tween { if (t == null || !t.active) return t; t.easeType = ease; if (EaseManager.IsFlashEase(ease)) overshoot = (int)overshoot; t.easeOvershootOrAmplitude = overshoot; t.customEase = null; return t; } /// Sets the ease of the tween. /// If applied to Sequences eases the whole sequence animation /// Eventual amplitude to use with Elastic easeType or overshoot to use with Flash easeType (default is 1.70158 - 1 for Flash). /// In case of Flash ease it must be an integer and sets the total number of flashes that will happen. /// Using an even number will complete the tween on the starting value, while an odd one will complete it on the end value. /// /// Eventual period to use with Elastic or Flash easeType (default is 0). /// In case of Flash ease it indicates the power in time of the ease, and must be between -1 and 1. /// 0 is balanced, 1 weakens the ease with time, -1 starts the ease weakened and gives it power towards the end. /// public static T SetEase(this T t, Ease ease, float amplitude, float period) where T : Tween { if (t == null || !t.active) return t; t.easeType = ease; if (EaseManager.IsFlashEase(ease)) amplitude = (int)amplitude; t.easeOvershootOrAmplitude = amplitude; t.easePeriod = period; t.customEase = null; return t; } /// Sets the ease of the tween using an AnimationCurve. /// If applied to Sequences eases the whole sequence animation public static T SetEase(this T t, AnimationCurve animCurve) where T : Tween { if (t == null || !t.active) return t; t.easeType = Ease.INTERNAL_Custom; t.customEase = new EaseCurve(animCurve).Evaluate; return t; } /// Sets the ease of the tween using a custom ease function (which must return a value between 0 and 1). /// If applied to Sequences eases the whole sequence animation public static T SetEase(this T t, EaseFunction customEase) where T : Tween { if (t == null || !t.active) return t; t.easeType = Ease.INTERNAL_Custom; t.customEase = customEase; return t; } /// Allows the tween to be recycled after being killed. public static T SetRecyclable(this T t) where T : Tween { if (t == null || !t.active) return t; t.isRecyclable = true; return t; } /// Sets the recycling behaviour for the tween. /// If TRUE the tween will be recycled after being killed, otherwise it will be destroyed. public static T SetRecyclable(this T t, bool recyclable) where T : Tween { if (t == null || !t.active) return t; t.isRecyclable = recyclable; return t; } /// Sets the update type to UpdateType.Normal and lets you choose if it should be independent from Unity's Time.timeScale /// If TRUE the tween will ignore Unity's Time.timeScale public static T SetUpdate(this T t, bool isIndependentUpdate) where T : Tween { if (t == null || !t.active) return t; TweenManager.SetUpdateType(t, DOTween.defaultUpdateType, isIndependentUpdate); return t; } /// Sets the type of update for the tween /// The type of update (defalt: UpdateType.Normal) public static T SetUpdate(this T t, UpdateType updateType) where T : Tween { if (t == null || !t.active) return t; TweenManager.SetUpdateType(t, updateType, DOTween.defaultTimeScaleIndependent); return t; } /// Sets the type of update for the tween and lets you choose if it should be independent from Unity's Time.timeScale /// The type of update /// If TRUE the tween will ignore Unity's Time.timeScale public static T SetUpdate(this T t, UpdateType updateType, bool isIndependentUpdate) where T : Tween { if (t == null || !t.active) return t; TweenManager.SetUpdateType(t, updateType, isIndependentUpdate); return t; } /// Sets the onStart callback for the tween, clearing any previous onStart callback that was set. /// Called the first time the tween is set in a playing state, after any eventual delay public static T OnStart(this T t, TweenCallback action) where T : Tween { if (t == null || !t.active) return t; t.onStart = action; return t; } /// Sets the onPlay callback for the tween, clearing any previous onPlay callback that was set. /// Called when the tween is set in a playing state, after any eventual delay. /// Also called each time the tween resumes playing from a paused state public static T OnPlay(this T t, TweenCallback action) where T : Tween { if (t == null || !t.active) return t; t.onPlay = action; return t; } /// Sets the onPause callback for the tween, clearing any previous onPause callback that was set. /// Called when the tween state changes from playing to paused. /// If the tween has autoKill set to FALSE, this is called also when the tween reaches completion. public static T OnPause(this T t, TweenCallback action) where T : Tween { if (t == null || !t.active) return t; t.onPause = action; return t; } /// Sets the onRewind callback for the tween, clearing any previous onRewind callback that was set. /// Called when the tween is rewinded, /// either by calling Rewind or by reaching the start position while playing backwards. /// Rewinding a tween that is already rewinded will not fire this callback public static T OnRewind(this T t, TweenCallback action) where T : Tween { if (t == null || !t.active) return t; t.onRewind = action; return t; } /// Sets the onUpdate callback for the tween, clearing any previous onUpdate callback that was set. /// Called each time the tween updates public static T OnUpdate(this T t, TweenCallback action) where T : Tween { if (t == null || !t.active) return t; t.onUpdate = action; return t; } /// Sets the onStepComplete callback for the tween, clearing any previous onStepComplete callback that was set. /// Called the moment the tween completes one loop cycle, even when going backwards public static T OnStepComplete(this T t, TweenCallback action) where T : Tween { if (t == null || !t.active) return t; t.onStepComplete = action; return t; } /// Sets the onComplete callback for the tween, clearing any previous onComplete callback that was set. /// Called the moment the tween reaches its final forward position, loops included public static T OnComplete(this T t, TweenCallback action) where T : Tween { if (t == null || !t.active) return t; t.onComplete = action; return t; } /// Sets the onKill callback for the tween, clearing any previous onKill callback that was set. /// Called the moment the tween is killed public static T OnKill(this T t, TweenCallback action) where T : Tween { if (t == null || !t.active) return t; t.onKill = action; return t; } /// Sets the onWaypointChange callback for the tween, clearing any previous onWaypointChange callback that was set. /// Called when a path tween's current waypoint changes public static T OnWaypointChange(this T t, TweenCallback action) where T : Tween { if (t == null || !t.active) return t; t.onWaypointChange = action; return t; } /// Sets the parameters of the tween (id, ease, loops, delay, timeScale, callbacks, etc) as the parameters of the given one. /// Doesn't copy specific SetOptions settings: those will need to be applied manually each time. /// Has no effect if the tween has already started. /// NOTE: the tween's target will not be changed /// Tween from which to copy the parameters public static T SetAs(this T t, Tween asTween) where T : Tween { if (t == null || !t.active || t.creationLocked) return t; // t.isFrom = asTween.isFrom; // t.target = asTween.target; t.timeScale = asTween.timeScale; t.isBackwards = asTween.isBackwards; TweenManager.SetUpdateType(t, asTween.updateType, asTween.isIndependentUpdate); t.id = asTween.id; t.onStart = asTween.onStart; t.onPlay = asTween.onPlay; t.onRewind = asTween.onRewind; t.onUpdate = asTween.onUpdate; t.onStepComplete = asTween.onStepComplete; t.onComplete = asTween.onComplete; t.onKill = asTween.onKill; t.onWaypointChange = asTween.onWaypointChange; t.isRecyclable = asTween.isRecyclable; t.isSpeedBased = asTween.isSpeedBased; t.autoKill = asTween.autoKill; t.loops = asTween.loops; t.loopType = asTween.loopType; if (t.tweenType == TweenType.Tweener) { if (t.loops > -1) t.fullDuration = t.duration * t.loops; else t.fullDuration = Mathf.Infinity; } t.delay = asTween.delay; t.delayComplete = t.delay <= 0; t.isRelative = asTween.isRelative; t.easeType = asTween.easeType; t.customEase = asTween.customEase; t.easeOvershootOrAmplitude = asTween.easeOvershootOrAmplitude; t.easePeriod = asTween.easePeriod; return t; } /// Sets the parameters of the tween (id, ease, loops, delay, timeScale, callbacks, etc) as the parameters of the given TweenParams. /// Has no effect if the tween has already started. /// TweenParams from which to copy the parameters public static T SetAs(this T t, TweenParams tweenParams) where T : Tween { if (t == null || !t.active || t.creationLocked) return t; TweenManager.SetUpdateType(t, tweenParams.updateType, tweenParams.isIndependentUpdate); t.id = tweenParams.id; t.onStart = tweenParams.onStart; t.onPlay = tweenParams.onPlay; t.onRewind = tweenParams.onRewind; t.onUpdate = tweenParams.onUpdate; t.onStepComplete = tweenParams.onStepComplete; t.onComplete = tweenParams.onComplete; t.onKill = tweenParams.onKill; t.onWaypointChange = tweenParams.onWaypointChange; t.isRecyclable = tweenParams.isRecyclable; t.isSpeedBased = tweenParams.isSpeedBased; t.autoKill = tweenParams.autoKill; t.loops = tweenParams.loops; t.loopType = tweenParams.loopType; if (t.tweenType == TweenType.Tweener) { if (t.loops > -1) t.fullDuration = t.duration * t.loops; else t.fullDuration = Mathf.Infinity; } t.delay = tweenParams.delay; t.delayComplete = t.delay <= 0; t.isRelative = tweenParams.isRelative; if (tweenParams.easeType == Ease.Unset) { if (t.tweenType == TweenType.Sequence) t.easeType = Ease.Linear; else t.easeType = DOTween.defaultEaseType; // t.easeType = t.tweenType == TweenType.Sequence ? Ease.Linear : DOTween.defaultEaseType; // Doesn't work w webplayer (why?) } else t.easeType = tweenParams.easeType; t.customEase = tweenParams.customEase; t.easeOvershootOrAmplitude = tweenParams.easeOvershootOrAmplitude; t.easePeriod = tweenParams.easePeriod; return t; } #endregion #region Sequences-only /// Adds the given tween to the end of the Sequence. /// Has no effect if the Sequence has already started /// The tween to append public static Sequence Append(this Sequence s, Tween t) { if (s == null || !s.active || s.creationLocked) return s; if (t == null || !t.active || t.isSequenced) return s; Sequence.DoInsert(s, t, s.duration); return s; } /// Adds the given tween to the beginning of the Sequence, pushing forward the other nested content. /// Has no effect if the Sequence has already started /// The tween to prepend public static Sequence Prepend(this Sequence s, Tween t) { if (s == null || !s.active || s.creationLocked) return s; if (t == null || !t.active || t.isSequenced) return s; Sequence.DoPrepend(s, t); return s; } /// Inserts the given tween at the same time position of the last tween, callback or intervale added to the Sequence. /// Note that, in case of a Join after an interval, the insertion time will be the time where the interval starts, not where it finishes. /// Has no effect if the Sequence has already started public static Sequence Join(this Sequence s, Tween t) { if (s == null || !s.active || s.creationLocked) return s; if (t == null || !t.active || t.isSequenced) return s; Sequence.DoInsert(s, t, s.lastTweenInsertTime); return s; } /// Inserts the given tween at the given time position in the Sequence, /// automatically adding an interval if needed. /// Has no effect if the Sequence has already started /// The time position where the tween will be placed /// The tween to insert public static Sequence Insert(this Sequence s, float atPosition, Tween t) { if (s == null || !s.active || s.creationLocked) return s; if (t == null || !t.active || t.isSequenced) return s; Sequence.DoInsert(s, t, atPosition); return s; } /// Adds the given interval to the end of the Sequence. /// Has no effect if the Sequence has already started /// The interval duration public static Sequence AppendInterval(this Sequence s, float interval) { if (s == null || !s.active || s.creationLocked) return s; Sequence.DoAppendInterval(s, interval); return s; } /// Adds the given interval to the beginning of the Sequence, pushing forward the other nested content. /// Has no effect if the Sequence has already started /// The interval duration public static Sequence PrependInterval(this Sequence s, float interval) { if (s == null || !s.active || s.creationLocked) return s; Sequence.DoPrependInterval(s, interval); return s; } /// Adds the given callback to the end of the Sequence. /// Has no effect if the Sequence has already started /// The callback to append public static Sequence AppendCallback(this Sequence s, TweenCallback callback) { if (s == null || !s.active || s.creationLocked) return s; if (callback == null) return s; Sequence.DoInsertCallback(s, callback, s.duration); return s; } /// Adds the given callback to the beginning of the Sequence, pushing forward the other nested content. /// Has no effect if the Sequence has already started /// The callback to prepend public static Sequence PrependCallback(this Sequence s, TweenCallback callback) { if (s == null || !s.active || s.creationLocked) return s; if (callback == null) return s; Sequence.DoInsertCallback(s, callback, 0); return s; } /// Inserts the given callback at the given time position in the Sequence, /// automatically adding an interval if needed. /// Has no effect if the Sequence has already started /// The time position where the callback will be placed /// The callback to insert public static Sequence InsertCallback(this Sequence s, float atPosition, TweenCallback callback) { if (s == null || !s.active || s.creationLocked) return s; if (callback == null) return s; Sequence.DoInsertCallback(s, callback, atPosition); return s; } #endregion #region Tweeners-only #region FROM /// Changes a TO tween into a FROM tween: sets the current target's position as the tween's endValue /// then immediately sends the target to the previously set endValue. public static T From(this T t) where T : Tweener { if (t == null || !t.active || t.creationLocked || !t.isFromAllowed) return t; t.isFrom = true; t.SetFrom(false); return t; } /// Changes a TO tween into a FROM tween: sets the current target's position as the tween's endValue /// then immediately sends the target to the previously set endValue. /// If TRUE the FROM value will be calculated as relative to the current one public static T From(this T t, bool isRelative) where T : Tweener { if (t == null || !t.active || t.creationLocked || !t.isFromAllowed) return t; t.isFrom = true; if (!isRelative) t.SetFrom(false); else t.SetFrom(!t.isBlendable); return t; } /// Changes a TO tween into a FROM tween: sets the tween's starting value to the given one /// and eventually sets the tween's target to that value immediately. /// Value to start from /// If TRUE sets the target to from value immediately, otherwise waits for the tween to start public static TweenerCore From(this TweenerCore t, T2 fromValue, bool setImmediately = true) where TPlugOptions : struct, IPlugOptions { if (t == null || !t.active || t.creationLocked || !t.isFromAllowed) return t; t.isFrom = true; t.SetFrom(fromValue, setImmediately); return t; } #region FROM Extra Overloads /// Changes a TO tween into a FROM tween: sets the tween's starting value to the given one /// and eventually sets the tween's target to that value immediately. /// Alpha value to start from (in case of Fade tweens) /// If TRUE sets the target to from value immediately, otherwise waits for the tween to start public static TweenerCore From(this TweenerCore t, float fromAlphaValue, bool setImmediately = true) { if (t == null || !t.active || t.creationLocked || !t.isFromAllowed) return t; t.isFrom = true; t.SetFrom(new Color(0,0,0,fromAlphaValue), setImmediately); return t; } /// Changes a TO tween into a FROM tween: sets the tween's starting value to the given one /// and eventually sets the tween's target to that value immediately. /// Value to start from (in case of Vector tweens that act on a single coordinate or scale tweens) /// If TRUE sets the target to from value immediately, otherwise waits for the tween to start public static TweenerCore From(this TweenerCore t, float fromValue, bool setImmediately = true) { if (t == null || !t.active || t.creationLocked || !t.isFromAllowed) return t; t.isFrom = true; t.SetFrom(new Vector3(fromValue, fromValue, fromValue), setImmediately); return t; } #endregion #endregion /// Sets a delayed startup for the tween. /// Has no effect on Sequences or if the tween has already started public static T SetDelay(this T t, float delay) where T : Tween { if (t == null || !t.active || t.creationLocked) return t; if (t.tweenType == TweenType.Sequence) { (t as Sequence).PrependInterval(delay); } else { t.delay = delay; t.delayComplete = delay <= 0; } return t; } /// Sets the tween as relative /// (the endValue will be calculated as startValue + endValue instead than being used directly). /// Has no effect on Sequences or if the tween has already started public static T SetRelative(this T t) where T : Tween { if (t == null || !t.active || t.creationLocked || t.isFrom || t.isBlendable) return t; t.isRelative = true; return t; } /// If isRelative is TRUE sets the tween as relative /// (the endValue will be calculated as startValue + endValue instead than being used directly). /// Has no effect on Sequences or if the tween has already started public static T SetRelative(this T t, bool isRelative) where T : Tween { if (t == null || !t.active || t.creationLocked || t.isFrom || t.isBlendable) return t; t.isRelative = isRelative; return t; } /// If isSpeedBased is TRUE sets the tween as speed based /// (the duration will represent the number of units the tween moves x second). /// Has no effect on Sequences, nested tweens, or if the tween has already started public static T SetSpeedBased(this T t) where T : Tween { if (t == null || !t.active || t.creationLocked) return t; t.isSpeedBased = true; return t; } /// If isSpeedBased is TRUE sets the tween as speed based /// (the duration will represent the number of units the tween moves x second). /// Has no effect on Sequences, nested tweens, or if the tween has already started public static T SetSpeedBased(this T t, bool isSpeedBased) where T : Tween { if (t == null || !t.active || t.creationLocked) return t; t.isSpeedBased = isSpeedBased; return t; } #endregion #region Tweeners Extra Options /// Options for float tweens /// If TRUE the tween will smoothly snap all values to integers public static Tweener SetOptions(this TweenerCore t, bool snapping) { if (t == null || !t.active) return t; t.plugOptions.snapping = snapping; return t; } /// Options for Vector2 tweens /// If TRUE the tween will smoothly snap all values to integers public static Tweener SetOptions(this TweenerCore t, bool snapping) { if (t == null || !t.active) return t; t.plugOptions.snapping = snapping; return t; } /// Options for Vector2 tweens /// Selecting an axis will tween the vector only on that axis, leaving the others untouched /// If TRUE the tween will smoothly snap all values to integers public static Tweener SetOptions(this TweenerCore t, AxisConstraint axisConstraint, bool snapping = false) { if (t == null || !t.active) return t; t.plugOptions.axisConstraint = axisConstraint; t.plugOptions.snapping = snapping; return t; } /// Options for Vector3 tweens /// If TRUE the tween will smoothly snap all values to integers public static Tweener SetOptions(this TweenerCore t, bool snapping) { if (t == null || !t.active) return t; t.plugOptions.snapping = snapping; return t; } /// Options for Vector3 tweens /// Selecting an axis will tween the vector only on that axis, leaving the others untouched /// If TRUE the tween will smoothly snap all values to integers public static Tweener SetOptions(this TweenerCore t, AxisConstraint axisConstraint, bool snapping = false) { if (t == null || !t.active) return t; t.plugOptions.axisConstraint = axisConstraint; t.plugOptions.snapping = snapping; return t; } /// Options for Vector4 tweens /// If TRUE the tween will smoothly snap all values to integers public static Tweener SetOptions(this TweenerCore t, bool snapping) { if (t == null || !t.active) return t; t.plugOptions.snapping = snapping; return t; } /// Options for Vector4 tweens /// Selecting an axis will tween the vector only on that axis, leaving the others untouched /// If TRUE the tween will smoothly snap all values to integers public static Tweener SetOptions(this TweenerCore t, AxisConstraint axisConstraint, bool snapping = false) { if (t == null || !t.active) return t; t.plugOptions.axisConstraint = axisConstraint; t.plugOptions.snapping = snapping; return t; } /// Options for Quaternion tweens /// If TRUE (default) the rotation will take the shortest route, and will not rotate more than 360°. /// If FALSE the rotation will be fully accounted. Is always FALSE if the tween is set as relative public static Tweener SetOptions(this TweenerCore t, bool useShortest360Route = true) { if (t == null || !t.active) return t; t.plugOptions.rotateMode = useShortest360Route ? RotateMode.Fast : RotateMode.FastBeyond360; return t; } /// Options for Color tweens /// If TRUE only the alpha value of the color will be tweened public static Tweener SetOptions(this TweenerCore t, bool alphaOnly) { if (t == null || !t.active) return t; t.plugOptions.alphaOnly = alphaOnly; return t; } /// Options for Vector4 tweens /// If TRUE the tween will smoothly snap all values to integers public static Tweener SetOptions(this TweenerCore t, bool snapping) { if (t == null || !t.active) return t; t.plugOptions.snapping = snapping; return t; } /// Options for Vector4 tweens /// If TRUE, rich text will be interpreted correctly while animated, /// otherwise all tags will be considered as normal text /// The type of scramble to use, if any /// A string containing the characters to use for scrambling. /// Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters. /// Leave it to NULL to use default ones public static Tweener SetOptions(this TweenerCore t, bool richTextEnabled, ScrambleMode scrambleMode = ScrambleMode.None, string scrambleChars = null) { if (t == null || !t.active) return t; t.plugOptions.richTextEnabled = richTextEnabled; t.plugOptions.scrambleMode = scrambleMode; if (!string.IsNullOrEmpty(scrambleChars)) { if (scrambleChars.Length <= 1) scrambleChars += scrambleChars; t.plugOptions.scrambledChars = scrambleChars.ToCharArray(); t.plugOptions.scrambledChars.ScrambleChars(); } return t; } /// Options for Vector3Array tweens /// If TRUE the tween will smoothly snap all values to integers public static Tweener SetOptions(this TweenerCore t, bool snapping) { if (t == null || !t.active) return t; t.plugOptions.snapping = snapping; return t; } /// Options for Vector3Array tweens /// If TRUE the tween will smoothly snap all values to integers public static Tweener SetOptions(this TweenerCore t, AxisConstraint axisConstraint, bool snapping = false) { if (t == null || !t.active) return t; t.plugOptions.axisConstraint = axisConstraint; t.plugOptions.snapping = snapping; return t; } #region Path Options /// Options for Path tweens (created via the DOPath shortcut) /// The eventual movement axis to lock. You can input multiple axis if you separate them like this: /// AxisConstrain.X | AxisConstraint.Y /// The eventual rotation axis to lock. You can input multiple axis if you separate them like this: /// AxisConstrain.X | AxisConstraint.Y public static TweenerCore SetOptions( this TweenerCore t, AxisConstraint lockPosition, AxisConstraint lockRotation = AxisConstraint.None ) { return SetOptions(t, false, lockPosition, lockRotation); } /// Options for Path tweens (created via the DOPath shortcut) /// If TRUE the path will be automatically closed /// The eventual movement axis to lock. You can input multiple axis if you separate them like this: /// AxisConstrain.X | AxisConstraint.Y /// The eventual rotation axis to lock. You can input multiple axis if you separate them like this: /// AxisConstrain.X | AxisConstraint.Y public static TweenerCore SetOptions( this TweenerCore t, bool closePath, AxisConstraint lockPosition = AxisConstraint.None, AxisConstraint lockRotation = AxisConstraint.None ) { if (t == null || !t.active) return t; t.plugOptions.isClosedPath = closePath; t.plugOptions.lockPositionAxis = lockPosition; t.plugOptions.lockRotationAxis = lockRotation; return t; } /// Additional LookAt options for Path tweens (created via the DOPath shortcut). /// Orients the target towards the given position. /// Must be chained directly to the tween creation method or to a SetOptions /// The position to look at /// The eventual direction to consider as "forward". /// If left to NULL defaults to the regular forward side of the transform /// The vector that defines in which direction up is (default: Vector3.up) public static TweenerCore SetLookAt( this TweenerCore t, Vector3 lookAtPosition, Vector3? forwardDirection = null, Vector3? up = null ) { if (t == null || !t.active) return t; t.plugOptions.orientType = OrientType.LookAtPosition; t.plugOptions.lookAtPosition = lookAtPosition; SetPathForwardDirection(t, forwardDirection, up); return t; } /// Additional LookAt options for Path tweens (created via the DOPath shortcut). /// Orients the target towards another transform. /// Must be chained directly to the tween creation method or to a SetOptions /// The transform to look at /// The eventual direction to consider as "forward". /// If left to NULL defaults to the regular forward side of the transform /// The vector that defines in which direction up is (default: Vector3.up) public static TweenerCore SetLookAt( this TweenerCore t, Transform lookAtTransform, Vector3? forwardDirection = null, Vector3? up = null ) { if (t == null || !t.active) return t; t.plugOptions.orientType = OrientType.LookAtTransform; t.plugOptions.lookAtTransform = lookAtTransform; SetPathForwardDirection(t, forwardDirection, up); return t; } /// Additional LookAt options for Path tweens (created via the DOPath shortcut). /// Orients the target to the path, with the given lookAhead. /// Must be chained directly to the tween creation method or to a SetOptions /// The percentage of lookAhead to use (0 to 1) /// The eventual direction to consider as "forward". /// If left to NULL defaults to the regular forward side of the transform /// The vector that defines in which direction up is (default: Vector3.up) public static TweenerCore SetLookAt( this TweenerCore t, float lookAhead, Vector3? forwardDirection = null, Vector3? up = null ) { if (t == null || !t.active) return t; t.plugOptions.orientType = OrientType.ToPath; if (lookAhead < PathPlugin.MinLookAhead) lookAhead = PathPlugin.MinLookAhead; t.plugOptions.lookAhead = lookAhead; SetPathForwardDirection(t, forwardDirection, up); return t; } static void SetPathForwardDirection(this TweenerCore t, Vector3? forwardDirection = null, Vector3? up = null) { if (t == null || !t.active) return; t.plugOptions.hasCustomForwardDirection = forwardDirection != null && forwardDirection != Vector3.zero || up != null && up != Vector3.zero; if (t.plugOptions.hasCustomForwardDirection) { if (forwardDirection == Vector3.zero) forwardDirection = Vector3.forward; t.plugOptions.forward = Quaternion.LookRotation( forwardDirection == null ? Vector3.forward : (Vector3)forwardDirection, up == null ? Vector3.up : (Vector3)up ); } } #endregion #endregion } }