1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-20 09:16:02 +08:00

Added DOTweenEditorPreview static class with methods to run tweens in the editor (outside of Playmode)

This commit is contained in:
Demigiant 2018-08-17 14:09:24 +02:00
parent 85967318a0
commit a88db1b6b0
18 changed files with 150 additions and 3 deletions

View File

@ -4,6 +4,26 @@
<name>DOTweenEditor</name> <name>DOTweenEditor</name>
</assembly> </assembly>
<members> <members>
<member name="M:DG.DOTweenEditor.DOTweenEditorPreview.Start(System.Action)">
<summary>
Starts the update loop of tween in the editor. Has no effect during playMode.
</summary>
<param name="onPreviewUpdated">Eventual callback to call after every update</param>
</member>
<member name="M:DG.DOTweenEditor.DOTweenEditorPreview.Stop">
<summary>
Stops the update loop and clears any callback.
</summary>
</member>
<member name="M:DG.DOTweenEditor.DOTweenEditorPreview.PrepareTweenForPreview(DG.Tweening.Tween,System.Boolean,System.Boolean,System.Boolean)">
<summary>
Readies the tween for editor preview by setting its UpdateType to Manual plus eventual extra settings.
</summary>
<param name="t">The tween to ready</param>
<param name="clearCallbacks">If TRUE (recommended) removes all callbacks (OnComplete/Rewind/etc)</param>
<param name="preventAutoKill">If TRUE prevents the tween from being auto-killed at completion</param>
<param name="andPlay">If TRUE starts playing the tween immediately</param>
</member>
<member name="M:DG.DOTweenEditor.EditorUtils.SetEditorTexture(UnityEngine.Texture2D,UnityEngine.FilterMode,System.Int32)"> <member name="M:DG.DOTweenEditor.EditorUtils.SetEditorTexture(UnityEngine.Texture2D,UnityEngine.FilterMode,System.Int32)">
<summary> <summary>
Checks that the given editor texture use the correct import settings, Checks that the given editor texture use the correct import settings,

View File

@ -1,6 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: d3e15b806a8368742ba6f10e794d7b76 guid: d3e15b806a8368742ba6f10e794d7b76
timeCreated: 1533807483 timeCreated: 1534502369
licenseType: Pro licenseType: Pro
TextureImporter: TextureImporter:
fileIDToRecycleName: {} fileIDToRecycleName: {}

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.105"; // Last version before modules: 1.1.755 public static readonly string Version = "1.2.110"; // Last version before modules: 1.1.755
/////////////////////////////////////////////// ///////////////////////////////////////////////
// Options //////////////////////////////////// // Options ////////////////////////////////////

View File

@ -74,6 +74,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="DelayedCall.cs" /> <Compile Include="DelayedCall.cs" />
<Compile Include="DOTweenEditorPreview.cs" />
<Compile Include="MenuItems.cs" /> <Compile Include="MenuItems.cs" />
<Compile Include="UI\EditorGUIUtils.cs" /> <Compile Include="UI\EditorGUIUtils.cs" />
<Compile Include="EditorUtils.cs" /> <Compile Include="EditorUtils.cs" />

View File

