1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2026-03-26 22:49:03 +08:00

Modules are now applied automatically if they were setup previously and stored in DOTweenSettings

This commit is contained in:
Demigiant 2018-08-02 21:21:33 +02:00
parent 98b2b57dd9
commit 44421094ea
17 changed files with 112 additions and 30 deletions

View File

@ -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

View File

@ -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
using System; using System;

View File

@ -45,6 +45,8 @@ namespace DG.DOTweenEditor
); );
return AssetDeleteResult.DidNotDelete; return AssetDeleteResult.DidNotDelete;
} }
} }
public class UtilityWindowPostProcessor : AssetPostprocessor public class UtilityWindowPostProcessor : AssetPostprocessor
@ -64,6 +66,8 @@ namespace DG.DOTweenEditor
EditorUtils.DeleteOldDemiLibCore(); EditorUtils.DeleteOldDemiLibCore();
// Remove old legacy defines // Remove old legacy defines
DOTweenDefines.RemoveAllLegacyDefines(); DOTweenDefines.RemoveAllLegacyDefines();
// Reapply modules
DOTweenUtilityWindowModules.ApplyModulesSettings();
// //
bool differentCoreVersion = EditorPrefs.GetString(Application.dataPath + DOTweenUtilityWindow.Id) != Application.dataPath + DOTween.Version; bool differentCoreVersion = EditorPrefs.GetString(Application.dataPath + DOTweenUtilityWindow.Id) != Application.dataPath + DOTween.Version;
bool differentProVersion = EditorUtils.hasPro && EditorPrefs.GetString(Application.dataPath + DOTweenUtilityWindow.IdPro) != Application.dataPath + EditorUtils.proVersion; bool differentProVersion = EditorUtils.hasPro && EditorPrefs.GetString(Application.dataPath + DOTweenUtilityWindow.IdPro) != Application.dataPath + EditorUtils.proVersion;

View File

