mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2024-12-28 10:15:06 +08:00
sync param sequence
This commit is contained in:
parent
f7df59adc1
commit
3a5e6ed5bc
@ -89,6 +89,7 @@ namespace nadena.dev.modular_avatar.core.editor.plugin
|
||||
FixupExpressionsMenuPass.FixupExpressionsMenu(maContext);
|
||||
});
|
||||
seq.Run(RemoveVertexColorPass.Instance);
|
||||
seq.Run(SyncParameterSequencePass.Instance);
|
||||
#endif
|
||||
seq.Run(RebindHumanoidAvatarPass.Instance);
|
||||
seq.Run("Purge ModularAvatar components", ctx =>
|
||||
|
110
Editor/SyncParameterSequencePass.cs
Normal file
110
Editor/SyncParameterSequencePass.cs
Normal file
@ -0,0 +1,110 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using nadena.dev.modular_avatar.editor.ErrorReporting;
|
||||
using nadena.dev.ndmf;
|
||||
using UnityEditor;
|
||||
using VRC.SDK3.Avatars.ScriptableObjects;
|
||||
|
||||
namespace nadena.dev.modular_avatar.core.editor
|
||||
{
|
||||
public class SyncParameterSequencePass : Pass<SyncParameterSequencePass>
|
||||
{
|
||||
private static Platform? CurrentPlatform
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (EditorUserBuildSettings.activeBuildTarget)
|
||||
{
|
||||
case BuildTarget.Android: return Platform.Android;
|
||||
case BuildTarget.iOS: return Platform.iOS;
|
||||
case BuildTarget.StandaloneWindows64: return Platform.PC;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Execute(ndmf.BuildContext context)
|
||||
{
|
||||
var avDesc = context.AvatarDescriptor;
|
||||
|
||||
var components = context.AvatarRootObject.GetComponentsInChildren<ModularAvatarSyncParameterSequence>(true);
|
||||
if (components.Length == 0) return;
|
||||
if (components.Length > 1)
|
||||
{
|
||||
BuildReport.LogFatal("ma.error.TODO.sps.multiple_components", components.Cast<object>().ToArray());
|
||||
return;
|
||||
}
|
||||
|
||||
var syncComponent = components[0];
|
||||
if (syncComponent.Parameters == null) return;
|
||||
|
||||
if (avDesc.expressionParameters == null) return;
|
||||
var avatarParams = avDesc.expressionParameters;
|
||||
|
||||
if (!context.IsTemporaryAsset(avatarParams))
|
||||
{
|
||||
avatarParams = UnityEngine.Object.Instantiate(avatarParams);
|
||||
avDesc.expressionParameters = avatarParams;
|
||||
}
|
||||
|
||||
if (syncComponent.Parameters.parameters == null)
|
||||
{
|
||||
syncComponent.Parameters.parameters = Array.Empty<VRCExpressionParameters.Parameter>();
|
||||
EditorUtility.SetDirty(syncComponent.Parameters);
|
||||
}
|
||||
|
||||
// If we're on the primary platform, add in any unknown parameters, and prune if we exceed the limit.
|
||||
if (CurrentPlatform != null && CurrentPlatform == syncComponent.PrimaryPlatform)
|
||||
{
|
||||
var registered = new OrderedDictionary();
|
||||
|
||||
foreach (var param in syncComponent.Parameters.parameters)
|
||||
{
|
||||
if (param == null) continue;
|
||||
if (!param.networkSynced) continue;
|
||||
registered[param.name] = param;
|
||||
}
|
||||
|
||||
foreach (var param in avatarParams.parameters)
|
||||
{
|
||||
if (param == null) continue;
|
||||
if (!param.networkSynced) continue;
|
||||
registered[param.name] = param;
|
||||
}
|
||||
|
||||
syncComponent.Parameters.parameters = registered.Values.Cast<VRCExpressionParameters.Parameter>().ToArray();
|
||||
if (!syncComponent.Parameters.IsWithinBudget())
|
||||
{
|
||||
var knownParams = avatarParams.parameters.Where(p => p != null).Select(p => p.name).ToHashSet();
|
||||
syncComponent.Parameters.parameters = syncComponent.Parameters.parameters.Where(
|
||||
p => p != null && knownParams.Contains(p.name)
|
||||
).ToArray();
|
||||
}
|
||||
|
||||
EditorUtility.SetDirty(syncComponent.Parameters);
|
||||
}
|
||||
|
||||
// Now copy back...
|
||||
OrderedDictionary finalParams = new();
|
||||
foreach (var param in syncComponent.Parameters.parameters)
|
||||
{
|
||||
if (param == null) continue;
|
||||
if (!param.networkSynced) continue;
|
||||
finalParams[param.name] = param;
|
||||
}
|
||||
|
||||
foreach (var param in avatarParams.parameters)
|
||||
{
|
||||
if (param == null) continue;
|
||||
finalParams[param.name] = param;
|
||||
}
|
||||
|
||||
avatarParams.parameters = finalParams.Values.Cast<VRCExpressionParameters.Parameter>().ToArray();
|
||||
|
||||
EditorUtility.SetDirty(avatarParams);
|
||||
}
|
||||
}
|
||||
}
|
3
Editor/SyncParameterSequencePass.cs.meta
Normal file
3
Editor/SyncParameterSequencePass.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 756425df8aeb4926afceda71bedffa40
|
||||
timeCreated: 1733011801
|
23
Runtime/ModularAvatarSyncParameterSequence.cs
Normal file
23
Runtime/ModularAvatarSyncParameterSequence.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Avatars.ScriptableObjects;
|
||||
|
||||
namespace nadena.dev.modular_avatar.core
|
||||
{
|
||||
[Serializable]
|
||||
public enum Platform
|
||||
{
|
||||
PC,
|
||||
Android,
|
||||
iOS
|
||||
}
|
||||
|
||||
[AddComponentMenu("Modular Avatar/MA Sync Parameter Sequence")]
|
||||
[DisallowMultipleComponent]
|
||||
[HelpURL("https://modular-avatar.nadena.dev/docs/reference/sync-parameter-sequence?lang=auto")]
|
||||
public class ModularAvatarSyncParameterSequence : AvatarTagComponent
|
||||
{
|
||||
public Platform PrimaryPlatform;
|
||||
public VRCExpressionParameters Parameters;
|
||||
}
|
||||
}
|
3
Runtime/ModularAvatarSyncParameterSequence.cs.meta
Normal file
3
Runtime/ModularAvatarSyncParameterSequence.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 934543afe4744213b5621aa13a67e3b4
|
||||
timeCreated: 1733011730
|
Loading…
Reference in New Issue
Block a user