SharedVRCStuff/PlatformSpecificFX/Editor/PlatformSpecificFXPlugin.cs
2026-02-04 21:35:29 -05:00

51 lines
2.1 KiB
C#

using System;
using System.Linq;
using gay.lilyy.platformspecificfx;
using nadena.dev.ndmf;
using nadena.dev.ndmf.vrchat;
using UnityEditor;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
[assembly: ExportsPlugin(typeof(PlatformSpecificFXPlugin))]
namespace gay.lilyy.platformspecificfx
{
public class PlatformSpecificFXPlugin : Plugin<PlatformSpecificFXPlugin>
{
public override string DisplayName => "Platform Specific FX";
public override string QualifiedName => "gay.lilyy.platformspecificfx";
protected override void Configure()
{
InPhase(BuildPhase.FirstChance).Run("PlatformSpecificFX", ctx =>
{
var configs = ctx.AvatarRootObject.GetComponentsInChildren<PlatformSpecificFX>(true);
if (configs == null || configs.Length == 0)
return;
var targetAnimator = EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows
|| EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64 ?
configs[0].desktop : configs[0].mobile;
if (targetAnimator == null) throw new Exception("Target animator not found");
var baseAnimationLayers = ctx.VRChatAvatarDescriptor().baseAnimationLayers.ToList();
// replace the fx layer with the target animator
var foundFXLayer = false;
for (int i = 0; i < baseAnimationLayers.Count; i++)
{
var layer = baseAnimationLayers[i];
if (layer.type == VRCAvatarDescriptor.AnimLayerType.FX) {
Debug.Log($"Found FX Layer, Replacing with {targetAnimator.name}");
layer.animatorController = targetAnimator;
baseAnimationLayers[i] = layer;
foundFXLayer = true;
}
}
if (!foundFXLayer) throw new Exception("FX Layer not found");
ctx.VRChatAvatarDescriptor().baseAnimationLayers = baseAnimationLayers.ToArray();
});
}
}
}