@ -37,7 +37,7 @@ namespace DG.DOTweenEditor.UI
// NOTE: this is also called via Reflection by UpgradeWindow // NOTE: this is also called via Reflection by UpgradeWindow
public static void Open() public static void Open()
{ {
EditorWindow window = EditorWindow.GetWindow<DOTweenUtilityWindow>(true, _Title, true); DOTweenUtilityWindow window = EditorWindow.GetWindow<DOTweenUtilityWindow>(true, _Title, true);
window.minSize = _WinSize; window.minSize = _WinSize;
window.maxSize = _WinSize; window.maxSize = _WinSize;
window.ShowUtility(); window.ShowUtility();
@ -159,7 +159,7 @@ 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(_src, true); DOTweenUtilityWindowModules.ApplyModulesSettings();
_src.modules.showPanel = true; _src.modules.showPanel = true;
EditorUtility.SetDirty(_src); EditorUtility.SetDirty(_src);
EditorUtils.DeleteLegacyNoModulesDOTweenFiles(); EditorUtils.DeleteLegacyNoModulesDOTweenFiles();
@ -265,43 +265,91 @@ namespace DG.DOTweenEditor.UI
// =================================================================================== // ===================================================================================
// METHODS --------------------------------------------------------------------------- // METHODS ---------------------------------------------------------------------------
void Connect(bool forceReconnect = false) public static DOTweenSettings GetDOTweenSettings()
{ {
if (_src != null && !forceReconnect) return; return ConnectToSource(null, false, false);
}
static DOTweenSettings ConnectToSource(DOTweenSettings src, bool createIfMissing, bool fullSetup)
{
LocationData assetsLD = new LocationData(EditorUtils.assetsPath + EditorUtils.pathSlash + "Resources"); LocationData assetsLD = new LocationData(EditorUtils.assetsPath + EditorUtils.pathSlash + "Resources");
LocationData dotweenLD = new LocationData(EditorUtils.dotweenDir + "Resources"); LocationData dotweenLD = new LocationData(EditorUtils.dotweenDir + "Resources");
bool hasDemigiantDir = EditorUtils.demigiantDir != null; bool hasDemigiantDir = EditorUtils.demigiantDir != null;
LocationData demigiantLD = hasDemigiantDir ? new LocationData(EditorUtils.demigiantDir + "Resources") : new LocationData(); LocationData demigiantLD = hasDemigiantDir ? new LocationData(EditorUtils.demigiantDir + "Resources") : new LocationData();
if (_src == null) { if (src == null) {
// Load eventual existing settings // Load eventual existing settings
_src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(assetsLD.adbFilePath, false); src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(assetsLD.adbFilePath, false);
if (_src == null) _src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(dotweenLD.adbFilePath, false); if (src == null) src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(dotweenLD.adbFilePath, false);
if (_src == null && hasDemigiantDir) _src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(demigiantLD.adbFilePath, false); if (src == null && hasDemigiantDir) src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(demigiantLD.adbFilePath, false);
} }
if (_src == null) { if (src == null) {
// Settings don't exist. Create it in external folder // Settings don't exist.
if (!createIfMissing) return null; // Stop here
// Create it in external folder
if (!Directory.Exists(assetsLD.dir)) AssetDatabase.CreateFolder(assetsLD.adbParentDir, "Resources"); if (!Directory.Exists(assetsLD.dir)) AssetDatabase.CreateFolder(assetsLD.adbParentDir, "Resources");
_src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(assetsLD.adbFilePath, true); src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(assetsLD.adbFilePath, true);
} }
if (fullSetup) {
// Move eventual settings from previous location and setup everything correctly // Move eventual settings from previous location and setup everything correctly
DOTweenSettings.SettingsLocation settingsLoc = _src.storeSettingsLocation; DOTweenSettings.SettingsLocation settingsLoc = src.storeSettingsLocation;
switch (settingsLoc) { switch (settingsLoc) {
case DOTweenSettings.SettingsLocation.AssetsDirectory: case DOTweenSettings.SettingsLocation.AssetsDirectory:
MoveSrc(new[] { dotweenLD, demigiantLD }, assetsLD); src = MoveSrc(new[] { dotweenLD, demigiantLD }, assetsLD);
break; break;
case DOTweenSettings.SettingsLocation.DOTweenDirectory: case DOTweenSettings.SettingsLocation.DOTweenDirectory:
MoveSrc(new[] { assetsLD, demigiantLD }, dotweenLD); src = MoveSrc(new[] { assetsLD, demigiantLD }, dotweenLD);
break; break;
case DOTweenSettings.SettingsLocation.DemigiantDirectory: case DOTweenSettings.SettingsLocation.DemigiantDirectory:
MoveSrc(new[] { assetsLD, dotweenLD }, demigiantLD); src = MoveSrc(new[] { assetsLD, dotweenLD }, demigiantLD);
break; break;
} }
} }
void MoveSrc(LocationData[] from, LocationData to) return src;
}
void Connect(bool forceReconnect = false)
{
if (_src != null && !forceReconnect) return;
_src = ConnectToSource(_src, true, true);
// LocationData assetsLD = new LocationData(EditorUtils.assetsPath + EditorUtils.pathSlash + "Resources");
// LocationData dotweenLD = new LocationData(EditorUtils.dotweenDir + "Resources");
// bool hasDemigiantDir = EditorUtils.demigiantDir != null;
// LocationData demigiantLD = hasDemigiantDir ? new LocationData(EditorUtils.demigiantDir + "Resources") : new LocationData();
//
// if (_src == null) {
// // Load eventual existing settings
// _src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(assetsLD.adbFilePath, false);
// if (_src == null) _src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(dotweenLD.adbFilePath, false);
// if (_src == null && hasDemigiantDir) _src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(demigiantLD.adbFilePath, false);
// }
// if (_src == null) {
// // Settings don't exist.
// if (!createSrcIfMissing) return; // Stop here
// // Create it in external folder
// if (!Directory.Exists(assetsLD.dir)) AssetDatabase.CreateFolder(assetsLD.adbParentDir, "Resources");
// _src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(assetsLD.adbFilePath, true);
// }
//
// // Move eventual settings from previous location and setup everything correctly
// DOTweenSettings.SettingsLocation settingsLoc = _src.storeSettingsLocation;
// switch (settingsLoc) {
// case DOTweenSettings.SettingsLocation.AssetsDirectory:
// MoveSrc(new[] { dotweenLD, demigiantLD }, assetsLD);
// break;
// case DOTweenSettings.SettingsLocation.DOTweenDirectory:
// MoveSrc(new[] { assetsLD, demigiantLD }, dotweenLD);
// break;
// case DOTweenSettings.SettingsLocation.DemigiantDirectory:
// MoveSrc(new[] { assetsLD, dotweenLD }, demigiantLD);
// break;
// }
}
static DOTweenSettings MoveSrc(LocationData[] from, LocationData to)
{ {
if (!Directory.Exists(to.dir)) AssetDatabase.CreateFolder(to.adbParentDir, "Resources"); if (!Directory.Exists(to.dir)) AssetDatabase.CreateFolder(to.adbParentDir, "Resources");
foreach (LocationData ld in from) { foreach (LocationData ld in from) {
@ -316,7 +364,7 @@ namespace DG.DOTweenEditor.UI
} }
} }
} }
_src = EditorUtils.ConnectToSourceAsset<DOTweenSettings>(to.adbFilePath, true); return EditorUtils.ConnectToSourceAsset<DOTweenSettings>(to.adbFilePath, true);
} }
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

