Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add showErrorLog flag #160

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _DOTween.Assembly/DOTween/Core/DOTweenSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class DOTweenSettings : ScriptableObject
public const string AssetName = "DOTweenSettings";

public bool useSafeMode = true;
public bool showErrorLog = true;
public float timeScale = 1;
public bool useSmoothDeltaTime;
public float maxSmoothUnscaledTime = 0.15f; // Used if useSmoothDeltaTime is TRUE
Expand Down
11 changes: 9 additions & 2 deletions _DOTween.Assembly/DOTween/Core/TweenerCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,22 @@ internal override bool Startup()
internal override bool ApplyTween(float prevPosition, int prevCompletedLoops, int newCompletedSteps, bool useInversePosition, UpdateMode updateMode, UpdateNotice updateNotice)
{
float updatePosition = useInversePosition ? duration - position : position;

if (DOTween.useSafeMode) {
try {
tweenPlugin.EvaluateAndApply(plugOptions, this, isRelative, getter, setter, updatePosition, startValue, changeValue, duration, useInversePosition, updateNotice);
} catch {
} catch (Exception e) {
if(DOTween.showErrorLog) Debugger.LogWarning(e);
// Target/field doesn't exist anymore: kill tween
return true;
}
} else {
tweenPlugin.EvaluateAndApply(plugOptions, this, isRelative, getter, setter, updatePosition, startValue, changeValue, duration, useInversePosition, updateNotice);
try {
tweenPlugin.EvaluateAndApply(plugOptions, this, isRelative, getter, setter, updatePosition, startValue, changeValue, duration, useInversePosition, updateNotice);
} catch (Exception e) {
if(DOTween.showErrorLog) Debugger.LogWarning(e);
throw e;
}
}
return false;
}
Expand Down
9 changes: 9 additions & 0 deletions _DOTween.Assembly/DOTween/DOTween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ public class DOTween
///////////////////////////////////////////////
// Options ////////////////////////////////////


/// <summary>If TRUE (default) makes tweens slightly slower but safer, automatically taking care of a series of things
/// (like targets becoming null while a tween is playing).
/// <para>Default: TRUE</para></summary>
public static bool useSafeMode = true;

/// <summary>If TRUE (default) show all exceptions occurred in tweening to log console.
/// Showing exception costs a bit.If you care about performance, make showErrorLog=false in production.
/// </summary>
public static bool showErrorLog = true;


/// <summary>If TRUE you will get a DOTween report when exiting play mode (only in the Editor).
/// Useful to know how many max Tweeners and Sequences you reached and optimize your final project accordingly.
/// Beware, this will slightly slow down your tweens while inside Unity Editor.
Expand Down Expand Up @@ -177,6 +185,7 @@ static IDOTweenInit Init(DOTweenSettings settings, bool? recycleAllByDefault, bo
if (useSafeMode == null) DOTween.useSafeMode = settings.useSafeMode;
if (logBehaviour == null) DOTween.logBehaviour = settings.logBehaviour;
if (recycleAllByDefault == null) DOTween.defaultRecyclable = settings.defaultRecyclable;
DOTween.showErrorLog = settings.showErrorLog;
DOTween.timeScale = settings.timeScale;
DOTween.useSmoothDeltaTime = settings.useSmoothDeltaTime;
DOTween.maxSmoothUnscaledTime = settings.maxSmoothUnscaledTime;
Expand Down
25 changes: 21 additions & 4 deletions _DOTween.Assembly/DOTween/Tweener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,23 @@ internal static bool DoStartup<T1, T2, TPlugOptions>(TweenerCore<T1, T2, TPlugOp
}

if (!t.hasManuallySetStartValue) {

// Take start value from current target value
if (DOTween.useSafeMode) {
try {
t.startValue = t.tweenPlugin.ConvertToStartValue(t, t.getter());
} catch {
} catch (System.Exception e) {
if(DOTween.showErrorLog) Debugger.LogError(e);
return false; // Target/field doesn't exist: kill tween
}
} else t.startValue = t.tweenPlugin.ConvertToStartValue(t, t.getter());
} else {
try {
t.startValue = t.tweenPlugin.ConvertToStartValue(t, t.getter());
} catch (System.Exception e) {
if(DOTween.showErrorLog) Debugger.LogError(e);
throw e;
}
}
}

if (t.isRelative) t.tweenPlugin.SetRelativeEndValue(t);
Expand Down Expand Up @@ -192,12 +201,20 @@ internal static Tweener DoChangeEndValue<T1, T2, TPlugOptions>(
if (DOTween.useSafeMode) {
try {
t.startValue = t.tweenPlugin.ConvertToStartValue(t, t.getter());
} catch {
} catch (System.Exception e) {
if (DOTween.showErrorLog) Debugger.LogWarning(e);
// Target/field doesn't exist: kill tween
TweenManager.Despawn(t);
return null;
}
} else t.startValue = t.tweenPlugin.ConvertToStartValue(t, t.getter());
} else {
try {
t.startValue = t.tweenPlugin.ConvertToStartValue(t, t.getter());
} catch (System.Exception e) {
if(DOTween.showErrorLog) Debugger.LogWarning(e);
throw e;
}
}
}
t.tweenPlugin.SetChangeValue(t);
}
Expand Down