Skip to content

Commit

Permalink
0.1.15 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeTeeS authored Mar 14, 2024
1 parent 3b2bdd8 commit d27b7c2
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 36 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 45 additions & 29 deletions Editor/MemoryOptimizerMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ParamDriversAndStates
public List<AnimatorState> states = new List<AnimatorState>();
}

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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -607,49 +608,64 @@ public static void UninstallMemOpt(VRCAvatarDescriptor avatar, AnimatorControlle
List<AnimatorControllerLayer> syncingLayers = fxLayer.FindHiddenIdentifier(syncingLayerIdentifier);

if (mainBlendTreeLayers.Count > 1)
{
Debug.LogError("<color=yellow>[MemoryOptimizer]</color> 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("<color=yellow>[MemoryOptimizer]</color> " + 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<ChildAnimatorState> states = syncingLayers[0].FindAllStatesInLayer();
List<ChildAnimatorState> 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<VRC_AvatarParameterDriver.Parameter> 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<ChildAnimatorState> states = syncingLayers[0].FindAllStatesInLayer();
List<ChildAnimatorState> setStates = states.Where(x => x.state.name.Contains("Set Value ")).ToList();
foreach (ChildAnimatorState state in setStates)
{
VRCAvatarParameterDriver paramdriver = (VRCAvatarParameterDriver)state.state.behaviours[0];
List<VRC_AvatarParameterDriver.Parameter> 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("<color=yellow>[MemoryOptimizer]</color> 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("<color=yellow>[MemoryOptimizer]</color> 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("<color=yellow>[MemoryOptimizer]</color> 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)
{
Expand Down
11 changes: 5 additions & 6 deletions Editor/MemoryOptimizerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -345,7 +344,7 @@ void OnAvatarChange()
GUI.enabled = true;
}

if (MemoryOptimizerMain.FindInstallation(avatarFXLayer))
if (MemoryOptimizerMain.IsSystemInstalled(avatarFXLayer))
{
GUI.enabled = false;
GUI.backgroundColor = Color.black;
Expand Down
17 changes: 17 additions & 0 deletions Editor/TESHelperFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit d27b7c2

Please sign in to comment.