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

Added option to add DOTweenComponent to the Hierarchy manually in editor mode

This commit is contained in:
Demigiant 2018-08-07 19:33:47 +02:00
parent 321780ba9b
commit 8931993c6b
20 changed files with 232 additions and 139 deletions

View File

@ -14,7 +14,12 @@ public class TempTests : BrainBase
public Transform target0;
public Transform target1;
IEnumerator Start()
void OnEnable()
{
this.StartCoroutine(CreateTweens());
}
IEnumerator CreateTweens()
{
Tween t0 = target0.DOBlendableLocalMoveBy(new Vector3(1, 2, 1), 2f);
Tween t1 = target1.DOBlendableLocalMoveBy(new Vector3(1, -2, 1), 2f);

View File

@ -31,13 +31,20 @@ namespace DG.Tweening.Core
void Awake()
{
if (DOTween.instance == null) DOTween.instance = this;
else {
Debugger.LogWarning("Duplicate DOTweenComponent instance found in scene: destroying it");
Destroy(this.gameObject);
return;
}
inspectorUpdater = 0;
_unscaledTime = Time.realtimeSinceStartup;
// Initialize DOTweenModuleUtils via Reflection
Type modules = Utils.GetLooseScriptType("DG.Tweening.DOTweenModuleUtils");
if (modules == null) {
Debug.LogError("DOTween ► Couldn't load Modules system");
Debugger.LogError("Couldn't load Modules system");
return;
}
MethodInfo mi = modules.GetMethod("Init", BindingFlags.Static | BindingFlags.Public);

View File

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

View File

@ -74,9 +74,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DelayedCall.cs" />
<Compile Include="MenuItems.cs" />
<Compile Include="UI\EditorGUIUtils.cs" />
<Compile Include="EditorUtils.cs" />
<Compile Include="UI\DOTweenInspector.cs" />
<Compile Include="UI\DOTweenComponentInspector.cs" />
<Compile Include="UI\DOTweenUtilityWindowModules.cs" />
<Compile Include="DOTweenProcessors.cs" />
<Compile Include="UI\DOTweenSettingsInspector.cs" />

View File

@ -0,0 +1,24 @@
// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2018/08/07 18:05
// License Copyright (c) Daniele Giardini
// This work is subject to the terms at http://dotween.demigiant.com/license.php
using DG.Tweening.Core;
using UnityEditor;
using UnityEngine;
namespace DG.DOTweenEditor
{
public static class MenuItems
{
[MenuItem("GameObject/Demigiant/DOTween Manager", false, 20)]
static void CreateDOTweenComponent(MenuCommand menuCommand)
{
GameObject go = new GameObject("[DOTween]");
go.AddComponent<DOTweenComponent>();
GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
Selection.activeObject = go;
}
}
}

View File

@ -0,0 +1,173 @@
// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2014/06/29 20:37
//
// License Copyright (c) Daniele Giardini.
// This work is subject to the terms at http://dotween.demigiant.com/license.php
using System.Text;
using DG.Tweening;
using DG.Tweening.Core;
using UnityEditor;
using UnityEngine;
namespace DG.DOTweenEditor.UI
{
[CustomEditor(typeof(DOTweenComponent))]
public class DOTweenComponentInspector : Editor
{
DOTweenSettings _settings;
string _title;
readonly StringBuilder _strBuilder = new StringBuilder();
bool _isRuntime;
Texture2D _headerImg;
#region Unity + GUI
void OnEnable()
{
_isRuntime = EditorApplication.isPlaying;
ConnectToSource(true);
_strBuilder.Remove(0, _strBuilder.Length);
_strBuilder.Append("DOTween v").Append(DOTween.Version);
if (TweenManager.isDebugBuild) _strBuilder.Append(" [Debug build]");
else _strBuilder.Append(" [Release build]");
if (EditorUtils.hasPro) _strBuilder.Append("\nDOTweenPro v").Append(EditorUtils.proVersion);
else _strBuilder.Append("\nDOTweenPro not installed");
_title = _strBuilder.ToString();
}
override public void OnInspectorGUI()
{
_isRuntime = EditorApplication.isPlaying;
ConnectToSource();
EditorGUIUtils.SetGUIStyles();
// Header img
GUILayout.Space(4);
GUILayout.BeginHorizontal();
Rect headeR = GUILayoutUtility.GetRect(0, 93, 18, 18);
GUI.DrawTexture(headeR, _headerImg, ScaleMode.ScaleToFit, true);
GUILayout.Label(_isRuntime ? "RUNTIME MODE" : "EDITOR MODE");
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
int totActiveTweens = TweenManager.totActiveTweens;
int totPlayingTweens = TweenManager.TotalPlayingTweens();
int totPausedTweens = totActiveTweens - totPlayingTweens;
int totActiveDefaultTweens = TweenManager.totActiveDefaultTweens;
int totActiveLateTweens = TweenManager.totActiveLateTweens;
GUILayout.Label(_title, TweenManager.isDebugBuild ? EditorGUIUtils.redLabelStyle : EditorGUIUtils.boldLabelStyle);
if (!_isRuntime) {
GUI.backgroundColor = new Color(0f, 0.31f, 0.48f);
GUI.contentColor = Color.white;
GUILayout.Label(
"This component is <b>added automatically</b> by DOTween at runtime." +
"\nAdding it yourself is <b>not recommended</b> unless you really know what you're doing:" +
" you'll have to be sure it's <b>never destroyed</b> and that it's present <b>in every scene</b>.",
EditorGUIUtils.infoboxStyle
);
GUI.backgroundColor = GUI.contentColor = GUI.contentColor = Color.white;
}
GUILayout.Space(6);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Documentation")) Application.OpenURL("http://dotween.demigiant.com/documentation.php");
if (GUILayout.Button("Check Updates")) Application.OpenURL("http://dotween.demigiant.com/download.php?v=" + DOTween.Version);
GUILayout.EndHorizontal();
if (_isRuntime) {
GUILayout.BeginHorizontal();
if (GUILayout.Button(_settings.showPlayingTweens ? "Hide Playing Tweens" : "Show Playing Tweens")) {
_settings.showPlayingTweens = !_settings.showPlayingTweens;
EditorUtility.SetDirty(_settings);
}
if (GUILayout.Button(_settings.showPausedTweens ? "Hide Paused Tweens" : "Show Paused Tweens")) {
_settings.showPausedTweens = !_settings.showPausedTweens;
EditorUtility.SetDirty(_settings);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Play all")) DOTween.PlayAll();
if (GUILayout.Button("Pause all")) DOTween.PauseAll();
if (GUILayout.Button("Kill all")) DOTween.KillAll();
GUILayout.EndHorizontal();
GUILayout.Space(8);
_strBuilder.Length = 0;
_strBuilder.Append("Active tweens: ").Append(totActiveTweens)
.Append(" (").Append(TweenManager.totActiveTweeners)
.Append("/").Append(TweenManager.totActiveSequences).Append(")")
.Append("\nDefault/Late tweens: ").Append(totActiveDefaultTweens)
.Append("/").Append(totActiveLateTweens)
.Append("\nPlaying tweens: ").Append(totPlayingTweens);
if (_settings.showPlayingTweens) {
foreach (Tween t in TweenManager._activeTweens) {
if (t != null && t.isPlaying) _strBuilder.Append("\n - [").Append(t.tweenType).Append("] ").Append(t.target);
}
}
_strBuilder.Append("\nPaused tweens: ").Append(totPausedTweens);
if (_settings.showPausedTweens) {
foreach (Tween t in TweenManager._activeTweens) {
if (t != null && !t.isPlaying) _strBuilder.Append("\n - [").Append(t.tweenType).Append("] ").Append(t.target);
}
}
_strBuilder.Append("\nPooled tweens: ").Append(TweenManager.TotalPooledTweens())
.Append(" (").Append(TweenManager.totPooledTweeners)
.Append("/").Append(TweenManager.totPooledSequences).Append(")");
GUILayout.Label(_strBuilder.ToString());
GUILayout.Space(8);
_strBuilder.Remove(0, _strBuilder.Length);
_strBuilder.Append("Tweens Capacity: ").Append(TweenManager.maxTweeners).Append("/").Append(TweenManager.maxSequences)
.Append("\nMax Simultaneous Active Tweens: ").Append(DOTween.maxActiveTweenersReached).Append("/").Append(DOTween.maxActiveSequencesReached);
GUILayout.Label(_strBuilder.ToString());
}
GUILayout.Space(8);
_strBuilder.Remove(0, _strBuilder.Length);
_strBuilder.Append("SETTINGS ▼");
_strBuilder.Append("\nSafe Mode: ").Append((_isRuntime ? DOTween.useSafeMode : _settings.useSafeMode) ? "ON" : "OFF");
_strBuilder.Append("\nLog Behaviour: ").Append(_isRuntime ? DOTween.logBehaviour : _settings.logBehaviour);
_strBuilder.Append("\nShow Unity Editor Report: ").Append(_isRuntime ? DOTween.showUnityEditorReport : _settings.showUnityEditorReport);
_strBuilder.Append("\nTimeScale (Unity/DOTween): ").Append(Time.timeScale).Append("/").Append(_isRuntime ? DOTween.timeScale : _settings.timeScale);
GUILayout.Label(_strBuilder.ToString());
GUILayout.Label("NOTE: DOTween's TimeScale is not the same as Unity's Time.timeScale: it is actually multiplied by it except for tweens that are set to update independently", EditorGUIUtils.wordWrapItalicLabelStyle);
GUILayout.Space(8);
_strBuilder.Remove(0, _strBuilder.Length);
_strBuilder.Append("DEFAULTS ▼");
_strBuilder.Append("\ndefaultRecyclable: ").Append(_isRuntime ? DOTween.defaultRecyclable : _settings.defaultRecyclable);
_strBuilder.Append("\ndefaultUpdateType: ").Append(_isRuntime ? DOTween.defaultUpdateType : _settings.defaultUpdateType);
_strBuilder.Append("\ndefaultTSIndependent: ").Append(_isRuntime ? DOTween.defaultTimeScaleIndependent : _settings.defaultTimeScaleIndependent);
_strBuilder.Append("\ndefaultAutoKill: ").Append(_isRuntime ? DOTween.defaultAutoKill : _settings.defaultAutoKill);
_strBuilder.Append("\ndefaultAutoPlay: ").Append(_isRuntime ? DOTween.defaultAutoPlay : _settings.defaultAutoPlay);
_strBuilder.Append("\ndefaultEaseType: ").Append(_isRuntime ? DOTween.defaultEaseType : _settings.defaultEaseType);
_strBuilder.Append("\ndefaultLoopType: ").Append(_isRuntime ? DOTween.defaultLoopType : _settings.defaultLoopType);
GUILayout.Label(_strBuilder.ToString());
GUILayout.Space(10);
}
#endregion
#region Methods
void ConnectToSource(bool forceReconnection = false)
{
_headerImg = AssetDatabase.LoadAssetAtPath("Assets/" + EditorUtils.editorADBDir + "Imgs/DOTweenIcon.png", typeof(Texture2D)) as Texture2D;
if (_settings == null || forceReconnection) {
_settings = _isRuntime
? Resources.Load(DOTweenSettings.AssetName) as DOTweenSettings
: DOTweenUtilityWindow.GetDOTweenSettings();
}
}
#endregion
}
}

View File

@ -1,128 +0,0 @@
// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2014/06/29 20:37
//
// License Copyright (c) Daniele Giardini.
// This work is subject to the terms at http://dotween.demigiant.com/license.php
using System.Text;
using DG.Tweening;
using DG.Tweening.Core;
using UnityEditor;
using UnityEngine;
namespace DG.DOTweenEditor.UI
{
[CustomEditor(typeof(DOTweenComponent))]
public class DOTweenInspector : Editor
{
DOTweenSettings _settings;
string _title;
readonly StringBuilder _strBuilder = new StringBuilder();
// ===================================================================================
// MONOBEHAVIOUR METHODS -------------------------------------------------------------
void OnEnable()
{
if (_settings == null) _settings = Resources.Load(DOTweenSettings.AssetName) as DOTweenSettings;
_strBuilder.Remove(0, _strBuilder.Length);
_strBuilder.Append("DOTween v").Append(DOTween.Version);
if (TweenManager.isDebugBuild) _strBuilder.Append(" [Debug build]");
else _strBuilder.Append(" [Release build]");
if (EditorUtils.hasPro) _strBuilder.Append("\nDOTweenPro v").Append(EditorUtils.proVersion);
else _strBuilder.Append("\nDOTweenPro not installed");
_title = _strBuilder.ToString();
}
override public void OnInspectorGUI()
{
EditorGUIUtils.SetGUIStyles();
int totActiveTweens = TweenManager.totActiveTweens;
int totPlayingTweens = TweenManager.TotalPlayingTweens();
int totPausedTweens = totActiveTweens - totPlayingTweens;
int totActiveDefaultTweens = TweenManager.totActiveDefaultTweens;
int totActiveLateTweens = TweenManager.totActiveLateTweens;
GUILayout.Space(4);
GUILayout.Label(_title, TweenManager.isDebugBuild ? EditorGUIUtils.redLabelStyle : EditorGUIUtils.boldLabelStyle);
GUILayout.Space(6);
GUILayout.BeginHorizontal();
if (GUILayout.Button("Documentation")) Application.OpenURL("http://dotween.demigiant.com/documentation.php");
if (GUILayout.Button("Check Updates")) Application.OpenURL("http://dotween.demigiant.com/download.php?v=" + DOTween.Version);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (GUILayout.Button(_settings.showPlayingTweens ? "Hide Playing Tweens" : "Show Playing Tweens")) {
_settings.showPlayingTweens = !_settings.showPlayingTweens;
EditorUtility.SetDirty(_settings);
}
if (GUILayout.Button(_settings.showPausedTweens ? "Hide Paused Tweens" : "Show Paused Tweens")) {
_settings.showPausedTweens = !_settings.showPausedTweens;
EditorUtility.SetDirty(_settings);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Play all")) DOTween.PlayAll();
if (GUILayout.Button("Pause all")) DOTween.PauseAll();
if (GUILayout.Button("Kill all")) DOTween.KillAll();
GUILayout.EndHorizontal();
GUILayout.Space(8);
_strBuilder.Length = 0;
_strBuilder.Append("Active tweens: ").Append(totActiveTweens)
.Append(" (").Append(TweenManager.totActiveTweeners)
.Append("/").Append(TweenManager.totActiveSequences).Append(")")
.Append("\nDefault/Late tweens: ").Append(totActiveDefaultTweens)
.Append("/").Append(totActiveLateTweens)
.Append("\nPlaying tweens: ").Append(totPlayingTweens);
if (_settings.showPlayingTweens) {
foreach (Tween t in TweenManager._activeTweens) {
if (t != null && t.isPlaying) _strBuilder.Append("\n - [").Append(t.tweenType).Append("] ").Append(t.target);
}
}
_strBuilder.Append("\nPaused tweens: ").Append(totPausedTweens);
if (_settings.showPausedTweens) {
foreach (Tween t in TweenManager._activeTweens) {
if (t != null && !t.isPlaying) _strBuilder.Append("\n - [").Append(t.tweenType).Append("] ").Append(t.target);
}
}
_strBuilder.Append("\nPooled tweens: ").Append(TweenManager.TotalPooledTweens())
.Append(" (").Append(TweenManager.totPooledTweeners)
.Append("/").Append(TweenManager.totPooledSequences).Append(")");
GUILayout.Label(_strBuilder.ToString());
GUILayout.Space(8);
_strBuilder.Remove(0, _strBuilder.Length);
_strBuilder.Append("Tweens Capacity: ").Append(TweenManager.maxTweeners).Append("/").Append(TweenManager.maxSequences)
.Append("\nMax Simultaneous Active Tweens: ").Append(DOTween.maxActiveTweenersReached).Append("/").Append(DOTween.maxActiveSequencesReached);
GUILayout.Label(_strBuilder.ToString());
GUILayout.Space(8);
_strBuilder.Remove(0, _strBuilder.Length);
_strBuilder.Append("SETTINGS ▼");
_strBuilder.Append("\nSafe Mode: ").Append(DOTween.useSafeMode ? "ON" : "OFF");
_strBuilder.Append("\nLog Behaviour: ").Append(DOTween.logBehaviour);
_strBuilder.Append("\nShow Unity Editor Report: ").Append(DOTween.showUnityEditorReport);
_strBuilder.Append("\nTimeScale (Unity/DOTween): ").Append(Time.timeScale).Append("/").Append(DOTween.timeScale);
GUILayout.Label(_strBuilder.ToString());
GUILayout.Label("NOTE: DOTween's TimeScale is not the same as Unity's Time.timeScale: it is actually multiplied by it except for tweens that are set to update independently", EditorGUIUtils.wordWrapItalicLabelStyle);
GUILayout.Space(8);
_strBuilder.Remove(0, _strBuilder.Length);
_strBuilder.Append("DEFAULTS ▼");
_strBuilder.Append("\ndefaultRecyclable: ").Append(DOTween.defaultRecyclable);
_strBuilder.Append("\ndefaultUpdateType: ").Append(DOTween.defaultUpdateType);
_strBuilder.Append("\ndefaultTSIndependent: ").Append(DOTween.defaultTimeScaleIndependent);
_strBuilder.Append("\ndefaultAutoKill: ").Append(DOTween.defaultAutoKill);
_strBuilder.Append("\ndefaultAutoPlay: ").Append(DOTween.defaultAutoPlay);
_strBuilder.Append("\ndefaultEaseType: ").Append(DOTween.defaultEaseType);
_strBuilder.Append("\ndefaultLoopType: ").Append(DOTween.defaultLoopType);
GUILayout.Label(_strBuilder.ToString());
GUILayout.Space(10);
}
}
}

View File

@ -120,7 +120,7 @@ namespace DG.DOTweenEditor.UI
}
} else {
Rect areaRect = new Rect(0, 0, _headerSize.x, 30);
_selectedTab = UnityEngine.GUI.Toolbar(areaRect, _selectedTab, _tabLabels);
_selectedTab = GUI.Toolbar(areaRect, _selectedTab, _tabLabels);
switch (_selectedTab) {
case 1:
@ -142,18 +142,18 @@ namespace DG.DOTweenEditor.UI
void DrawSetupGUI()
{
Rect areaRect = new Rect(0, 30, _headerSize.x, _headerSize.y);
UnityEngine.GUI.DrawTexture(areaRect, _headerImg, ScaleMode.StretchToFill, false);
GUI.DrawTexture(areaRect, _headerImg, ScaleMode.StretchToFill, false);
GUILayout.Space(areaRect.y + _headerSize.y + 2);
GUILayout.Label(_innerTitle, TweenManager.isDebugBuild ? EditorGUIUtils.redLabelStyle : EditorGUIUtils.boldLabelStyle);
if (_setupRequired) {
UnityEngine.GUI.backgroundColor = Color.red;
GUILayout.BeginVertical(UnityEngine.GUI.skin.box);
GUI.backgroundColor = Color.red;
GUILayout.BeginVertical(GUI.skin.box);
GUILayout.Label("DOTWEEN SETUP REQUIRED", EditorGUIUtils.setupLabelStyle);
GUILayout.EndVertical();
UnityEngine.GUI.backgroundColor = Color.white;
GUI.backgroundColor = Color.white;
} else GUILayout.Space(8);
UnityEngine.GUI.color = Color.green;
GUI.color = Color.green;
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("<b>Setup DOTween...</b>\n(add/remove Modules)", EditorGUIUtils.btSetup)) {
@ -168,7 +168,7 @@ namespace DG.DOTweenEditor.UI
return;
}
GUILayout.FlexibleSpace();
UnityEngine.GUI.color = Color.white;
GUI.color = Color.white;
GUILayout.EndHorizontal();
GUILayout.Space(8);

View File

@ -29,6 +29,7 @@ namespace DG.DOTweenEditor.UI
wordWrapTextArea,
popupButton,
btIconStyle;
public static GUIStyle infoboxStyle;
public static Texture2D logo
{
@ -198,6 +199,16 @@ namespace DG.DOTweenEditor.UI
btIconStyle.padding.left -= 2;
btIconStyle.fixedWidth = 24;
btIconStyle.stretchWidth = false;
//
infoboxStyle = new GUIStyle(GUI.skin.box) {
alignment = TextAnchor.UpperLeft,
richText = true,
wordWrap = true,
padding = new RectOffset(5, 5, 5, 6),
normal = { textColor = Color.white, background = Texture2D.whiteTexture }
};
}
}
}

Binary file not shown.