Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create Toggle for Selection #1400

Merged
merged 7 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions Editor/Inspector/Menu/ToggleCreatorShortcut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ namespace nadena.dev.modular_avatar.core.editor
{
internal static class ToggleCreatorShortcut
{
[MenuItem(UnityMenuItems.GameObject_CreateToggleForSelection, false, UnityMenuItems.GameObject_CreateToggleForSelectionOrder)]
private static void CreateToggleForSelection(MenuCommand command) => CreateToggleImpl(command, true);

[MenuItem(UnityMenuItems.GameObject_CreateToggle, false, UnityMenuItems.GameObject_CreateToggleOrder)]
private static void CreateToggle()
private static void CreateToggle(MenuCommand command) => CreateToggleImpl(command, false);

private static void CreateToggleImpl(MenuCommand command, bool forSelection)
{
var selected = Selection.activeGameObject;
var selected = command.context as GameObject;
if (selected == null) return;

var avatarRoot = RuntimeUtil.FindAvatarTransformInParents(selected.transform);
if (avatarRoot == null) return;

Expand All @@ -35,10 +40,22 @@ private static void CreateToggle()
{
// ignore
}

var name = forSelection ? selected.name + " Toggle" : "New Toggle";

var toggle = new GameObject("New Toggle");
var toggle = new GameObject(name);

var objToggle = toggle.AddComponent<ModularAvatarObjectToggle>();
if (forSelection)
{
var path = RuntimeUtil.RelativePath(avatarRoot.gameObject, selected);
objToggle.Objects.Add(new ToggledObject
{
Object = new AvatarObjectReference(){ referencePath = path },
Active = !selected.activeSelf
});
}
Comment on lines +52 to +57
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

メニューの状態とオブジェクトの状態を合わせたほうがわかりやすいかも

つまり MenuItemのDefault = activeSelf, Inverted = activeSelf, Active = !activeSelf

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

アニメーションは再生されているものの、Expression Parameterが意図せずオフで固定されるというような状況は、恐らく今も存在すると思うのですが(相手だけ先にアバターが読み込めている時とかFBT Callibration時とか)、その場合もbd_さんの方式(オブジェクトのオンオフにメニューのオンオフを合わせる)の方が良いのでしょうか…?
(意図せず脱げる等が発生しそう)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あー確かに。ただ、それを対策するならMenuItem側で対策したいかな?(同期パラメーターとメニュー用パラメーターを別にするとか)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ふーむ(負荷面であんまりParameter Driver使う箇所を増やさない方が良さそうな感じもしつつ…?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

とりあえず fa4e714 でメニューの状態とオブジェクトの状態を合わせるようにしました。Revertは可能です。
同期された方が基本的に分かりやすいのはあるので悩ましいところではありますが…

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

うーん…MenuItem側で対策できるのはしばらく先なので、やっぱり元の仕様(OFF=基本状態)にいったんしておいて、MenuItem側の対策ができたら変更しましょう。



toggle.transform.SetParent(parent, false);

Expand All @@ -47,7 +64,7 @@ private static void CreateToggle()
mami.Control = new VRCExpressionsMenu.Control
{
type = VRCExpressionsMenu.Control.ControlType.Toggle,
name = "New Toggle",
name = name,
value = 1,
};

Expand Down
5 changes: 4 additions & 1 deletion Runtime/UI/UnityMenuItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ internal static class UnityMenuItems
internal const string GameObject_CreateToggle = "GameObject/Modular Avatar/Create Toggle";
internal const int GameObject_CreateToggleOrder = GameObject_SetupOutfitOrder + 1;

internal const string GameObject_CreateToggleForSelection = "GameObject/Modular Avatar/Create Toggle for Selection";
internal const int GameObject_CreateToggleForSelectionOrder = GameObject_CreateToggleOrder + 1;

internal const string GameObject_ManualBake = "GameObject/Modular Avatar/Manual Bake Avatar";
internal const int GameObject_ManualBakeOrder = GameObject_CreateToggleOrder + 1;
internal const int GameObject_ManualBakeOrder = GameObject_CreateToggleForSelectionOrder + 1;

// <separator>

Expand Down
Loading