@ -0,0 +1,106 @@
// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2018/08/17 12:18
// License Copyright (c) Daniele Giardini
// This work is subject to the terms at http://dotween.demigiant.com/license.php
using System;
using System.Collections.Generic;
using DG.Tweening;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
namespace DG.DOTweenEditor
{
public static class DOTweenEditorPreview
{
static bool _isPreviewing;
static double _previewTime;
static Action _onPreviewUpdated;
static GameObject _previewObj; // Used so it can be set dirty (otherwise canvas-only tweens won't refresh the view)
static DOTweenEditorPreview()
{
Clear();
}
#region Public Methods
/// <summary>
/// Starts the update loop of tween in the editor. Has no effect during playMode.
/// </summary>
/// <param name="onPreviewUpdated">Eventual callback to call after every update</param>
public static void Start(Action onPreviewUpdated = null)
{
if (_isPreviewing || EditorApplication.isPlayingOrWillChangePlaymode) return;
_isPreviewing = true;
_onPreviewUpdated = onPreviewUpdated;
_previewTime = EditorApplication.timeSinceStartup;
EditorApplication.update += PreviewUpdate;
_previewObj = new GameObject("-[ DOTween Preview ► ]-", typeof(PreviewComponent));
}
/// <summary>
/// Stops the update loop and clears any callback.
/// </summary>
public static void Stop()
{
_isPreviewing = false;
EditorApplication.update -= PreviewUpdate;
_onPreviewUpdated = null;
Clear();
}
/// <summary>
/// Readies the tween for editor preview by setting its UpdateType to Manual plus eventual extra settings.
/// </summary>
/// <param name="t">The tween to ready</param>
/// <param name="clearCallbacks">If TRUE (recommended) removes all callbacks (OnComplete/Rewind/etc)</param>
/// <param name="preventAutoKill">If TRUE prevents the tween from being auto-killed at completion</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)
{
t.SetUpdate(UpdateType.Manual);
if (preventAutoKill) t.SetAutoKill(false);
if (clearCallbacks) {
t.OnComplete(null)
.OnStart(null).OnPlay(null).OnPause(null).OnUpdate(null).OnWaypointChange(null)
.OnStepComplete(null).OnRewind(null).OnKill(null);
}
if (andPlay) t.Play();
}
#endregion
#region Methods
static void Clear()
{
_previewObj = null;
// Find and destroy any existing preview objects
PreviewComponent[] objs = Object.FindObjectsOfType<PreviewComponent>();
for (int i = 0; i < objs.Length; ++i) Object.DestroyImmediate(objs[i].gameObject);
}
static void PreviewUpdate()
{
double currTime = _previewTime;
_previewTime = EditorApplication.timeSinceStartup;
float elapsed = (float)(_previewTime - currTime);
DOTween.ManualUpdate(elapsed, elapsed);
if (_previewObj != null) EditorUtility.SetDirty(_previewObj);
if (_onPreviewUpdated != null) _onPreviewUpdated();
}
#endregion
// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
// ███ INTERNAL CLASSES ████████████████████████████████████████████████████████████████████████████████████████████████
// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
class PreviewComponent : MonoBehaviour {}
}
}

View File

@ -9,7 +9,7 @@ using UnityEngine;
namespace DG.DOTweenEditor namespace DG.DOTweenEditor
{ {
public static class MenuItems static class MenuItems
{ {
[MenuItem("GameObject/Demigiant/DOTween Manager", false, 20)] [MenuItem("GameObject/Demigiant/DOTween Manager", false, 20)]
static void CreateDOTweenComponent(MenuCommand menuCommand) static void CreateDOTweenComponent(MenuCommand menuCommand)

Binary file not shown.

View File

@ -4,6 +4,26 @@
<name>DOTweenEditor</name> <name>DOTweenEditor</name>
</assembly> </assembly>
<members> <members>
<member name="M:DG.DOTweenEditor.DOTweenEditorPreview.Start(System.Action)">
<summary>
Starts the update loop of tween in the editor. Has no effect during playMode.
</summary>
<param name="onPreviewUpdated">Eventual callback to call after every update</param>
</member>
<member name="M:DG.DOTweenEditor.DOTweenEditorPreview.Stop">
<summary>
Stops the update loop and clears any callback.
</summary>
</member>
<member name="M:DG.DOTweenEditor.DOTweenEditorPreview.PrepareTweenForPreview(DG.Tweening.Tween,System.Boolean,System.Boolean,System.Boolean)">
<summary>
Readies the tween for editor preview by setting its UpdateType to Manual plus eventual extra settings.
</summary>
<param name="t">The tween to ready</param>
<param name="clearCallbacks">If TRUE (recommended) removes all callbacks (OnComplete/Rewind/etc)</param>
<param name="preventAutoKill">If TRUE prevents the tween from being auto-killed at completion</param>
<param name="andPlay">If TRUE starts playing the tween immediately</param>
</member>
<member name="M:DG.DOTweenEditor.EditorUtils.SetEditorTexture(UnityEngine.Texture2D,UnityEngine.FilterMode,System.Int32)"> <member name="M:DG.DOTweenEditor.EditorUtils.SetEditorTexture(UnityEngine.Texture2D,UnityEngine.FilterMode,System.Int32)">
<summary> <summary>
Checks that the given editor texture use the correct import settings, Checks that the given editor texture use the correct import settings,