View File

@ -113,6 +113,17 @@ namespace DG.DOTweenEditor.UI
#endregion #endregion
#region Public Methods
// Also called via Reflection by Autorun
public static void ApplyModulesSettings()
{
DOTweenSettings src = DOTweenUtilityWindow.GetDOTweenSettings();
if (src != null) Refresh(src, true);
}
#endregion
#region Methods #region Methods
public static void Refresh(DOTweenSettings src, bool applySrcSettings = false) public static void Refresh(DOTweenSettings src, bool applySrcSettings = false)

View File

@ -4,6 +4,7 @@
// 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; using System;
using System.Reflection;
using UnityEditor; using UnityEditor;
using UnityEditor.Callbacks; using UnityEditor.Callbacks;
using UnityEngine; using UnityEngine;
@ -25,12 +26,26 @@ namespace DG.DOTweenUpgradeManager
public static void OnUpdate() public static void OnUpdate()
{ {
if (!UpgradeWindowIsOpen()) UpgradeWindow.Open(); if (!UpgradeWindowIsOpen()) {
ApplyModulesSettings();
UpgradeWindow.Open();
}
} }
static bool UpgradeWindowIsOpen() static bool UpgradeWindowIsOpen()
{ {
return Resources.FindObjectsOfTypeAll<UpgradeWindow>().Length > 0; return Resources.FindObjectsOfTypeAll<UpgradeWindow>().Length > 0;
} }
static void ApplyModulesSettings()
{
Type doeditorT = Type.GetType("DG.DOTweenEditor.UI.DOTweenUtilityWindowModules, DOTweenEditor");
if (doeditorT != null) {
MethodInfo miOpen = doeditorT.GetMethod("ApplyModulesSettings", BindingFlags.Static | BindingFlags.Public);
if (miOpen != null) {
miOpen.Invoke(null, null);
}
}
}
} }
} }

View File

@ -62,8 +62,12 @@ namespace DG.DOTweenUpgradeManager
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
if (GUILayout.Button("Open DOTween Utility Panel", GUILayout.Height(30))) { if (GUILayout.Button("Open DOTween Utility Panel", GUILayout.Height(30))) {
Type doeditorT = Type.GetType("DG.DOTweenEditor.UI.DOTweenUtilityWindow, DOTweenEditor"); Type doeditorT = Type.GetType("DG.DOTweenEditor.UI.DOTweenUtilityWindow, DOTweenEditor");
if (doeditorT != null) {
MethodInfo miOpen = doeditorT.GetMethod("Open", BindingFlags.Static | BindingFlags.Public); MethodInfo miOpen = doeditorT.GetMethod("Open", BindingFlags.Static | BindingFlags.Public);
if (miOpen != null) {
miOpen.Invoke(null, null); miOpen.Invoke(null, null);
}
}
EditorApplication.update -= Autorun.OnUpdate; EditorApplication.update -= Autorun.OnUpdate;
this.Close(); this.Close();
} }

Binary file not shown.