Skip to content

Commit

Permalink
0.1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
JeTeeS authored Feb 28, 2024
1 parent 50e0358 commit 4a922c2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 57 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,17 @@
### Changed

- Menu tabs now use Toolbar instead of buttons lol

## [0.1.11] - 2024-2-28

### Added

- Uninstall now properly deletes blendtrees from controller when uninstalling

### Fixed

- Custom folderpath

### Changed

- Minor UI change in settings
4 changes: 2 additions & 2 deletions Editor/MemoryOptimizerMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static bool FindInstallation(AnimatorController controller)

public static void InstallMemOpt(VRCAvatarDescriptor avatarIn, AnimatorController fxLayer, VRCExpressionParameters expressionParameters, List<MemoryOptimizerListData> boolsToOptimize, List<MemoryOptimizerListData> intsNFloatsToOptimize, int syncSteps, float stepDelay, bool generateChangeCheck, int wdOption, string mainFilePath)
{
string generatedAssetsFilePath = mainFilePath + "GeneratedAssets/";
string generatedAssetsFilePath = mainFilePath + "/GeneratedAssets/";
ReadyPath(generatedAssetsFilePath);

MemoryOptimizerState optimizerState = new MemoryOptimizerState
Expand Down Expand Up @@ -654,6 +654,7 @@ public static void UninstallMemOpt(VRCAvatarDescriptor avatar, AnimatorControlle
foreach (AnimatorControllerLayer mainBlendTreeLayer in mainBlendTreeLayers)
{
//Debug.Log("<color=yellow>[MemoryOptimizer]</color> Animator layer " + mainBlendTreeLayer.name + " of index " + fxLayer.FindLayerIndex(mainBlendTreeLayer) + " is being deleted");
DeleteBlendTreeFromAsset((BlendTree)mainBlendTreeLayer.stateMachine.states[0].state.motion);
fxLayer.RemoveLayer(mainBlendTreeLayer);
}

Expand All @@ -671,7 +672,6 @@ public static void UninstallMemOpt(VRCAvatarDescriptor avatar, AnimatorControlle

foreach (AnimatorControllerParameter param in generatedAnimatorParams)
{

//Debug.Log("<color=yellow>[MemoryOptimizer]</color> Controller param " + param.name + " of type: " + param.type + " is being deleted");
fxLayer.RemoveParameter(param);
}
Expand Down
108 changes: 55 additions & 53 deletions Editor/MemoryOptimizerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace JeTeeS.MemoryOptimizer
public class MemoryOptimizerWindow : EditorWindow
{
private const string menuPath = "Tools/TES/MemoryOptimizer";
private const string defaultSavePath = "Assets/TES/MemoryOptimizer/";
private const string defaultSavePath = "Assets/TES/MemOpt";
private string currentSavePath;
DefaultAsset savePathOverride = null;

Expand Down Expand Up @@ -357,80 +357,82 @@ void OnAvatarChange()
{
backupMode = EditorPrefs.GetInt(backUpModeEPKey);
if (backupMode == 0)
MakeBackupOf(new List<UnityEngine.Object> { avatarFXLayer, expressionParameters }, currentSavePath + "Backup/");
MakeBackupOf(new List<UnityEngine.Object> { avatarFXLayer, expressionParameters }, currentSavePath + "/Backup/");
else if (backupMode == 2)
if (EditorUtility.DisplayDialog("", "Do you want to make a backup of your controller and parameters?", "Yes", "No"))
MakeBackupOf(new List<UnityEngine.Object> { avatarFXLayer, expressionParameters }, currentSavePath + "Backup/");
MakeBackupOf(new List<UnityEngine.Object> { avatarFXLayer, expressionParameters }, currentSavePath + "/Backup/");

MemoryOptimizerMain.InstallMemOpt(avatarDescriptor, avatarFXLayer, expressionParameters, boolsToOptimize, intsNFloatsToOptimize, syncSteps, stepDelay, changeCheckEnabled, wdOptionSelected, currentSavePath);
}
}
}
break;
case 1:

unlockSyncSteps = EditorPrefs.GetBool(unlockSyncStepsEPKey);
backupMode = EditorPrefs.GetInt(backUpModeEPKey);
string savePathEP = PlayerPrefs.GetString(savePathPPKey);
if (!String.IsNullOrEmpty(savePathEP) && AssetDatabase.IsValidFolder(savePathEP))
savePathOverride = (DefaultAsset)AssetDatabase.LoadAssetAtPath(savePathEP, typeof(DefaultAsset));

//Backup Mode
using (new SqueezeScope((0, 0, Horizontal, EditorStyles.helpBox)))
using (new SqueezeScope((0,0, Vertical, EditorStyles.helpBox)))
{
EditorGUILayout.LabelField("Backup Mode: ", EditorStyles.boldLabel);
EditorPrefs.SetInt(backUpModeEPKey, EditorGUILayout.Popup(backupMode, backupModes, new GUIStyle(EditorStyles.popup) { fixedHeight = 18, stretchWidth = false }));
}
unlockSyncSteps = EditorPrefs.GetBool(unlockSyncStepsEPKey);
backupMode = EditorPrefs.GetInt(backUpModeEPKey);
string savePathEP = PlayerPrefs.GetString(savePathPPKey);
if (!String.IsNullOrEmpty(savePathEP) && AssetDatabase.IsValidFolder(savePathEP))
savePathOverride = (DefaultAsset)AssetDatabase.LoadAssetAtPath(savePathEP, typeof(DefaultAsset));

//Backup Mode
using (new SqueezeScope((0, 0, Horizontal, EditorStyles.helpBox)))
{
EditorGUILayout.LabelField("Backup Mode: ", EditorStyles.boldLabel);
EditorPrefs.SetInt(backUpModeEPKey, EditorGUILayout.Popup(backupMode, backupModes, new GUIStyle(EditorStyles.popup) { fixedHeight = 18, stretchWidth = false }));
}

GUILayout.Space(5);
GUILayout.Space(5);

//Unlock sync steps button
if (unlockSyncSteps)
GUI.backgroundColor = Color.green;
else
GUI.backgroundColor = Color.red;
if (GUILayout.Button("Unlock sync steps"))
EditorPrefs.SetBool(unlockSyncStepsEPKey, !unlockSyncSteps);
GUI.backgroundColor = Color.white;
//Unlock sync steps button
if (unlockSyncSteps)
GUI.backgroundColor = Color.green;
else
GUI.backgroundColor = Color.red;
if (GUILayout.Button("Unlock sync steps"))
EditorPrefs.SetBool(unlockSyncStepsEPKey, !unlockSyncSteps);
GUI.backgroundColor = Color.white;

GUILayout.Space(5);
GUILayout.Space(5);

//save path
using (new SqueezeScope((0, 0, Vertical, EditorStyles.helpBox)))
{
using (new SqueezeScope((0, 0, Horizontal)))
//save path
using (new SqueezeScope((0, 0, Vertical, EditorStyles.helpBox)))
{
using (new ChangeCheckScope(SavePathChange))
{
EditorGUILayout.LabelField("Select folder to save generated assets to: ");
savePathOverride = (DefaultAsset)EditorGUILayout.ObjectField("", savePathOverride, typeof(DefaultAsset), false);
}
void SavePathChange()
using (new SqueezeScope((0, 0, Horizontal)))
{
PlayerPrefs.SetString(savePathPPKey, AssetDatabase.GetAssetPath(savePathOverride));
using (new ChangeCheckScope(SavePathChange))
{
EditorGUILayout.LabelField("Select folder to save generated assets to: ");
savePathOverride = (DefaultAsset)EditorGUILayout.ObjectField("", savePathOverride, typeof(DefaultAsset), false);
}
void SavePathChange()
{
PlayerPrefs.SetString(savePathPPKey, AssetDatabase.GetAssetPath(savePathOverride));
}
}
}

if (savePathOverride && AssetDatabase.IsValidFolder(AssetDatabase.GetAssetPath(savePathOverride)))
EditorGUILayout.HelpBox($"Valid folder! Now saving to: {currentSavePath}", MessageType.Info, true);
else
EditorGUILayout.HelpBox($"Not valid! Now saving to: {currentSavePath}", MessageType.Info, true);
}
if (savePathOverride && AssetDatabase.IsValidFolder(AssetDatabase.GetAssetPath(savePathOverride)))
EditorGUILayout.HelpBox($"Valid folder! Now saving to: {currentSavePath}", MessageType.Info, true);
else
EditorGUILayout.HelpBox($"Not valid! Now saving to: {currentSavePath}", MessageType.Info, true);
}

GUILayout.Space(5);
GUILayout.Space(5);

//Step delay
using (new SqueezeScope((0, 0, Vertical, EditorStyles.helpBox)))
{
EditorGUILayout.HelpBox($"Not recommended editing!", MessageType.Error, true);
using (new SqueezeScope((0, 0, Horizontal)))
//Step delay
using (new SqueezeScope((0, 0, Vertical, EditorStyles.helpBox)))
{
GUILayout.Label("Step delay", GUILayout.MaxWidth(100));
using (new ChangeCheckScope(OnChangeUpdate))
stepDelay = EditorGUILayout.FloatField(stepDelay);
EditorGUILayout.HelpBox($"Not recommended editing!", MessageType.Error, true);
using (new SqueezeScope((0, 0, Horizontal)))
{
GUILayout.Label("Step delay", GUILayout.MaxWidth(100));
using (new ChangeCheckScope(OnChangeUpdate))
stepDelay = EditorGUILayout.FloatField(stepDelay);
}
if (GUILayout.Button("Reset value"))
stepDelay = 0.2f;
}
if (GUILayout.Button("Reset value"))
stepDelay = 0.2f;
}
break;
}
Expand Down
15 changes: 14 additions & 1 deletion Editor/TESHelperFunctions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
using VRC.SDK3.Avatars.ScriptableObjects;

