mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-06 14:45:06 +08:00
6b99b763a7
* ui: adjustments to reactive object UI * ui: toggle creation shortcuts
62 lines
2.1 KiB
C#
62 lines
2.1 KiB
C#
using nadena.dev.modular_avatar.ui;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using VRC.SDK3.Avatars.ScriptableObjects;
|
|
|
|
namespace nadena.dev.modular_avatar.core.editor
|
|
{
|
|
internal static class ToggleCreatorShortcut
|
|
{
|
|
[MenuItem(UnityMenuItems.GameObject_CreateToggle, false, UnityMenuItems.GameObject_CreateToggleOrder)]
|
|
private static void CreateToggle()
|
|
{
|
|
var selected = Selection.activeGameObject;
|
|
if (selected == null) return;
|
|
|
|
var avatarRoot = RuntimeUtil.FindAvatarTransformInParents(selected.transform);
|
|
if (avatarRoot == null) return;
|
|
|
|
bool createInstaller = true;
|
|
Transform parent = avatarRoot;
|
|
|
|
try
|
|
{
|
|
var selectedMenuItem = selected.GetComponent<ModularAvatarMenuItem>();
|
|
if (selectedMenuItem?.Control?.type == VRCExpressionsMenu.Control.ControlType.SubMenu
|
|
&& selectedMenuItem.MenuSource == SubmenuSource.Children
|
|
)
|
|
{
|
|
parent = selected.transform;
|
|
createInstaller = false;
|
|
}
|
|
}
|
|
catch (MissingComponentException e)
|
|
{
|
|
// ignore
|
|
}
|
|
|
|
var toggle = new GameObject("New Toggle");
|
|
|
|
var objToggle = toggle.AddComponent<ModularAvatarObjectToggle>();
|
|
|
|
toggle.transform.SetParent(parent, false);
|
|
toggle.AddComponent<ModularAvatarMenuItem>().Control = new VRCExpressionsMenu.Control
|
|
{
|
|
type = VRCExpressionsMenu.Control.ControlType.Toggle,
|
|
name = "New Toggle",
|
|
value = 1,
|
|
};
|
|
|
|
if (createInstaller)
|
|
{
|
|
toggle.AddComponent<ModularAvatarMenuInstaller>();
|
|
}
|
|
|
|
Selection.activeGameObject = toggle;
|
|
EditorGUIUtility.PingObject(objToggle);
|
|
|
|
|
|
Undo.RegisterCreatedObjectUndo(toggle, "Create Toggle");
|
|
}
|
|
}
|
|
} |