mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-21 14:00:08 +08:00
Add warnings to menu installer
This commit is contained in:
parent
ea623a3030
commit
ff75670ac9
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using VRC.SDK3.Avatars.Components;
|
||||||
using VRC.SDK3.Avatars.ScriptableObjects;
|
using VRC.SDK3.Avatars.ScriptableObjects;
|
||||||
|
|
||||||
namespace net.fushizen.modular_avatar.core.editor
|
namespace net.fushizen.modular_avatar.core.editor
|
||||||
@ -16,9 +18,13 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
private bool _menuFoldout;
|
private bool _menuFoldout;
|
||||||
private bool _devFoldout;
|
private bool _devFoldout;
|
||||||
|
|
||||||
|
private HashSet<VRCExpressionsMenu> _avatarMenus;
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
_installer = (ModularAvatarMenuInstaller) target;
|
_installer = (ModularAvatarMenuInstaller) target;
|
||||||
|
|
||||||
|
FindMenus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupMenuEditor()
|
private void SetupMenuEditor()
|
||||||
@ -45,6 +51,24 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
SetupMenuEditor();
|
SetupMenuEditor();
|
||||||
|
|
||||||
var installTo = serializedObject.FindProperty(nameof(ModularAvatarMenuInstaller.installTargetMenu));
|
var installTo = serializedObject.FindProperty(nameof(ModularAvatarMenuInstaller.installTargetMenu));
|
||||||
|
|
||||||
|
if (!installTo.hasMultipleDifferentValues)
|
||||||
|
{
|
||||||
|
if (installTo.objectReferenceValue == null)
|
||||||
|
{
|
||||||
|
EditorGUILayout.HelpBox(
|
||||||
|
"Select one of your avatar's menus below to automatically install controls for this prefab."
|
||||||
|
, MessageType.Info);
|
||||||
|
}
|
||||||
|
else if (!IsMenuReachable(RuntimeUtil.FindAvatarInParents(((Component) target).transform),
|
||||||
|
(VRCExpressionsMenu) installTo.objectReferenceValue))
|
||||||
|
{
|
||||||
|
EditorGUILayout.HelpBox(
|
||||||
|
"Selected menu asset is not part of your avatar."
|
||||||
|
, MessageType.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(installTo, new GUIContent("Install To"));
|
EditorGUILayout.PropertyField(installTo, new GUIContent("Install To"));
|
||||||
|
|
||||||
var avatar = RuntimeUtil.FindAvatarInParents(_installer.transform);
|
var avatar = RuntimeUtil.FindAvatarInParents(_installer.transform);
|
||||||
@ -86,5 +110,40 @@ namespace net.fushizen.modular_avatar.core.editor
|
|||||||
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FindMenus()
|
||||||
|
{
|
||||||
|
if (targets.Length > 1)
|
||||||
|
{
|
||||||
|
_avatarMenus = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_avatarMenus = new HashSet<VRCExpressionsMenu>();
|
||||||
|
var queue = new Queue<VRCExpressionsMenu>();
|
||||||
|
var avatar = RuntimeUtil.FindAvatarInParents(((Component) target).transform);
|
||||||
|
if (avatar == null || avatar.expressionsMenu == null) return;
|
||||||
|
queue.Enqueue(avatar.expressionsMenu);
|
||||||
|
|
||||||
|
while (queue.Count > 0)
|
||||||
|
{
|
||||||
|
var menu = queue.Dequeue();
|
||||||
|
if (_avatarMenus.Contains(menu)) continue;
|
||||||
|
|
||||||
|
_avatarMenus.Add(menu);
|
||||||
|
foreach (var subMenu in menu.controls)
|
||||||
|
{
|
||||||
|
if (subMenu.type == VRCExpressionsMenu.Control.ControlType.SubMenu)
|
||||||
|
{
|
||||||
|
queue.Enqueue(subMenu.subMenu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsMenuReachable(VRCAvatarDescriptor avatar, VRCExpressionsMenu menu)
|
||||||
|
{
|
||||||
|
return _avatarMenus == null || _avatarMenus.Contains(menu);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user