mirror of
https://github.com/Cardidi/dotween-upm-fork.git
synced 2025-12-22 18:26:15 +08:00
DOTween now remembers which modules were activated and re-enables them when pressing Setup after an upgrade
This commit is contained in:
parent
a32e2c35d3
commit
98b2b57dd9
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1,4 @@
|
|||||||
// Author: Daniele Giardini - http://www.demigiant.com
|
// Author: Daniele Giardini - http://www.demigiant.com
|
||||||
// Created: 2018/07/13
|
// Created: 2018/07/13
|
||||||
|
|
||||||
#if true // MODULE_MARKER
|
#if true // MODULE_MARKER
|
||||||
|
|||||||
Binary file not shown.
@ -1,6 +1,7 @@
|
|||||||
// Author: Daniele Giardini - http://www.demigiant.com
|
// Author: Daniele Giardini - http://www.demigiant.com
|
||||||
// Created: 2015/02/05 10:28
|
// Created: 2015/02/05 10:28
|
||||||
|
|
||||||
|
using System;
|
||||||
using DG.Tweening.Core.Enums;
|
using DG.Tweening.Core.Enums;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -37,9 +38,27 @@ namespace DG.Tweening.Core
|
|||||||
DemigiantDirectory
|
DemigiantDirectory
|
||||||
}
|
}
|
||||||
public SettingsLocation storeSettingsLocation = SettingsLocation.AssetsDirectory;
|
public SettingsLocation storeSettingsLocation = SettingsLocation.AssetsDirectory;
|
||||||
public bool showModulesPanel;
|
public ModulesSetup modules = new ModulesSetup();
|
||||||
|
|
||||||
// Editor-Only ► DOTween Inspector
|
// Editor-Only ► DOTween Inspector
|
||||||
public bool showPlayingTweens, showPausedTweens;
|
public bool showPlayingTweens, showPausedTweens;
|
||||||
|
|
||||||
|
// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
|
||||||
|
// ███ INTERNAL CLASSES ████████████████████████████████████████████████████████████████████████████████████████████████
|
||||||
|
// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class ModulesSetup // Editor-only
|
||||||
|
{
|
||||||
|
public bool showPanel;
|
||||||
|
|
||||||
|
public bool audioEnabled = true;
|
||||||
|
public bool physicsEnabled = true;
|
||||||
|
public bool physics2DEnabled = true;
|
||||||
|
public bool spriteEnabled = true;
|
||||||
|
public bool uiEnabled = true;
|
||||||
|
public bool textMeshProEnabled;
|
||||||
|
public bool tk2DEnabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ namespace DG.DOTweenEditor.UI
|
|||||||
void OnDestroy()
|
void OnDestroy()
|
||||||
{
|
{
|
||||||
if (_src != null) {
|
if (_src != null) {
|
||||||
_src.showModulesPanel = false;
|
_src.modules.showPanel = false;
|
||||||
EditorUtility.SetDirty(_src);
|
EditorUtility.SetDirty(_src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,10 +112,10 @@ namespace DG.DOTweenEditor.UI
|
|||||||
GUILayout.Space(40);
|
GUILayout.Space(40);
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
} else {
|
} else {
|
||||||
if (_src.showModulesPanel) {
|
if (_src.modules.showPanel) {
|
||||||
if (DOTweenUtilityWindowModules.Draw(this)) {
|
if (DOTweenUtilityWindowModules.Draw(this, _src)) {
|
||||||
_setupRequired = EditorUtils.DOTweenSetupRequired();
|
_setupRequired = EditorUtils.DOTweenSetupRequired();
|
||||||
_src.showModulesPanel = false;
|
_src.modules.showPanel = false;
|
||||||
EditorUtility.SetDirty(_src);
|
EditorUtility.SetDirty(_src);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -159,8 +159,8 @@ namespace DG.DOTweenEditor.UI
|
|||||||
if (GUILayout.Button("<b>Setup DOTween...</b>\n(add/remove Modules)", EditorGUIUtils.btSetup)) {
|
if (GUILayout.Button("<b>Setup DOTween...</b>\n(add/remove Modules)", EditorGUIUtils.btSetup)) {
|
||||||
// DOTweenDefines.Setup();
|
// DOTweenDefines.Setup();
|
||||||
// _setupRequired = EditorUtils.DOTweenSetupRequired();
|
// _setupRequired = EditorUtils.DOTweenSetupRequired();
|
||||||
DOTweenUtilityWindowModules.Refresh();
|
DOTweenUtilityWindowModules.Refresh(_src, true);
|
||||||
_src.showModulesPanel = true;
|
_src.modules.showPanel = true;
|
||||||
EditorUtility.SetDirty(_src);
|
EditorUtility.SetDirty(_src);
|
||||||
EditorUtils.DeleteLegacyNoModulesDOTweenFiles();
|
EditorUtils.DeleteLegacyNoModulesDOTweenFiles();
|
||||||
DOTweenDefines.RemoveAllLegacyDefines();
|
DOTweenDefines.RemoveAllLegacyDefines();
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
// License Copyright (c) Daniele Giardini
|
// License Copyright (c) Daniele Giardini
|
||||||
// This work is subject to the terms at http://dotween.demigiant.com/license.php
|
// This work is subject to the terms at http://dotween.demigiant.com/license.php
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using DG.Tweening.Core;
|
using DG.Tweening.Core;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
@ -25,8 +26,10 @@ namespace DG.DOTweenEditor.UI
|
|||||||
static readonly string _ModuleUtilsPath = "Modules/DOTweenModuleUtils.cs";
|
static readonly string _ModuleUtilsPath = "Modules/DOTweenModuleUtils.cs";
|
||||||
|
|
||||||
static EditorWindow _editor;
|
static EditorWindow _editor;
|
||||||
|
static DOTweenSettings _src;
|
||||||
static bool _refreshed;
|
static bool _refreshed;
|
||||||
static bool _isWaitingForCompilation;
|
static bool _isWaitingForCompilation;
|
||||||
|
static readonly List<int> _LinesToChange = new List<int>();
|
||||||
|
|
||||||
static DOTweenUtilityWindowModules()
|
static DOTweenUtilityWindowModules()
|
||||||
{
|
{
|
||||||
@ -43,10 +46,11 @@ namespace DG.DOTweenEditor.UI
|
|||||||
#region GUI
|
#region GUI
|
||||||
|
|
||||||
// Returns TRUE if it should be closed
|
// Returns TRUE if it should be closed
|
||||||
public static bool Draw(EditorWindow editor)
|
public static bool Draw(EditorWindow editor, DOTweenSettings src)
|
||||||
{
|
{
|
||||||
_editor = editor;
|
_editor = editor;
|
||||||
if (!_refreshed) Refresh();
|
_src = src;
|
||||||
|
if (!_refreshed) Refresh(_src);
|
||||||
|
|
||||||
GUILayout.Label("Add/Remove Modules", EditorGUIUtils.titleStyle);
|
GUILayout.Label("Add/Remove Modules", EditorGUIUtils.titleStyle);
|
||||||
|
|
||||||
@ -72,6 +76,7 @@ namespace DG.DOTweenEditor.UI
|
|||||||
GUILayout.BeginHorizontal();
|
GUILayout.BeginHorizontal();
|
||||||
if (GUILayout.Button("Apply")) {
|
if (GUILayout.Button("Apply")) {
|
||||||
Apply();
|
Apply();
|
||||||
|
Refresh(_src);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (GUILayout.Button("Cancel")) {
|
if (GUILayout.Button("Cancel")) {
|
||||||
@ -101,7 +106,7 @@ namespace DG.DOTweenEditor.UI
|
|||||||
if (!EditorApplication.isCompiling) {
|
if (!EditorApplication.isCompiling) {
|
||||||
EditorApplication.update -= WaitForCompilation_Update;
|
EditorApplication.update -= WaitForCompilation_Update;
|
||||||
_isWaitingForCompilation = false;
|
_isWaitingForCompilation = false;
|
||||||
Refresh();
|
Refresh(_src);
|
||||||
}
|
}
|
||||||
_editor.Repaint();
|
_editor.Repaint();
|
||||||
}
|
}
|
||||||
@ -110,18 +115,32 @@ namespace DG.DOTweenEditor.UI
|
|||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
public static void Refresh()
|
public static void Refresh(DOTweenSettings src, bool applySrcSettings = false)
|
||||||
{
|
{
|
||||||
|
_src = src;
|
||||||
_refreshed = true;
|
_refreshed = true;
|
||||||
|
|
||||||
|
AssetDatabase.StartAssetEditing();
|
||||||
_audioModule.enabled = ModuleIsEnabled(_audioModule);
|
_audioModule.enabled = ModuleIsEnabled(_audioModule);
|
||||||
_physicsModule.enabled = ModuleIsEnabled(_physicsModule);
|
_physicsModule.enabled = ModuleIsEnabled(_physicsModule);
|
||||||
_physics2DModule.enabled = ModuleIsEnabled(_physics2DModule);
|
_physics2DModule.enabled = ModuleIsEnabled(_physics2DModule);
|
||||||
_spriteModule.enabled = ModuleIsEnabled(_spriteModule);
|
_spriteModule.enabled = ModuleIsEnabled(_spriteModule);
|
||||||
_uiModule.enabled = ModuleIsEnabled(_uiModule);
|
_uiModule.enabled = ModuleIsEnabled(_uiModule);
|
||||||
|
//
|
||||||
_textMeshProModule.enabled = ModuleIsEnabled(_textMeshProModule);
|
_textMeshProModule.enabled = ModuleIsEnabled(_textMeshProModule);
|
||||||
_tk2DModule.enabled = ModuleIsEnabled(_tk2DModule);
|
_tk2DModule.enabled = ModuleIsEnabled(_tk2DModule);
|
||||||
|
|
||||||
|
CheckAutoModuleSettings(applySrcSettings, _audioModule, ref src.modules.audioEnabled);
|
||||||
|
CheckAutoModuleSettings(applySrcSettings, _physicsModule, ref src.modules.physicsEnabled);
|
||||||
|
CheckAutoModuleSettings(applySrcSettings, _physics2DModule, ref src.modules.physics2DEnabled);
|
||||||
|
CheckAutoModuleSettings(applySrcSettings, _spriteModule, ref src.modules.spriteEnabled);
|
||||||
|
CheckAutoModuleSettings(applySrcSettings, _uiModule, ref src.modules.uiEnabled);
|
||||||
|
//
|
||||||
|
CheckAutoModuleSettings(applySrcSettings, _textMeshProModule, ref src.modules.textMeshProEnabled);
|
||||||
|
CheckAutoModuleSettings(applySrcSettings, _tk2DModule, ref src.modules.tk2DEnabled);
|
||||||
|
AssetDatabase.StopAssetEditing();
|
||||||
|
|
||||||
|
EditorUtility.SetDirty(_src);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Apply()
|
static void Apply()
|
||||||
@ -147,38 +166,68 @@ namespace DG.DOTweenEditor.UI
|
|||||||
using (StreamReader sr = new StreamReader(m.filePath)) {
|
using (StreamReader sr = new StreamReader(m.filePath)) {
|
||||||
string line = sr.ReadLine();
|
string line = sr.ReadLine();
|
||||||
while (line != null) {
|
while (line != null) {
|
||||||
if (line.EndsWith(ModuleMarkerId) && line.TrimStart().StartsWith("#if")) return line.Contains("#if true");
|
if (line.EndsWith(ModuleMarkerId) && line.StartsWith("#if")) return line.StartsWith("#if true");
|
||||||
line = sr.ReadLine();
|
line = sr.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void CheckAutoModuleSettings(bool applySettings, ModuleInfo m, ref bool srcModuleEnabled)
|
||||||
|
{
|
||||||
|
if (m.enabled != srcModuleEnabled) {
|
||||||
|
if (applySettings) {
|
||||||
|
m.enabled = srcModuleEnabled;
|
||||||
|
ToggleModule(m);
|
||||||
|
} else {
|
||||||
|
srcModuleEnabled = m.enabled;
|
||||||
|
EditorUtility.SetDirty(_src);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void ToggleModule(ModuleInfo m)
|
static void ToggleModule(ModuleInfo m)
|
||||||
{
|
{
|
||||||
if (!File.Exists(m.filePath)) return;
|
if (!File.Exists(m.filePath)) return;
|
||||||
if (ModuleIsEnabled(m) == m.enabled) return; // Already set
|
if (ModuleIsEnabled(m) == m.enabled) return; // Already set
|
||||||
|
|
||||||
|
_LinesToChange.Clear();
|
||||||
string[] lines = File.ReadAllLines(m.filePath);
|
string[] lines = File.ReadAllLines(m.filePath);
|
||||||
|
for (int i = 0; i < lines.Length; ++i) {
|
||||||
|
string s = lines[i];
|
||||||
|
if (s.EndsWith(ModuleMarkerId) && (m.enabled && s.StartsWith("#if false") || !m.enabled && s.StartsWith("#if true"))) {
|
||||||
|
_LinesToChange.Add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_LinesToChange.Count > 0) {
|
||||||
using (StreamWriter sw = new StreamWriter(m.filePath)) {
|
using (StreamWriter sw = new StreamWriter(m.filePath)) {
|
||||||
for (int i = 0; i < lines.Length; ++i) {
|
for (int i = 0; i < lines.Length; ++i) {
|
||||||
string s = lines[i];
|
string s = lines[i];
|
||||||
if (s.EndsWith(ModuleMarkerId) && s.TrimStart().StartsWith("#if")) {
|
if (_LinesToChange.Contains(i)) {
|
||||||
s = m.enabled ? s.Replace("#if false", "#if true") : s.Replace("#if true", "#if false");
|
s = m.enabled ? s.Replace("#if false", "#if true") : s.Replace("#if true", "#if false");
|
||||||
}
|
}
|
||||||
sw.WriteLine(s);
|
sw.WriteLine(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AssetDatabase.ImportAsset(EditorUtils.FullPathToADBPath(m.filePath), ImportAssetOptions.Default);
|
AssetDatabase.ImportAsset(EditorUtils.FullPathToADBPath(m.filePath), ImportAssetOptions.Default);
|
||||||
|
}
|
||||||
|
|
||||||
// Enable/disable conditions inside DOTweenModuleUtils.cs
|
// Enable/disable conditions inside DOTweenModuleUtils.cs
|
||||||
if (!File.Exists(_ModuleUtilsPath)) return;
|
if (!File.Exists(_ModuleUtilsPath)) return;
|
||||||
string marker = m.id + "_MARKER";
|
string marker = m.id + "_MARKER";
|
||||||
lines = File.ReadAllLines(_ModuleUtilsPath);
|
lines = File.ReadAllLines(_ModuleUtilsPath);
|
||||||
|
_LinesToChange.Clear();
|
||||||
|
for (int i = 0; i < lines.Length; ++i) {
|
||||||
|
string s = lines[i];
|
||||||
|
if (s.EndsWith(marker) && (m.enabled && s.StartsWith("#if false") || !m.enabled && s.StartsWith("#if true"))) {
|
||||||
|
_LinesToChange.Add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_LinesToChange.Count > 0) {
|
||||||
using (StreamWriter sw = new StreamWriter(_ModuleUtilsPath)) {
|
using (StreamWriter sw = new StreamWriter(_ModuleUtilsPath)) {
|
||||||
for (int i = 0; i < lines.Length; ++i) {
|
for (int i = 0; i < lines.Length; ++i) {
|
||||||
string s = lines[i];
|
string s = lines[i];
|
||||||
if (s.EndsWith(marker) && s.TrimStart().StartsWith("#if")) {
|
if (_LinesToChange.Contains(i)) {
|
||||||
s = m.enabled ? s.Replace("#if false", "#if true") : s.Replace("#if true", "#if false");
|
s = m.enabled ? s.Replace("#if false", "#if true") : s.Replace("#if true", "#if false");
|
||||||
}
|
}
|
||||||
sw.WriteLine(s);
|
sw.WriteLine(s);
|
||||||
@ -187,6 +236,9 @@ namespace DG.DOTweenEditor.UI
|
|||||||
AssetDatabase.ImportAsset(EditorUtils.FullPathToADBPath(_ModuleUtilsPath), ImportAssetOptions.Default);
|
AssetDatabase.ImportAsset(EditorUtils.FullPathToADBPath(_ModuleUtilsPath), ImportAssetOptions.Default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_LinesToChange.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
|
// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user