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

Added auto-ASMDEF creation/management via DOTween Utility Panel

This commit is contained in:
Demigiant 2019-03-05 17:12:44 +01:00
parent 90885a1906
commit 64f7409e78
20 changed files with 251 additions and 38 deletions

View File

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

View File

@ -0,0 +1,201 @@
// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2019/03/05 12:37
// License Copyright (c) Daniele Giardini
// This work is subject to the terms at http://dotween.demigiant.com/license.php
using System;
using System.IO;
using DG.DOTweenEditor.UI;
using DG.Tweening.Core;
using UnityEditor;
using UnityEngine;
namespace DG.DOTweenEditor
{
internal static class ASMDEFManager
{
public enum ASMDEFType
{
Modules,
DOTweenPro
}
enum ChangeType
{
Deleted,
Created,
Overwritten
}
public static bool hasModulesASMDEF { get; private set; }
public static bool hasProASMDEF { get; private set; }
const string _ModulesId = "DOTween.Modules";
const string _ProId = "DOTweenPro.Scripts";
const string _ModulesASMDEFFile = _ModulesId + ".asmdef";
const string _ProASMDEFFile = _ProId + ".asmdef";
const string _RefTextMeshPro = "Unity.TextMeshPro";
static ASMDEFManager()
{
Refresh();
}
#region Public Methods
public static void Refresh()
{
hasModulesASMDEF = File.Exists(EditorUtils.dotweenModulesDir + _ModulesASMDEFFile);
hasProASMDEF = File.Exists(EditorUtils.dotweenProDir + _ProASMDEFFile);
}
public static void RefreshExistingASMDEFFiles()
{
Refresh();
if (!hasModulesASMDEF) {
if (hasProASMDEF) RemoveASMDEF(ASMDEFType.DOTweenPro);
return;
}
if (EditorUtils.hasPro && !hasProASMDEF) {
CreateASMDEF(ASMDEFType.DOTweenPro);
return;
}
// Pro ASMDEF present: check that it contains correct elements
DOTweenSettings src = DOTweenUtilityWindow.GetDOTweenSettings();
if (src == null) return;
bool hasTextMeshProRef = false;
using (StreamReader sr = new StreamReader(EditorUtils.dotweenProDir + _ProASMDEFFile)) {
string s;
while ((s = sr.ReadLine()) != null) {
if (!s.Contains(_RefTextMeshPro)) continue;
hasTextMeshProRef = true;
break;
}
}
bool recreate = hasTextMeshProRef != src.modules.textMeshProEnabled;
if (recreate) CreateASMDEF(ASMDEFType.DOTweenPro, true);
}
public static void CreateAllASMDEF()
{
CreateASMDEF(ASMDEFType.Modules);
CreateASMDEF(ASMDEFType.DOTweenPro);
}
public static void RemoveAllASMDEF()
{
RemoveASMDEF(ASMDEFType.Modules);
RemoveASMDEF(ASMDEFType.DOTweenPro);
}
#endregion
#region Methods
static void LogASMDEFChange(ASMDEFType asmdefType, ChangeType changeType)
{
Debug.Log(string.Format(
"<b>DOTween ASMDEF file <color=#{0}>{1}</color></b> ► {2}",
changeType == ChangeType.Deleted ? "ff0000" : changeType == ChangeType.Created ? "00ff00" : "ff6600",
changeType == ChangeType.Deleted ? "removed" : changeType == ChangeType.Created ? "created" : "changed",
asmdefType == ASMDEFType.Modules ? "DOTween/Modules/" + _ModulesASMDEFFile : "DOTweenPro/" + _ProASMDEFFile
));
}
static void CreateASMDEF(ASMDEFType type, bool forceOverwrite = false)
{
Refresh();
bool alreadyPresent = false;
string asmdefId = null;
string asmdefFile = null;
string asmdefDir = null; // with final OS slash
switch (type) {
case ASMDEFType.Modules:
alreadyPresent = hasModulesASMDEF;
asmdefId = _ModulesId;
asmdefFile = _ModulesASMDEFFile;
asmdefDir = EditorUtils.dotweenModulesDir;
break;
case ASMDEFType.DOTweenPro:
alreadyPresent = hasProASMDEF;
asmdefId = _ProId;
asmdefFile = _ProASMDEFFile;
asmdefDir = EditorUtils.dotweenProDir;
break;
}
if (alreadyPresent && !forceOverwrite) {
EditorUtility.DisplayDialog("Create ASMDEF", asmdefFile + " already exists", "Ok");
return;
}
if (!Directory.Exists(asmdefDir)) {
EditorUtility.DisplayDialog(
"Create ASMDEF",
string.Format("Directory not found\n({0})", asmdefDir),
"Ok"
);
return;
}
string asmdefFilePath = asmdefDir + asmdefFile;
using (StreamWriter sw = File.CreateText(asmdefFilePath)) {
sw.WriteLine("{");
switch (type) {
case ASMDEFType.Modules:
sw.WriteLine("\t\"name\": \"{0}\"", asmdefId);
break;
case ASMDEFType.DOTweenPro:
sw.WriteLine("\t\"name\": \"{0}\",", asmdefId);
sw.WriteLine("\t\"references\": [");
DOTweenSettings src = DOTweenUtilityWindow.GetDOTweenSettings();
if (src != null) {
if (src.modules.textMeshProEnabled) sw.WriteLine("\t\t\"{0}\",", _RefTextMeshPro);
}
sw.WriteLine("\t\t\"{0}\"", _ModulesId);
sw.WriteLine("\t]");
break;
}
sw.WriteLine("}");
}
string adbFilePath = EditorUtils.FullPathToADBPath(asmdefFilePath);
AssetDatabase.ImportAsset(adbFilePath, ImportAssetOptions.ForceUpdate);
Refresh();
LogASMDEFChange(type, alreadyPresent ? ChangeType.Overwritten : ChangeType.Created);
}
static void RemoveASMDEF(ASMDEFType type)
{
bool alreadyPresent = false;
string asmdefFile = null;
string asmdefDir = null; // with final OS slash
switch (type) {
case ASMDEFType.Modules:
alreadyPresent = hasModulesASMDEF;
asmdefDir = EditorUtils.dotweenModulesDir;
asmdefFile = _ModulesASMDEFFile;
break;
case ASMDEFType.DOTweenPro:
alreadyPresent = hasProASMDEF;
asmdefFile = _ProASMDEFFile;
asmdefDir = EditorUtils.dotweenProDir;
break;
}
Refresh();
if (!alreadyPresent) {
EditorUtility.DisplayDialog("Remove ASMDEF", asmdefFile + " not present", "Ok");
return;
}
string asmdefFilePath = asmdefDir + asmdefFile;
AssetDatabase.DeleteAsset(EditorUtils.FullPathToADBPath(asmdefFilePath));
Refresh();
LogASMDEFChange(type, ChangeType.Deleted);
}
#endregion
}
}

