mirror of
https://github.com/Cardidi/dotween-upm-fork.git
synced 2025-12-20 09:16:02 +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
|
||||
|
||||
#if true // MODULE_MARKER
|
||||
|
||||
Binary file not shown.
@ -1,6 +1,7 @@
|
||||
// Author: Daniele Giardini - http://www.demigiant.com
|
||||
// Created: 2015/02/05 10:28
|
||||
|
||||
using System;
|
||||
using DG.Tweening.Core.Enums;
|
||||
using UnityEngine;
|
||||
|
||||
@ -37,9 +38,27 @@ namespace DG.Tweening.Core
|
||||
DemigiantDirectory
|
||||
}
|
||||
public SettingsLocation storeSettingsLocation = SettingsLocation.AssetsDirectory;
|
||||
public bool showModulesPanel;
|
||||
public ModulesSetup modules = new ModulesSetup();
|
||||
|
||||
// Editor-Only ► DOTween Inspector
|
||||
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()
|
||||
{
|
||||
if (_src != null) {
|
||||
_src.showModulesPanel = false;
|
||||
_src.modules.showPanel = false;
|
||||
EditorUtility.SetDirty(_src);
|
||||
}
|
||||
}
|
||||
@ -112,10 +112,10 @@ namespace DG.DOTweenEditor.UI
|
||||
GUILayout.Space(40);
|
||||
GUILayout.EndHorizontal();
|
||||
} else {
|
||||
if (_src.showModulesPanel) {
|
||||
if (DOTweenUtilityWindowModules.Draw(this)) {
|
||||
if (_src.modules.showPanel) {
|
||||
if (DOTweenUtilityWindowModules.Draw(this, _src)) {
|
||||
_setupRequired = EditorUtils.DOTweenSetupRequired();
|
||||
_src.showModulesPanel = false;
|
||||
_src.modules.showPanel = false;
|
||||
EditorUtility.SetDirty(_src);
|
||||
}
|
||||
} else {
|
||||
@ -159,8 +159,8 @@ namespace DG.DOTweenEditor.UI
|
||||
if (GUILayout.Button("<b>Setup DOTween...</b>\n(add/remove Modules)", EditorGUIUtils.btSetup)) {
|
||||
// DOTweenDefines.Setup();
|
||||
// _setupRequired = EditorUtils.DOTweenSetupRequired();
|
||||
DOTweenUtilityWindowModules.Refresh();
|
||||
_src.showModulesPanel = true;
|
||||
DOTweenUtilityWindowModules.Refresh(_src, true);
|
||||
_src.modules.showPanel = true;
|
||||
EditorUtility.SetDirty(_src);
|
||||
EditorUtils.DeleteLegacyNoModulesDOTweenFiles();
|
||||
DOTweenDefines.RemoveAllLegacyDefines();
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
// License Copyright (c) Daniele Giardini
|
||||
// This work is subject to the terms at http://dotween.demigiant.com/license.php
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using DG.Tweening.Core;
|
||||
using UnityEditor;
|
||||
@ -25,8 +26,10 @@ namespace DG.DOTweenEditor.UI
|
||||
static readonly string _ModuleUtilsPath = "Modules/DOTweenModuleUtils.cs";
|
||||
|
||||
static EditorWindow _editor;
|
||||
static DOTweenSettings _src;
|
||||
static bool _refreshed;
|
||||
static bool _isWaitingForCompilation;
|
||||
static readonly List<int> _LinesToChange = new List<int>();
|
||||
|
||||
static DOTweenUtilityWindowModules()
|
||||
{
|
||||
@ -43,10 +46,11 @@ namespace DG.DOTweenEditor.UI
|
||||
#region GUI
|
||||
|
||||
// Returns TRUE if it should be closed
|
||||
public static bool Draw(EditorWindow editor)
|
||||
public static bool Draw(EditorWindow editor, DOTweenSettings src)
|
||||
{
|
||||
_editor = editor;
|
||||
if (!_refreshed) Refresh();
|
||||
_src = src;
|
||||
if (!_refreshed) Refresh(_src);
|
||||
|
||||
GUILayout.Label("Add/Remove Modules", EditorGUIUtils.titleStyle);
|
||||
|
||||
@ -72,6 +76,7 @@ namespace DG.DOTweenEditor.UI
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("Apply")) {
|
||||
Apply();
|
||||
Refresh(_src);
|
||||
return true;
|
||||
}
|
||||
if (GUILayout.Button("Cancel")) {
|
||||
@ -101,7 +106,7 @@ namespace DG.DOTweenEditor.UI
|
||||
if (!EditorApplication.isCompiling) {
|
||||
EditorApplication.update -= WaitForCompilation_Update;
|
||||
_isWaitingForCompilation = false;
|
||||
Refresh();
|
||||
Refresh(_src);
|
||||
}
|
||||
_editor.Repaint();
|
||||
}
|
||||
@ -110,18 +115,32 @@ namespace DG.DOTweenEditor.UI
|
||||
|
||||
#region Methods
|
||||
|
||||
public static void Refresh()
|
||||
public static void Refresh(DOTweenSettings src, bool applySrcSettings = false)
|
||||
{
|
||||
_src = src;
|
||||
_refreshed = true;
|
||||
|
||||
AssetDatabase.StartAssetEditing();
|
||||
_audioModule.enabled = ModuleIsEnabled(_audioModule);
|
||||
_physicsModule.enabled = ModuleIsEnabled(_physicsModule);
|
||||
_physics2DModule.enabled = ModuleIsEnabled(_physics2DModule);
|
||||
_spriteModule.enabled = ModuleIsEnabled(_spriteModule);
|
||||
_uiModule.enabled = ModuleIsEnabled(_uiModule);
|
||||
|
||||
//
|
||||
_textMeshProModule.enabled = ModuleIsEnabled(_textMeshProModule);
|
||||
_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()
|
||||
@ -147,44 +166,77 @@ namespace DG.DOTweenEditor.UI
|
||||
using (StreamReader sr = new StreamReader(m.filePath)) {
|
||||
string line = sr.ReadLine();
|
||||
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();
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
if (!File.Exists(m.filePath)) return;
|
||||
if (ModuleIsEnabled(m) == m.enabled) return; // Already set
|
||||
|
||||
_LinesToChange.Clear();
|
||||
string[] lines = File.ReadAllLines(m.filePath);
|
||||
using (StreamWriter sw = new StreamWriter(m.filePath)) {
|
||||
for (int i = 0; i < lines.Length; ++i) {
|
||||
string s = lines[i];
|
||||
if (s.EndsWith(ModuleMarkerId) && s.TrimStart().StartsWith("#if")) {
|
||||
s = m.enabled ? s.Replace("#if false", "#if true") : s.Replace("#if true", "#if false");
|
||||
}
|
||||
sw.WriteLine(s);
|
||||
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);
|
||||
}
|
||||
}
|
||||
AssetDatabase.ImportAsset(EditorUtils.FullPathToADBPath(m.filePath), ImportAssetOptions.Default);
|
||||
if (_LinesToChange.Count > 0) {
|
||||
using (StreamWriter sw = new StreamWriter(m.filePath)) {
|
||||
for (int i = 0; i < lines.Length; ++i) {
|
||||
string s = lines[i];
|
||||
if (_LinesToChange.Contains(i)) {
|
||||
s = m.enabled ? s.Replace("#if false", "#if true") : s.Replace("#if true", "#if false");
|
||||
}
|
||||
sw.WriteLine(s);
|
||||
}
|
||||
}
|
||||
AssetDatabase.ImportAsset(EditorUtils.FullPathToADBPath(m.filePath), ImportAssetOptions.Default);
|
||||
}
|
||||
|
||||
// Enable/disable conditions inside DOTweenModuleUtils.cs
|
||||
if (!File.Exists(_ModuleUtilsPath)) return;
|
||||
string marker = m.id + "_MARKER";
|
||||
lines = File.ReadAllLines(_ModuleUtilsPath);
|
||||
using (StreamWriter sw = new StreamWriter(_ModuleUtilsPath)) {
|
||||
for (int i = 0; i < lines.Length; ++i) {
|
||||
string s = lines[i];
|
||||
if (s.EndsWith(marker) && s.TrimStart().StartsWith("#if")) {
|
||||
s = m.enabled ? s.Replace("#if false", "#if true") : s.Replace("#if true", "#if false");
|
||||
}
|
||||
sw.WriteLine(s);
|
||||
_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);
|
||||
}
|
||||
}
|
||||
AssetDatabase.ImportAsset(EditorUtils.FullPathToADBPath(_ModuleUtilsPath), ImportAssetOptions.Default);
|
||||
if (_LinesToChange.Count > 0) {
|
||||
using (StreamWriter sw = new StreamWriter(_ModuleUtilsPath)) {
|
||||
for (int i = 0; i < lines.Length; ++i) {
|
||||
string s = lines[i];
|
||||
if (_LinesToChange.Contains(i)) {
|
||||
s = m.enabled ? s.Replace("#if false", "#if true") : s.Replace("#if true", "#if false");
|
||||
}
|
||||
sw.WriteLine(s);
|
||||
}
|
||||
}
|
||||
AssetDatabase.ImportAsset(EditorUtils.FullPathToADBPath(_ModuleUtilsPath), ImportAssetOptions.Default);
|
||||
}
|
||||
|
||||
_LinesToChange.Clear();
|
||||
}
|
||||
|
||||
#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