You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PlumberUltimateAds/Assets/Demigiant/DOTweenPro/Editor/DOTweenPreviewManager.cs

256 lines
11 KiB
C#

Squashed commit of the following: commit 761fe0f0e39341baeea362d1a24b85307c6533bf Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Thu Oct 17 17:30:04 2024 +0500 Fixed some spash issues commit a29c5d792ee1e70828ca21d11b1d0e8b57194d3b Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Thu Oct 17 16:57:44 2024 +0500 Fixed Splash issue commit 4000ab25110d0593dfe5ad5eea81a4109a744464 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Thu Oct 17 16:00:08 2024 +0500 fixed spalsh issue commit df377a68259ee183783ce1d898258a26e9f7e6de Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Thu Oct 17 00:59:51 2024 +0500 Reapply "Fixed Splash Animation" This reverts commit b13733598e066c087cc1835f0e566d9fc6e4ebb3. commit b13733598e066c087cc1835f0e566d9fc6e4ebb3 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Thu Oct 17 00:39:51 2024 +0500 Revert "Fixed Splash Animation" This reverts commit 7ca6548075765db1bc2f62015ffec7fecb6235de. commit 7ca6548075765db1bc2f62015ffec7fecb6235de Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Wed Oct 16 17:19:40 2024 +0500 Fixed Splash Animation commit ec93b630739611fe012cd30c081421d4f63f3395 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Wed Oct 16 16:52:15 2024 +0500 Added New Pipes commit 47925d7b4d767d72f41a8e24b2728645a6444771 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Tue Oct 15 18:08:10 2024 +0500 Some indentation commit 0c342ac10c38154817b2e11f05821b0f1a1ea674 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Tue Oct 15 18:07:14 2024 +0500 Increased Level Cell Size commit f3a7e3ed5a1ae97a6aae36cd9e1c87f206a1488c Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Tue Oct 15 18:02:58 2024 +0500 Revert "Increased Cell size" This reverts commit 6e4c1672ba8e63276cfe45afed9af56abb7668de. commit 6e4c1672ba8e63276cfe45afed9af56abb7668de Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Tue Oct 15 17:48:28 2024 +0500 Increased Cell size commit dce666657f57307688c7633084330aec07052f78 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Tue Oct 15 17:36:13 2024 +0500 Added Ranked Up Screen commit d4883314781598c9a3444930ac0a956b1b088890 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Tue Oct 15 14:13:54 2024 +0500 Added new Level Complete Screen commit 1ef6d7cf34773c89b12723f99e26b6aa6043745a Author: TG9six <totalgamer.tg.x@gmail.com> Date: Mon Oct 14 12:04:04 2024 +0400 UI improved Level selection change anchoring improved commit ea8f9899e856e021978159125a8e782bd0cf3a53 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Fri Oct 11 21:05:40 2024 +0500 All UI Done commit d656fb09a601bc57f1e6d004b83256ce26e59d97 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Fri Oct 11 19:15:22 2024 +0500 Added Level Screen commit f131e38a6b7ea830ae6816df16d148bbf3847dcd Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Fri Oct 11 17:13:26 2024 +0500 Gameplay UI Done commit a695895c90522a7208abfa9edc07040021362799 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Fri Oct 11 16:36:09 2024 +0500 Added all gameplay UI commit ab259bf005c7dc1bf01cc334da9b5dd701818496 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Fri Oct 11 11:21:47 2024 +0500 Added Level Type Selection Screen commit 8cebd78cfeec4fea53a38687d8c244c8ff08f15b Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Thu Oct 10 21:33:27 2024 +0500 Added RateUs commit 901e44afafb7b0bca1209df744d9a0be1012cd0b Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Thu Oct 10 20:56:50 2024 +0500 Before addiung unity figma bridge commit bdc01bcb186e1714d5b7efa061418e979b926312 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Thu Oct 10 19:36:39 2024 +0500 Added Settings menu commit 85b53482054a0f4831dc62ca805dbc8a96e474e5 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Wed Oct 9 19:13:39 2024 +0500 Added Main Menu Screen commit a80c82c82f91563ea3a06a5d7cb4219dc9520b14 Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Wed Oct 9 17:26:31 2024 +0500 Added new main menu UI commit 833a599da1496f33d46bd2f32457ad2b16f6bd9d Author: Hazim Bin Ijaz <hazimijaz_gamedev@rizzestudios.com> Date: Wed Oct 9 13:22:52 2024 +0500 Added MainMenu Animation
2 months ago
// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2015/03/12 16:03
using System;
using System.Collections.Generic;
using DG.DemiEditor;
using DG.DemiLib;
using DG.Tweening;
using DG.Tweening.Core;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using Object = UnityEngine.Object;
namespace DG.DOTweenEditor
{
public static class DOTweenPreviewManager
{
static bool _previewOnlyIfSetToAutoPlay = true;
static readonly Dictionary<DOTweenAnimation,TweenInfo> _AnimationToTween = new Dictionary<DOTweenAnimation,TweenInfo>();
static readonly List<DOTweenAnimation> _TmpKeys = new List<DOTweenAnimation>();
#region Public Methods & GUI
/// <summary>
/// Returns TRUE if its actually previewing animations
/// </summary>
public static bool PreviewGUI(DOTweenAnimation src)
{
if (EditorApplication.isPlaying) return false;
Styles.Init();
bool isPreviewing = _AnimationToTween.Count > 0;
bool isPreviewingThis = isPreviewing && _AnimationToTween.ContainsKey(src);
// Preview in editor
GUI.backgroundColor = isPreviewing
? new DeSkinColor(new Color(0.49f, 0.8f, 0.86f), new Color(0.15f, 0.26f, 0.35f))
: new DeSkinColor(Color.white, new Color(0.13f, 0.13f, 0.13f));
GUILayout.BeginVertical(Styles.previewBox);
DeGUI.ResetGUIColors();
GUILayout.BeginHorizontal();
GUILayout.Label("Preview Mode - Experimental", Styles.previewLabel);
_previewOnlyIfSetToAutoPlay = DeGUILayout.ToggleButton(
_previewOnlyIfSetToAutoPlay,
new GUIContent("AutoPlay only", "If toggled only previews animations that have AutoPlay turned ON"),
Styles.btOption
);
GUILayout.EndHorizontal();
GUILayout.Space(1);
// Preview - Play
GUILayout.BeginHorizontal();
EditorGUI.BeginDisabledGroup(
isPreviewingThis || src.animationType == DOTweenAnimationType.None
|| !src.isActive || _previewOnlyIfSetToAutoPlay && !src.autoPlay
);
if (GUILayout.Button("► Play", Styles.btPreview)) {
if (!isPreviewing) StartupGlobalPreview();
AddAnimationToGlobalPreview(src);
}
EditorGUI.EndDisabledGroup();
EditorGUI.BeginDisabledGroup(isPreviewing);
if (GUILayout.Button("► Play All <i>on GameObject</i>", Styles.btPreview)) {
if (!isPreviewing) StartupGlobalPreview();
DOTweenAnimation[] anims = src.gameObject.GetComponents<DOTweenAnimation>();
foreach (DOTweenAnimation anim in anims) AddAnimationToGlobalPreview(anim);
}
if (GUILayout.Button("► Play All <i>in Scene</i>", Styles.btPreview)) {
if (!isPreviewing) StartupGlobalPreview();
DOTweenAnimation[] anims = Object.FindObjectsOfType<DOTweenAnimation>();
foreach (DOTweenAnimation anim in anims) AddAnimationToGlobalPreview(anim);
}
EditorGUI.EndDisabledGroup();
GUILayout.EndHorizontal();
// Preview - Stop
GUILayout.BeginHorizontal();
EditorGUI.BeginDisabledGroup(!isPreviewingThis);
if (GUILayout.Button("■ Stop", Styles.btPreview)) {
if (_AnimationToTween.ContainsKey(src)) StopPreview(_AnimationToTween[src].tween);
}
EditorGUI.EndDisabledGroup();
EditorGUI.BeginDisabledGroup(!isPreviewing);
if (GUILayout.Button("■ Stop All <i>on GameObject</i>", Styles.btPreview)) {
StopPreview(src.gameObject);
}
if (GUILayout.Button("■ Stop All <i>in Scene</i>", Styles.btPreview)) {
StopAllPreviews();
}
EditorGUI.EndDisabledGroup();
GUILayout.EndHorizontal();
if (isPreviewing) {
int playingTweens = 0;
int completedTweens = 0;
int pausedTweens = 0;
foreach (KeyValuePair<DOTweenAnimation, TweenInfo> kvp in _AnimationToTween) {
Tween t = kvp.Value.tween;
if (t.IsPlaying()) playingTweens++;
else if (t.IsComplete()) completedTweens++;
else pausedTweens++;
}
GUILayout.Label("Playing Tweens: " + playingTweens, Styles.previewStatusLabel);
GUILayout.Label("Completed Tweens: " + completedTweens, Styles.previewStatusLabel);
// GUILayout.Label("Paused Tweens: " + playingTweens);
}
GUILayout.EndVertical();
return isPreviewing;
}
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
public static void StopAllPreviews(PlayModeStateChange state)
{
StopAllPreviews();
}
#endif
public static void StopAllPreviews()
{
_TmpKeys.Clear();
foreach (KeyValuePair<DOTweenAnimation,TweenInfo> kvp in _AnimationToTween) {
_TmpKeys.Add(kvp.Key);
}
StopPreview(_TmpKeys);
_TmpKeys.Clear();
_AnimationToTween.Clear();
DOTweenEditorPreview.Stop();
#if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5
UnityEditor.EditorApplication.playmodeStateChanged -= StopAllPreviews;
#else
UnityEditor.EditorApplication.playModeStateChanged -= StopAllPreviews;
#endif
// EditorApplication.playmodeStateChanged -= StopAllPreviews;
InternalEditorUtility.RepaintAllViews();
}
#endregion
#region Methods
static void StartupGlobalPreview()
{
DOTweenEditorPreview.Start();
#if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5
UnityEditor.EditorApplication.playmodeStateChanged += StopAllPreviews;
#else
UnityEditor.EditorApplication.playModeStateChanged += StopAllPreviews;
#endif
// EditorApplication.playmodeStateChanged += StopAllPreviews;
}
static void AddAnimationToGlobalPreview(DOTweenAnimation src)
{
if (!src.isActive) return; // Ignore sources whose tweens have been set to inactive
if (_previewOnlyIfSetToAutoPlay && !src.autoPlay) return;
Tween t = src.CreateEditorPreview();
_AnimationToTween.Add(src, new TweenInfo(src, t, src.isFrom));
// Tween setup
DOTweenEditorPreview.PrepareTweenForPreview(t);
}
static void StopPreview(GameObject go)
{
_TmpKeys.Clear();
foreach (KeyValuePair<DOTweenAnimation,TweenInfo> kvp in _AnimationToTween) {
if (kvp.Key.gameObject != go) continue;
_TmpKeys.Add(kvp.Key);
}
StopPreview(_TmpKeys);
_TmpKeys.Clear();
if (_AnimationToTween.Count == 0) StopAllPreviews();
else InternalEditorUtility.RepaintAllViews();
}
static void StopPreview(Tween t)
{
TweenInfo tInfo = null;
foreach (KeyValuePair<DOTweenAnimation,TweenInfo> kvp in _AnimationToTween) {
if (kvp.Value.tween != t) continue;
tInfo = kvp.Value;
_AnimationToTween.Remove(kvp.Key);
break;
}
if (tInfo == null) {
Debug.LogWarning("DOTween Preview ► Couldn't find tween to stop");
return;
}
if (tInfo.isFrom) tInfo.tween.Complete();
else tInfo.tween.Rewind();
tInfo.tween.Kill();
EditorUtility.SetDirty(tInfo.animation); // Refresh views
if (_AnimationToTween.Count == 0) StopAllPreviews();
else InternalEditorUtility.RepaintAllViews();
}
// Stops while iterating inversely, which deals better with tweens that overwrite each other
static void StopPreview(List<DOTweenAnimation> keys)
{
for (int i = keys.Count - 1; i > -1; --i) {
DOTweenAnimation anim = keys[i];
TweenInfo tInfo = _AnimationToTween[anim];
if (tInfo.isFrom) tInfo.tween.Complete();
else tInfo.tween.Rewind();
tInfo.tween.Kill();
EditorUtility.SetDirty(anim); // Refresh views
_AnimationToTween.Remove(anim);
}
}
#endregion
// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
// ███ INTERNAL CLASSES ████████████████████████████████████████████████████████████████████████████████████████████████
// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
class TweenInfo
{
public DOTweenAnimation animation;
public Tween tween;
public bool isFrom;
public TweenInfo(DOTweenAnimation animation, Tween tween, bool isFrom)
{
this.animation = animation;
this.tween = tween;
this.isFrom = isFrom;
}
}
static class Styles
{
static bool _initialized;
public static GUIStyle previewBox, previewLabel, btOption, btPreview, previewStatusLabel;
public static void Init()
{
if (_initialized) return;
_initialized = true;
previewBox = new GUIStyle(GUI.skin.box).Clone().Padding(1, 1, 0, 3)
.Background(DeStylePalette.squareBorderCurved_darkBorders).Border(7, 7, 7, 7);
previewLabel = new GUIStyle(GUI.skin.label).Clone(10, FontStyle.Bold).Padding(1, 0, 3, 0).Margin(3, 6, 0, 0).StretchWidth(false);
btOption = DeGUI.styles.button.bBlankBorderCompact.MarginBottom(2).MarginRight(4);
btPreview = EditorStyles.miniButton.Clone(Format.RichText);
previewStatusLabel = EditorStyles.miniLabel.Clone().Padding(4, 0, 0, 0).Margin(0);
}
}
}
}