From d27b7c2ad74bfcdaacf8414a8459d22102659291 Mon Sep 17 00:00:00 2001 From: JeTeeS <54726375+JeTeeS@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:21:50 +0100 Subject: [PATCH] 0.1.15 (#17) --- CHANGELOG.md | 10 +++++ Editor/MemoryOptimizerMain.cs | 74 ++++++++++++++++++++------------- Editor/MemoryOptimizerWindow.cs | 11 +++-- Editor/TESHelperFunctions.cs | 17 ++++++++ package.json | 2 +- 5 files changed, 78 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce86ac1..f9bc446 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -141,3 +141,13 @@ ### Added - Check if param amount will exceed 255 when generating + +## [0.1.15] - 2024-3-14 + +### Changed + +- An error during uninstall no longer blocks you from uninstalling but instead prompts you to visit the discord. + +### Fixed + +- Deselect prefix now properly updates the UI diff --git a/Editor/MemoryOptimizerMain.cs b/Editor/MemoryOptimizerMain.cs index 3757db3..b557bae 100644 --- a/Editor/MemoryOptimizerMain.cs +++ b/Editor/MemoryOptimizerMain.cs @@ -34,6 +34,7 @@ public class ParamDriversAndStates public List states = new List(); } + private const string discordLink = "https://discord.gg/N7snuJhzkd"; private const string prefix = "MemOpt_"; private const string syncingLayerName = prefix + "Syncing Layer"; private const string syncingLayerIdentifier = prefix + "Syncer"; @@ -67,7 +68,7 @@ private class MemoryOptimizerState public AnimatorControllerLayer syncingLayer; } - public static bool FindInstallation(AnimatorController controller) + public static bool IsSystemInstalled(AnimatorController controller) { if (controller == null) return false; @@ -607,49 +608,64 @@ public static void UninstallMemOpt(VRCAvatarDescriptor avatar, AnimatorControlle List syncingLayers = fxLayer.FindHiddenIdentifier(syncingLayerIdentifier); if (mainBlendTreeLayers.Count > 1) - { - Debug.LogError("[MemoryOptimizer] Too many memory optimizer blendtrees found, unable to uninstall automatically!"); - return; - } + if (UninstallErrorDialogWithDiscordLink( + $"Too many MemOptBlendtrees found", + $"Too many MemOptBlendtrees found! {mainBlendTreeLayers.Count} found. \nPlease join the discord for support. \nKeep in mind there are backups made by default by the script!", + discordLink) != 0 + ) + return; if (syncingLayers.Count != 1) { - Debug.LogError("[MemoryOptimizer] " + syncingLayers.Count + " syncing layers found, unable to uninstall automatically"); - return; + string s = (mainBlendTreeLayers.Count > 1) ? "many" : "few"; + if (UninstallErrorDialogWithDiscordLink( + $"Too {s} syncing layers found", + $"Too {s} syncing layers found! {syncingLayers.Count} found. \nPlease join the discord for support. \nKeep in mind there are backups made by default by the script!", + discordLink) != 0 + ) + return; } - - List states = syncingLayers[0].FindAllStatesInLayer(); - List setStates = states.Where(x => x.state.name.Contains("Set Value ")).ToList(); - foreach (ChildAnimatorState state in setStates) + else { - VRCAvatarParameterDriver paramdriver = (VRCAvatarParameterDriver)state.state.behaviours[0]; - List paramdriverParams = paramdriver.parameters; - foreach (VRC_AvatarParameterDriver.Parameter param in paramdriverParams) - if (!String.IsNullOrEmpty(param.source)) - foreach (VRCExpressionParameters.Parameter item in expressionParameters.parameters.Where(x => x.name == param.source)) - optimizedParams.Add(item); + List states = syncingLayers[0].FindAllStatesInLayer(); + List setStates = states.Where(x => x.state.name.Contains("Set Value ")).ToList(); + foreach (ChildAnimatorState state in setStates) + { + VRCAvatarParameterDriver paramdriver = (VRCAvatarParameterDriver)state.state.behaviours[0]; + List paramdriverParams = paramdriver.parameters; + foreach (VRC_AvatarParameterDriver.Parameter param in paramdriverParams) + if (!String.IsNullOrEmpty(param.source)) + foreach (VRCExpressionParameters.Parameter item in expressionParameters.parameters.Where(x => x.name == param.source)) + optimizedParams.Add(item); + } } foreach (VRCExpressionParameters.Parameter item in expressionParameters.parameters.Where(x => x.name.Contains(prefix))) generatedExpressionParams.Add(item); if (generatedExpressionParams.Count <= 0) - { - Debug.LogError("[MemoryOptimizer] Too few generated expression parameters found! Only " + generatedExpressionParams.Count + " found. Aborting uninstall..."); - return; - } + if (UninstallErrorDialogWithDiscordLink( + "Too few generated expressions found", + $"Too few generated expressions found! {generatedExpressionParams.Count} found. \nPlease join the discord for support. \nKeep in mind there are backups made by default by the script!", + discordLink) != 0 + ) + return; if (generatedAnimatorParams.Count <= 0) - { - Debug.LogError("[MemoryOptimizer] Too few generated animator parameters found! Only " + generatedAnimatorParams.Count + " found. Aborting uninstall..."); - return; - } + if (UninstallErrorDialogWithDiscordLink( + "Too few generated animator parameters found!", + $"Too few generated animator parameters found! {generatedAnimatorParams.Count} found. \nPlease join the discord for support. \nKeep in mind there are backups made by default by the script!", + discordLink) != 0 + ) + return; if (optimizedParams.Count < 2) - { - Debug.LogError("[MemoryOptimizer] Too few optimized parameters found! Only " + optimizedParams.Count + " found. Aborting uninstall..."); - return; - } + if (UninstallErrorDialogWithDiscordLink( + "Too few optimized parameters found!", + $"Too few generated animator parameters found! {optimizedParams.Count} found. \nPlease join the discord for support. \nKeep in mind there are backups made by default by the script!", + discordLink) != 0 + ) + return; foreach (AnimatorControllerLayer mainBlendTreeLayer in mainBlendTreeLayers) { diff --git a/Editor/MemoryOptimizerWindow.cs b/Editor/MemoryOptimizerWindow.cs index 4d1582c..885bef0 100644 --- a/Editor/MemoryOptimizerWindow.cs +++ b/Editor/MemoryOptimizerWindow.cs @@ -190,9 +190,8 @@ void OnAvatarChange() { if (!string.IsNullOrEmpty(name)) foreach (MemoryOptimizerMain.MemoryOptimizerListData param in paramList.FindAll(x => x.param.name.StartsWith(name, true, null))) param.selected = false; + OnChangeUpdate(); }); - - OnChangeUpdate(); } if (GUILayout.Button("Select All")) @@ -225,7 +224,7 @@ void OnAvatarChange() GUI.enabled = true; //System already installed - if (MemoryOptimizerMain.FindInstallation(avatarFXLayer)) + if (MemoryOptimizerMain.IsSystemInstalled(avatarFXLayer)) { GUI.backgroundColor = new Color(0.1f, 0.1f, 0.1f, 1); GUI.enabled = false; @@ -306,7 +305,7 @@ void OnAvatarChange() */ using (new SqueezeScope((0, 0, EditorH, EditorStyles.helpBox))) { - if (MemoryOptimizerMain.FindInstallation(avatarFXLayer)) + if (MemoryOptimizerMain.IsSystemInstalled(avatarFXLayer)) { GUI.backgroundColor = Color.black; GUILayout.Label("System Already Installed!", EditorStyles.boldLabel); @@ -333,7 +332,7 @@ void OnAvatarChange() if (syncSteps > maxSyncSteps) syncSteps = maxSyncSteps; - if (MemoryOptimizerMain.FindInstallation(avatarFXLayer)) + if (MemoryOptimizerMain.IsSystemInstalled(avatarFXLayer)) { if (GUILayout.Button("Uninstall")) MemoryOptimizerMain.UninstallMemOpt(avatarDescriptor, avatarFXLayer, expressionParameters); @@ -345,7 +344,7 @@ void OnAvatarChange() GUI.enabled = true; } - if (MemoryOptimizerMain.FindInstallation(avatarFXLayer)) + if (MemoryOptimizerMain.IsSystemInstalled(avatarFXLayer)) { GUI.enabled = false; GUI.backgroundColor = Color.black; diff --git a/Editor/TESHelperFunctions.cs b/Editor/TESHelperFunctions.cs index effc850..fbb3716 100644 --- a/Editor/TESHelperFunctions.cs +++ b/Editor/TESHelperFunctions.cs @@ -50,6 +50,23 @@ public static string GetAssetName(UnityEngine.Object thing) string path = AssetDatabase.GetAssetPath(thing); return GetAssetName(path); } + public static int UninstallErrorDialogWithDiscordLink(string title, string mainMessage, string discordLink) + { + int option = EditorUtility.DisplayDialogComplex(title, mainMessage, "Continue uninstall anyways (not recommended)", "Cancel uninstall", "Join the discord"); + switch (option) + { + case 0: + return 0; + case 1: + return 1; + case 2: + Application.OpenURL(discordLink); + return 2; + default: + Debug.LogError("Unrecognized option."); + return -1; + } + } public static AnimatorController FindFXLayer(VRCAvatarDescriptor descriptor) { return (AnimatorController)descriptor.baseAnimationLayers.FirstOrDefault(x => x.type == VRCAvatarDescriptor.AnimLayerType.FX && x.animatorController != null).animatorController; diff --git a/package.json b/package.json index 66d10e5..7ea3498 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "dev.jetees.memoryoptimizer", "displayName": "Memory Optimizer", - "version": "0.1.14", + "version": "0.1.15", "unity" : "2022.3", "description": "A tool to help you optimize your avatar's parameters", "url": "https://github.com/JeTeeS/MemoryOptimizer",