better param merger
This commit is contained in:
parent
b475edd583
commit
54c79328f6
13 changed files with 233 additions and 0 deletions
8
BetterParamMerger.meta
Normal file
8
BetterParamMerger.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 917617695c0f94e469af3fcfb5755f3d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
BetterParamMerger/Editor.meta
Normal file
8
BetterParamMerger/Editor.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: add4c1d2bfc13434eb90de2d72e1b0a4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
BetterParamMerger/Editor/BetterParamMergerConfigEditor.cs
Normal file
19
BetterParamMerger/Editor/BetterParamMergerConfigEditor.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using gay.lilyy.BetterParamMerger;
|
||||
|
||||
namespace gay.lilyy.BetterParamMerger
|
||||
{
|
||||
[CustomEditor(typeof(BetterParamMergerConfig))]
|
||||
public class BetterParamMergerConfigEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.HelpBox("This merges parameters in the optimizing stage, making sure it runs after all other preprocessors", MessageType.Info);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
DrawDefaultInspector();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2164453d75bb637449b08caccd62991e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "BetterParamMergerEditorAsmdef",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:62ced99b048af7f4d8dfe4bed8373d76",
|
||||
"GUID:5718fb738711cd34ea54e9553040911d",
|
||||
"GUID:901e56b065a857d4483a77f8cae73588",
|
||||
"GUID:209cbd2a789c4f72963fdbf1f8a01909",
|
||||
"GUID:901acb251964b054b93b9c13e801eabd"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ad9a12eb44c834641a47b41e7bd0d17d
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
104
BetterParamMerger/Editor/BetterParamMergerPlugin.cs
Normal file
104
BetterParamMerger/Editor/BetterParamMergerPlugin.cs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using gay.lilyy.Common;
|
||||
using gay.lilyy.BetterParamMerger;
|
||||
using nadena.dev.ndmf;
|
||||
using nadena.dev.ndmf.vrchat;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Avatars.ScriptableObjects;
|
||||
|
||||
[assembly: ExportsPlugin(typeof(BetterParamMergerPlugin))]
|
||||
|
||||
namespace gay.lilyy.BetterParamMerger
|
||||
{
|
||||
public class BetterParamMergerPlugin : Plugin<BetterParamMergerPlugin>
|
||||
{
|
||||
public override string DisplayName => "Better Param Merger";
|
||||
public override string QualifiedName => "gay.lilyy.BetterParamMerger";
|
||||
|
||||
protected override void Configure()
|
||||
{
|
||||
InPhase(BuildPhase.Optimizing).Run("MergeParameters", ctx =>
|
||||
{
|
||||
var configs = ctx.AvatarRootObject.GetComponentsInChildren<BetterParamMergerConfig>(true);
|
||||
if (configs == null || configs.Length == 0)
|
||||
return;
|
||||
|
||||
var descriptor = ctx.VRChatAvatarDescriptor();
|
||||
if (descriptor.expressionParameters == null)
|
||||
{
|
||||
Debug.LogWarning($"[Better Param Merger] No expression parameters found on avatar {ctx.AvatarRootObject.name}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Duplicate the parameters asset to avoid modifying the original
|
||||
var originalParams = descriptor.expressionParameters;
|
||||
var newParams = ScriptableObject.CreateInstance<VRCExpressionParameters>();
|
||||
var paramList = new List<VRCExpressionParameters.Parameter>();
|
||||
if (originalParams.parameters != null)
|
||||
{
|
||||
paramList.AddRange(originalParams.parameters);
|
||||
}
|
||||
newParams.parameters = paramList.ToArray();
|
||||
|
||||
// Create a dictionary for quick lookup of existing parameters by name
|
||||
var paramDict = paramList.ToDictionary(p => p.name, p => p);
|
||||
|
||||
// Iterate over all config components
|
||||
foreach (var config in configs)
|
||||
{
|
||||
if (config == null || config.parameterAssets == null)
|
||||
continue;
|
||||
|
||||
// Iterate over all VRCExpressionParameters assets in this config
|
||||
foreach (var paramAsset in config.parameterAssets)
|
||||
{
|
||||
if (paramAsset == null || paramAsset.parameters == null)
|
||||
continue;
|
||||
|
||||
// Iterate over all parameters in this asset
|
||||
foreach (var param in paramAsset.parameters)
|
||||
{
|
||||
if (string.IsNullOrEmpty(param.name))
|
||||
continue;
|
||||
|
||||
if (paramDict.ContainsKey(param.name))
|
||||
{
|
||||
// Parameter exists - update its settings
|
||||
var existingParam = paramDict[param.name];
|
||||
existingParam.valueType = param.valueType;
|
||||
existingParam.defaultValue = param.defaultValue;
|
||||
existingParam.saved = param.saved;
|
||||
existingParam.networkSynced = param.networkSynced;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Parameter doesn't exist - add it
|
||||
var newParam = new VRCExpressionParameters.Parameter
|
||||
{
|
||||
name = param.name,
|
||||
valueType = param.valueType,
|
||||
defaultValue = param.defaultValue,
|
||||
saved = param.saved,
|
||||
networkSynced = param.networkSynced
|
||||
};
|
||||
paramList.Add(newParam);
|
||||
paramDict[param.name] = newParam;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy the config component after processing
|
||||
Object.DestroyImmediate(config);
|
||||
}
|
||||
|
||||
// Update the parameters array from the list
|
||||
newParams.parameters = paramList.ToArray();
|
||||
|
||||
// Assign the new parameters asset to the descriptor
|
||||
descriptor.expressionParameters = newParams;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
BetterParamMerger/Editor/BetterParamMergerPlugin.cs.meta
Normal file
11
BetterParamMerger/Editor/BetterParamMergerPlugin.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1520255993057634180ba08b172d3547
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
BetterParamMerger/Runtime.meta
Normal file
8
BetterParamMerger/Runtime.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ba35c9429c286124185d3bcad6d24ec7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
BetterParamMerger/Runtime/BetterParamMergerConfig.cs
Normal file
13
BetterParamMerger/Runtime/BetterParamMergerConfig.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Avatars.ScriptableObjects;
|
||||
|
||||
namespace gay.lilyy.BetterParamMerger
|
||||
{
|
||||
[AddComponentMenu("LillithRosePup/VRCExpressionParameters/Better Param Merger")]
|
||||
public class BetterParamMergerConfig : MonoBehaviour, VRC.SDKBase.IEditorOnly
|
||||
{
|
||||
public List<VRCExpressionParameters> parameterAssets = new List<VRCExpressionParameters>();
|
||||
}
|
||||
}
|
||||
|
||||
11
BetterParamMerger/Runtime/BetterParamMergerConfig.cs.meta
Normal file
11
BetterParamMerger/Runtime/BetterParamMergerConfig.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 592d18cd1923357478b77252c450ded9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name": "BetterParamMergerRuntimeAsmdef"
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 901acb251964b054b93b9c13e801eabd
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue