modular-avatar/Editor/ReactiveObjects/Simulator/ROSimulatorButton.cs
Haï~ 3b067e4664
Make compatible with Unity 6 projects (#1232)
* Disable compilation for use in Unity 6 (6000.0.20f1):
- Do not compile some classes and code paths in non-VRChat projects.
- This has been tested in Unity 6 (6000.0.20f1).

* Fix hide internal components in Unity 6:
- [AddComponentMenu("")] does not work in Unity 6.
- Replace it with [AddComponentMenu("/")]
- This alternative is confirmed to also work in Unity 2022.

---------

Co-authored-by: Haï~ <hai-vr@users.noreply.github.com>
Co-authored-by: bd_ <bd_@nadena.dev>
2024-10-19 18:58:41 -07:00

56 lines
1.5 KiB
C#

using nadena.dev.modular_avatar.core.editor;
#if MA_VRCSDK3_AVATARS
using nadena.dev.modular_avatar.core.editor.Simulator;
#endif
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace nadena.dev.modular_avatar.core.editor
{
internal class ROSimulatorButton : VisualElement
{
public new class UxmlFactory : UxmlFactory<ROSimulatorButton, UxmlTraits>
{
}
public new class UxmlTraits : VisualElement.UxmlTraits
{
}
private Button btn;
public UnityEngine.Object ReferenceObject;
public static void BindRefObject(VisualElement elem, UnityEngine.Object obj)
{
var button = elem.Q<ROSimulatorButton>();
if (button != null)
{
button.ReferenceObject = obj;
}
}
public ROSimulatorButton()
{
btn = new Button();
btn.AddToClassList("ndmf-tr");
btn.text = "ro_sim.open_debugger_button";
Add(btn);
btn.clicked += OpenDebugger;
}
private void OpenDebugger()
{
#if MA_VRCSDK3_AVATARS
GameObject target = Selection.activeGameObject;
if (ReferenceObject is Component c) target = c.gameObject;
else if (ReferenceObject is GameObject go) target = go;
ROSimulator.OpenDebugger(target);
#endif
}
}
}