1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-21 01:36:05 +08:00

[DOTweenEditorPreview] Better reset management

This commit is contained in:
Demigiant 2018-12-16 14:54:51 +01:00
parent cdc4b68f53
commit af057d7fcc
16 changed files with 28 additions and 23 deletions

View File

@ -12,9 +12,9 @@
</member> </member>
<member name="M:DG.DOTweenEditor.DOTweenEditorPreview.Stop(System.Boolean)"> <member name="M:DG.DOTweenEditor.DOTweenEditorPreview.Stop(System.Boolean)">
<summary> <summary>
Stops the update loop and clears any callback. Stops the update loop and clears the onPreviewUpdated callback.
</summary> </summary>
<param name="reset">If TRUE also resets the tweened objects to their original state</param> <param name="resetTweenTargets">If TRUE also resets the tweened objects to their original state</param>
</member> </member>
<member name="M:DG.DOTweenEditor.DOTweenEditorPreview.PrepareTweenForPreview(DG.Tweening.Tween,System.Boolean,System.Boolean,System.Boolean)"> <member name="M:DG.DOTweenEditor.DOTweenEditorPreview.PrepareTweenForPreview(DG.Tweening.Tween,System.Boolean,System.Boolean,System.Boolean)">
<summary> <summary>

View File

@ -32,7 +32,7 @@ namespace DG.Tweening
public class DOTween public class DOTween
{ {
/// <summary>DOTween's version</summary> /// <summary>DOTween's version</summary>
public static readonly string Version = "1.2.140"; // Last version before modules: 1.1.755 public static readonly string Version = "1.2.145"; // Last version before modules: 1.1.755
/////////////////////////////////////////////// ///////////////////////////////////////////////
// Options //////////////////////////////////// // Options ////////////////////////////////////

View File

@ -18,11 +18,11 @@ namespace DG.DOTweenEditor
static double _previewTime; static double _previewTime;
static Action _onPreviewUpdated; static Action _onPreviewUpdated;
static GameObject _previewObj; // Used so it can be set dirty (otherwise canvas-only tweens won't refresh the view) static GameObject _previewObj; // Used so it can be set dirty (otherwise canvas-only tweens won't refresh the view)
static readonly List<Tween> _tweens = new List<Tween>(); static readonly List<Tween> _Tweens = new List<Tween>();
static DOTweenEditorPreview() static DOTweenEditorPreview()
{ {
Clear(); ClearPreviewObject();
} }
#region Public Methods #region Public Methods
@ -43,27 +43,26 @@ namespace DG.DOTweenEditor
} }
/// <summary> /// <summary>
/// Stops the update loop and clears any callback. /// Stops the update loop and clears the onPreviewUpdated callback.
/// </summary> /// </summary>
/// <param name="reset">If TRUE also resets the tweened objects to their original state</param> /// <param name="resetTweenTargets">If TRUE also resets the tweened objects to their original state</param>
public static void Stop(bool reset = false) public static void Stop(bool resetTweenTargets = false)
{ {
_isPreviewing = false; _isPreviewing = false;
EditorApplication.update -= PreviewUpdate; EditorApplication.update -= PreviewUpdate;
_onPreviewUpdated = null; _onPreviewUpdated = null;
if (reset) { if (resetTweenTargets) {
foreach (Tween t in _tweens) { foreach (Tween t in _Tweens) {
if (t != null && t.active) { try {
try { if (t.isFrom) t.Complete();
if (t.isFrom) t.Complete(); else t.Rewind();
else t.Rewind(); } catch {
} catch { // Ignore
// Just skip
}
} }
} }
} }
Clear(); ValidateTweens();
ClearPreviewObject();
} }
/// <summary> /// <summary>
@ -75,7 +74,7 @@ namespace DG.DOTweenEditor
/// <param name="andPlay">If TRUE starts playing the tween immediately</param> /// <param name="andPlay">If TRUE starts playing the tween immediately</param>
public static void PrepareTweenForPreview(Tween t, bool clearCallbacks = true, bool preventAutoKill = true, bool andPlay = true) public static void PrepareTweenForPreview(Tween t, bool clearCallbacks = true, bool preventAutoKill = true, bool andPlay = true)
{ {
_tweens.Add(t); _Tweens.Add(t);
t.SetUpdate(UpdateType.Manual); t.SetUpdate(UpdateType.Manual);
if (preventAutoKill) t.SetAutoKill(false); if (preventAutoKill) t.SetAutoKill(false);
if (clearCallbacks) { if (clearCallbacks) {
@ -90,10 +89,9 @@ namespace DG.DOTweenEditor
#region Methods #region Methods
static void Clear() static void ClearPreviewObject()
{ {
_previewObj = null; _previewObj = null;
_tweens.Clear();
// Find and destroy any existing preview objects // Find and destroy any existing preview objects
PreviewComponent[] objs = Object.FindObjectsOfType<PreviewComponent>(); PreviewComponent[] objs = Object.FindObjectsOfType<PreviewComponent>();
for (int i = 0; i < objs.Length; ++i) Object.DestroyImmediate(objs[i].gameObject); for (int i = 0; i < objs.Length; ++i) Object.DestroyImmediate(objs[i].gameObject);
@ -111,6 +109,13 @@ namespace DG.DOTweenEditor
if (_onPreviewUpdated != null) _onPreviewUpdated(); if (_onPreviewUpdated != null) _onPreviewUpdated();
} }
static void ValidateTweens()
{
for (int i = _Tweens.Count - 1; i > -1; --i) {
if (_Tweens[i] == null || !_Tweens[i].active) _Tweens.RemoveAt(i);
}
}
#endregion #endregion
// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ // █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████

Binary file not shown.

View File

@ -12,9 +12,9 @@
</member> </member>
<member name="M:DG.DOTweenEditor.DOTweenEditorPreview.Stop(System.Boolean)"> <member name="M:DG.DOTweenEditor.DOTweenEditorPreview.Stop(System.Boolean)">
<summary> <summary>
Stops the update loop and clears any callback. Stops the update loop and clears the onPreviewUpdated callback.
</summary> </summary>
<param name="reset">If TRUE also resets the tweened objects to their original state</param> <param name="resetTweenTargets">If TRUE also resets the tweened objects to their original state</param>
</member> </member>
<member name="M:DG.DOTweenEditor.DOTweenEditorPreview.PrepareTweenForPreview(DG.Tweening.Tween,System.Boolean,System.Boolean,System.Boolean)"> <member name="M:DG.DOTweenEditor.DOTweenEditorPreview.PrepareTweenForPreview(DG.Tweening.Tween,System.Boolean,System.Boolean,System.Boolean)">
<summary> <summary>