View File

@ -74,6 +74,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DelayedCall.cs" />
<Compile Include="ASMDEFManager.cs" />
<Compile Include="DOTweenEditorPreview.cs" />
<Compile Include="MenuItems.cs" />
<Compile Include="UI\EditorGUIUtils.cs" />

View File

@ -62,37 +62,23 @@ namespace DG.DOTweenEditor
string[] dotweenEntries = System.Array.FindAll(importedAssets, name => name.Contains("DOTween") && !name.EndsWith(".meta") && !name.EndsWith(".jpg") && !name.EndsWith(".png"));
bool dotweenImported = dotweenEntries.Length > 0;
if (!dotweenImported) return;
if (dotweenImported) {
// Reapply modules
EditorUtils.DelayedCall(0.1f, ()=> {
// Debug.Log("Apply Modules Settings after reimport");
DOTweenUtilityWindowModules.ApplyModulesSettings();
});
}
// Reapply modules
EditorUtils.DelayedCall(0.1f, ()=> {
// Debug.Log("Apply Modules Settings after reimport");
DOTweenUtilityWindowModules.ApplyModulesSettings();
});
// DOTweenUtilityWindowModules.ApplyModulesSettings();
// // Delete old DOTween files
// EditorUtils.DeleteLegacyNoModulesDOTweenFiles();
// // Delete old DemiLib configuration
// EditorUtils.DeleteOldDemiLibCore();
// // Remove old legacy defines
// DOTweenDefines.RemoveAllLegacyDefines();
// // Reapply modules
// DOTweenUtilityWindowModules.ApplyModulesSettings();
// //
// 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 setupRequired = differentCoreVersion || differentProVersion;
// if (!setupRequired) return;
//
// _setupDialogRequested = true;
// EditorPrefs.SetString(Application.dataPath + DOTweenUtilityWindow.Id, Application.dataPath + DOTween.Version);
// if (EditorUtils.hasPro) {
// EditorPrefs.SetString(Application.dataPath + DOTweenUtilityWindow.IdPro, Application.dataPath + EditorUtils.proVersion);
// }
// DOTweenUtilityWindow.Open();
string[] dotweenProEntries = System.Array.FindAll(importedAssets, name => name.Contains("DOTweenPro") && !name.EndsWith(".meta") && !name.EndsWith(".jpg") && !name.EndsWith(".png"));
bool dotweenProImported = dotweenProEntries.Length > 0;
if (dotweenProImported) {
// Refresh ASMDEF
EditorUtils.DelayedCall(0.1f, ()=> {
// Debug.Log("Refresh ASMDEF after DOTween Pro reimport");
ASMDEFManager.RefreshExistingASMDEFFiles();
});
}
}
}
}

