2023-11-10 14:37:56 +08:00
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
|
|
|
|
|
|
|
|
|
using System;
|
2023-05-17 19:19:05 +08:00
|
|
|
|
using System.Collections.Generic;
|
2023-04-15 18:17:30 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using VRC.SDKBase;
|
|
|
|
|
using VRC.SDKBase.Editor.BuildPipeline;
|
2023-05-17 19:19:05 +08:00
|
|
|
|
using Object = UnityEngine.Object;
|
2023-04-15 18:17:30 +08:00
|
|
|
|
|
|
|
|
|
namespace nadena.dev.modular_avatar.core.editor
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// See https://feedback.vrchat.com/sdk-bug-reports/p/ieditoronly-components-should-be-destroyed-late-in-the-build-process
|
|
|
|
|
/// </summary>
|
|
|
|
|
[InitializeOnLoad]
|
|
|
|
|
internal static class PreventStripTagObjects
|
|
|
|
|
{
|
|
|
|
|
static PreventStripTagObjects()
|
|
|
|
|
{
|
|
|
|
|
EditorApplication.delayCall += () =>
|
|
|
|
|
{
|
|
|
|
|
var f_callbacks = typeof(VRCBuildPipelineCallbacks).GetField("_preprocessAvatarCallbacks",
|
|
|
|
|
BindingFlags.Static | BindingFlags.NonPublic);
|
|
|
|
|
var callbacks = (List<IVRCSDKPreprocessAvatarCallback>) f_callbacks.GetValue(null);
|
|
|
|
|
|
|
|
|
|
var filteredCallbacks = callbacks.Where(c => !(c is RemoveAvatarEditorOnly)).ToList();
|
|
|
|
|
|
|
|
|
|
f_callbacks.SetValue(null, filteredCallbacks);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class ReplacementRemoveAvatarEditorOnly : IVRCSDKPreprocessAvatarCallback
|
|
|
|
|
{
|
|
|
|
|
public int callbackOrder => -1024;
|
|
|
|
|
|
|
|
|
|
public bool OnPreprocessAvatar(GameObject avatarGameObject)
|
|
|
|
|
{
|
|
|
|
|
foreach (var xform in avatarGameObject.GetComponentsInChildren<Transform>(true))
|
|
|
|
|
{
|
|
|
|
|
if (xform != null && xform.CompareTag("EditorOnly"))
|
|
|
|
|
{
|
|
|
|
|
Object.DestroyImmediate(xform.gameObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 19:19:05 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-15 18:17:30 +08:00
|
|
|
|
|
2023-05-17 19:19:05 +08:00
|
|
|
|
internal class ReplacementRemoveIEditorOnly : IVRCSDKPreprocessAvatarCallback
|
|
|
|
|
{
|
|
|
|
|
public int callbackOrder => Int32.MaxValue;
|
|
|
|
|
|
|
|
|
|
public bool OnPreprocessAvatar(GameObject avatarGameObject)
|
|
|
|
|
{
|
|
|
|
|
foreach (var component in avatarGameObject.GetComponentsInChildren<IEditorOnly>(true))
|
|
|
|
|
{
|
|
|
|
|
Object.DestroyImmediate(component as Object);
|
2023-04-15 18:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-10 14:37:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|