Skip to content

Commit

Permalink
-update: prime tween 1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
aprius committed Dec 3, 2023
1 parent a2dc4e2 commit 4a99705
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 29 deletions.
16 changes: 3 additions & 13 deletions Assets/Heart/Modules/PrimeTween/Runtime/Internal/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static string buildWarningCanBeDisabledMessage(string settingName) {
internal const string endDelayTooltip = "Delays the completion of a tween.\n\n" +
"For example, can be used to add the delay between cycles.\n\n" +
"Or can be used to postpone the execution of the onComplete callback.";
internal const string infiniteTweenInSequenceError = "It's not allowed to have infinite tweens (cycles == -1) in a sequence. If you want the sequence to repeat forever, " + nameof(Sequence.Create) + "(-1) on the parent sequence instead."; // todoo error instead of exception?
internal const string infiniteTweenInSequenceError = "It's not allowed to have infinite tweens (cycles == -1) in a sequence. If you want the sequence to repeat forever, " + nameof(Sequence.SetRemainingCycles) + "(-1) on the parent sequence instead."; // todoo error instead of exception?
internal const string customTweensDontSupportStartFromCurrentWarning =
"Custom tweens don't support the '" + nameof(T.startFromCurrent) + "' because they don't know the current value of animated property.\n" +
"This means that the animated value will be changed abruptly if a new tween is started mid-way.\n" +
Expand Down Expand Up @@ -53,17 +53,7 @@ internal static bool warnNoInstance {
}
}

internal static bool noInstance => PrimeTweenManager.Instance == null;

internal static bool isEditMode {
get {
try {
return !UnityEditor.EditorApplication.isPlaying;
} catch {
return true;
}
}
}
#endif // UNITY_EDITOR
internal static bool noInstance => ReferenceEquals(null, PrimeTweenManager.Instance);
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ internal class PrimeTweenManager : MonoBehaviour {
[HideInInspector]
internal int lastId;
internal Ease defaultEase = Ease.OutQuad;
internal const Ease defaultShakeEase = Ease.OutSine;
internal const Ease defaultShakeEase = Ease.OutSine; // todo to OutQuad for performance
internal bool warnTweenOnDisabledTarget = true;
internal bool warnZeroDuration = true;
internal bool warnStructBoxingAllocationInCoroutine = true;
internal bool warnBenchmarkWithAsserts = true;
internal bool validateCustomCurves = true;
internal bool warnEndValueEqualsCurrent = true;
int processedCount;
internal int updateDepth;
internal static readonly object dummyTarget = new object();
Expand Down Expand Up @@ -69,10 +70,16 @@ void init() {

const string manualInstanceCreationIsNotAllowedMessage = "Please don't create the " + nameof(PrimeTweenManager) + " instance manually.";
void Awake() => Assert.IsNull(Instance, manualInstanceCreationIsNotAllowedMessage);

#if UNITY_EDITOR
[InitializeOnLoadMethod]
static void iniOnLoad() {
EditorApplication.playModeStateChanged += state => {
if (state == PlayModeStateChange.EnteredEditMode) {
Instance = null;
customInitialCapacity = -1;
}
};
if (!isHotReload) {
return;
}
Expand Down Expand Up @@ -134,10 +141,6 @@ void Start() {
Assert.AreEqual(Instance, this, manualInstanceCreationIsNotAllowedMessage);
}

void OnDestroy() {
customInitialCapacity = -1;
}

/// <summary>
/// The most common tween lifecycle:
/// 1. User's script creates a tween in Update() in frame N.
Expand Down Expand Up @@ -412,7 +415,7 @@ int processAll_internal([CanBeNull] object onTarget, [NotNull] Predicate<Reusabl
}
return numProcessed;
}

internal void SetTweensCapacity(int capacity) {
var runningTweens = tweensCount;
if (capacity < runningTweens) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ void ReportOnValueChange(float _easedInterpolationFactor) {
if (startFromCurrent) {
startFromCurrent = false;
startValue = Tween.tryGetStartValueFromOtherShake(this) ?? getter(this);
if (startValue.Vector4Val == endValue.Vector4Val && PrimeTweenManager.Instance.warnEndValueEqualsCurrent) {
Debug.LogWarning($"Tween's 'endValue' equals to the current animated value: {startValue.Vector4Val}, tween: {GetDescription()}.\n" +
$"{Constants.buildWarningCanBeDisabledMessage(nameof(PrimeTweenConfig.warnEndValueEqualsCurrent))}\n");
}
cacheDiff();
}
easedInterpolationFactor = _easedInterpolationFactor;
Expand Down
8 changes: 6 additions & 2 deletions Assets/Heart/Modules/PrimeTween/Runtime/PrimeTweenConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static partial class PrimeTweenConfig {
internal static PrimeTweenManager Instance {
get {
#if UNITY_EDITOR
Assert.IsFalse(Constants.isEditMode, Constants.editModeWarning);
Assert.IsFalse(Constants.noInstance, Constants.editModeWarning);
#endif
return PrimeTweenManager.Instance;
}
Expand Down Expand Up @@ -42,7 +42,7 @@ public static Ease defaultEase {
get => Instance.defaultEase;
set {
if (value == Ease.Custom || value == Ease.Default) {
Debug.LogError($"defaultEase can't be Ease.Custom or Ease.Default.");
Debug.LogError("defaultEase can't be Ease.Custom or Ease.Default.");
return;
}
Instance.defaultEase = value;
Expand Down Expand Up @@ -71,5 +71,9 @@ public static bool warnBenchmarkWithAsserts {
}

internal const bool defaultUseUnscaledTimeForShakes = false;

public static bool warnEndValueEqualsCurrent {
set => Instance.warnEndValueEqualsCurrent = value;
}
}
}
6 changes: 0 additions & 6 deletions Assets/Heart/Modules/PrimeTween/Runtime/Sequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ public static Sequence Create(Tween firstTween) {
}

Sequence(Tween rootTween) {
#if UNITY_EDITOR
if (Constants.noInstance) {
root = default;
return;
}
#endif
root = rootTween;
setSequence(rootTween);
Assert.IsTrue(isAlive);
Expand Down
3 changes: 2 additions & 1 deletion Assets/Heart/Modules/PrimeTween/Runtime/Tween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ void setElapsedTimeTotal(float value) {
value = 0f;
}
tween.SetElapsedTimeTotal(value);
if (value > durationTotal) {
// SetElapsedTimeTotal may complete the tween, so isAlive check is needed
if (isAlive && value > durationTotal) {
tween.elapsedTimeTotal = durationTotal;
}
}
Expand Down

0 comments on commit 4a99705

Please sign in to comment.