View File

@ -25,6 +25,8 @@ namespace DG.DOTweenEditor
public static string dotweenDir { get { if (string.IsNullOrEmpty(_dotweenDir)) StoreDOTweenDirs(); return _dotweenDir; } }
// With final slash (system based)
public static string dotweenProDir { get { if (string.IsNullOrEmpty(_dotweenProDir)) StoreDOTweenDirs(); return _dotweenProDir; } }
// With final slash (system based)
public static string dotweenModulesDir { get { if (string.IsNullOrEmpty(_dotweenModulesDir)) StoreDOTweenDirs(); return _dotweenModulesDir; } }
public static bool isOSXEditor { get; private set; }
public static string pathSlash { get; private set; } // for full paths
public static string pathSlashToReplace { get; private set; } // for full paths
@ -37,6 +39,7 @@ namespace DG.DOTweenEditor
static string _demigiantDir; // with final slash
static string _dotweenDir; // with final slash
static string _dotweenProDir; // with final slash
static string _dotweenModulesDir; // with final slash
static EditorUtils()
{
@ -372,6 +375,7 @@ namespace DG.DOTweenEditor
_dotweenDir = _dotweenDir.Replace(pathSlashToReplace, pathSlash);
_dotweenProDir = _dotweenProDir.Replace(pathSlashToReplace, pathSlash);
_dotweenModulesDir = _dotweenDir + "Modules" + pathSlash;
if (_demigiantDir != null) _demigiantDir = _demigiantDir.Replace(pathSlashToReplace, pathSlash);
}

View File

@ -159,7 +159,7 @@ namespace DG.DOTweenEditor.UI
GUI.color = Color.green;
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
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, GUILayout.Width(200))) {
// DOTweenDefines.Setup();
// _setupRequired = EditorUtils.DOTweenSetupRequired();
DOTweenUtilityWindowModules.ApplyModulesSettings();
@ -171,15 +171,34 @@ namespace DG.DOTweenEditor.UI
return;
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUI.color = Color.white;
GUILayout.Space(4);
// ASMDEF
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUI.color = ASMDEFManager.hasModulesASMDEF ? Color.yellow : Color.cyan;
if (GUILayout.Button(ASMDEFManager.hasModulesASMDEF ? "Remove ASMDEF..." : "Create ASMDEF...", EditorGUIUtils.btSetup, GUILayout.Width(200))) {
if (ASMDEFManager.hasModulesASMDEF) {
if (EditorUtility.DisplayDialog("Remove ASMDEF",
string.Format("This will remove the \"DOTween/Modules/DOTween.Modules.asmdef\" and \"DOTweenPro/DOTweenPro.Scripts.asmdef\"" +
" (if you have DOTween Pro) files."),
"Ok", "Cancel"
)) ASMDEFManager.RemoveAllASMDEF();
} else {
if (EditorUtility.DisplayDialog("Create ASMDEF",
string.Format("This will create the \"DOTween/Modules/DOTween.Modules.asmdef\" and \"DOTweenPro/DOTweenPro.Scripts.asmdef\"" +
" (if you have DOTween Pro) files."),
"Ok", "Cancel"
)) ASMDEFManager.CreateAllASMDEF();
}
}
GUI.color = Color.white;
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.Space(8);
// EditorGUILayout.HelpBox(
// "NOTE: if you get \"Requested build target group (N) doesn't exist\" or [CS0618] errors during the setup don't worry: it's ok and allows the setup to work on all possible Unity versions",
// MessageType.Info
// );
GUILayout.BeginHorizontal();
if (GUILayout.Button("Website", EditorGUIUtils.btBigStyle, GUILayout.Width(_HalfBtSize))) Application.OpenURL("http://dotween.demigiant.com/index.php");
if (GUILayout.Button("Get Started", EditorGUIUtils.btBigStyle, GUILayout.Width(_HalfBtSize))) Application.OpenURL("http://dotween.demigiant.com/getstarted.php");

View File

@ -199,6 +199,8 @@ namespace DG.DOTweenEditor.UI
strb.Remove(strb.Length - 3, 3);
Debug.Log(strb.ToString());
}
ASMDEFManager.RefreshExistingASMDEFFiles();
}
static void Apply_AppendLog(StringBuilder strb, bool enabled, string id)

View File

@ -148,7 +148,7 @@ namespace DG.DOTweenEditor.UI
btBigStyle.padding = new RectOffset(0, 0, 10, 10);
btSetup = new GUIStyle(btBigStyle);
btSetup.padding = new RectOffset(36, 36, 6, 6);
btSetup.padding = new RectOffset(10, 10, 6, 6);
btSetup.wordWrap = true;
btSetup.richText = true;

Binary file not shown.