Expand Down Expand Up @@ -419,6 +419,19 @@ public static void SaveUnsavedBlendtreesToController(BlendTree blendTree, UnityE
}
}

public static void DeleteBlendTreeFromAsset(BlendTree blendTree)
{
Queue<BlendTree> blendTrees = new Queue<BlendTree>();
blendTrees.Enqueue(blendTree);
while (blendTrees.Count > 0)
{
BlendTree subBlendTree = blendTrees.Dequeue();
AssetDatabase.RemoveObjectFromAsset(subBlendTree);
foreach (ChildMotion child in subBlendTree.children)
if (child.motion is BlendTree tree) blendTrees.Enqueue(tree);
}
}

public static AnimatorControllerParameter AddSmoothedVer(this AnimatorControllerParameter param, float minValue, float maxValue, AnimatorController controller, string smoothedParamName, string saveTo, string smoothingAmountParamName = "SmoothingAmount", string mainBlendTreeIdentifier = "MainBlendTree", string mainBlendTreeLayerName = "MainBlendTree", string smoothingParentTreeName = "SmoothingParentTree", string constantOneName = "ConstantOne")
{
BlendTree smoothingParentTree = GetOrGenerateChildTree(controller, smoothingParentTreeName, mainBlendTreeIdentifier, mainBlendTreeLayerName, constantOneName);
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.10",
"version": "0.1.11",
"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 4a922c2

Please sign in to comment.