generated from vrchat-community/template-package
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Menus.cs
144 lines (118 loc) · 4.84 KB
/
Menus.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#region
using System;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using nadena.dev.ndmf.config;
using nadena.dev.ndmf.runtime;
using UnityEditor;
using UnityEngine;
using UnityEngine.Profiling;
using UnityObject = UnityEngine.Object;
#endregion
namespace nadena.dev.ndmf.ui
{
internal static class Menus
{
private const string APPLY_ON_PLAY_MENU_NAME = "Tools/NDM Framework/Apply on Play";
private const string TOPLEVEL_MANUAL_BAKE_MENU_NAME = "Tools/NDM Framework/Manual bake avatar";
private const int APPLY_ON_PLAY_PRIO = 1;
private const int TOPLEVEL_MANUAL_BAKE_PRIO = 2;
[InitializeOnLoadMethod]
static void Init()
{
EditorApplication.delayCall += OnSettingsChanged;
Config.OnChange += OnSettingsChanged;
}
// Avoid cluttering the GameObject context menu with duplicate entries. Users are more familiar with MA anyway,
// so we'll keep that entry.
#if !MODULAR_AVATAR
[MenuItem("GameObject/[NDMF] Manual bake avatar", true, 49)]
private static bool ValidateManualBakeGameObject()
{
return AvatarProcessor.CanProcessObject(Selection.activeGameObject);
}
[MenuItem("GameObject/[NDMF] Manual bake avatar", false, 49)]
private static void ManualBakeGameObject()
{
AvatarProcessor.ProcessAvatarUI(Selection.activeGameObject);
}
#endif
[MenuItem(TOPLEVEL_MANUAL_BAKE_MENU_NAME, true, TOPLEVEL_MANUAL_BAKE_PRIO)]
private static bool ValidateManualBakeToplevel()
{
return AvatarProcessor.CanProcessObject(Selection.activeGameObject);
}
[MenuItem(TOPLEVEL_MANUAL_BAKE_MENU_NAME, false, TOPLEVEL_MANUAL_BAKE_PRIO)]
private static void ManualBakeToplevel()
{
AvatarProcessor.ProcessAvatarUI(Selection.activeGameObject);
}
[MenuItem(APPLY_ON_PLAY_MENU_NAME, false, APPLY_ON_PLAY_PRIO)]
private static void ApplyOnPlay()
{
Config.ApplyOnPlay = !Config.ApplyOnPlay;
}
private static void OnSettingsChanged()
{
Menu.SetChecked(APPLY_ON_PLAY_MENU_NAME, Config.ApplyOnPlay);
}
#if UNITY_2022_1_OR_NEWER
[MenuItem("Tools/NDM Framework/Debug Tools/Profile build", false, 101)]
private static void ProfileBuild()
{
var av = Selection.activeGameObject;
IEnumerator coro = ProfileBuildCoro(av);
EditorApplication.CallbackFunction updateCall = null;
updateCall = () =>
{
if (coro == null)
{
EditorApplication.update -= updateCall;
}
else
{
coro.MoveNext();
}
};
EditorApplication.update += updateCall;
}
[MenuItem("Tools/NDM Framework/Debug Tools/Profile build", true, 101)]
private static bool ProfileBuild_Validate()
{
return Selection.activeGameObject != null
&& RuntimeUtil.IsAvatarRoot(Selection.activeGameObject.transform);
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
private static IEnumerator ProfileBuildCoro(GameObject av)
{
Type ty_PW = typeof(ProfilerWindow);
MethodInfo m_OnTargetedEditorConnectionChanged =
ty_PW.GetMethod("OnTargetedEditorConnectionChanged", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo m_SetRecordingEnabled =
ty_PW.GetMethod("SetRecordingEnabled", BindingFlags.Instance | BindingFlags.NonPublic);
Type ty_EditorConnectionTarget = m_OnTargetedEditorConnectionChanged.GetParameters()[0].ParameterType;
var MainEditorProcessEditmode = Enum.Parse(ty_EditorConnectionTarget, "MainEditorProcessEditmode");
var profWindow = EditorWindow.GetWindow<ProfilerWindow>();
m_OnTargetedEditorConnectionChanged.Invoke(profWindow, new object[] { MainEditorProcessEditmode });
m_SetRecordingEnabled.Invoke(profWindow, new object[] { true });
yield return null; // wait one frame
if (av == null) yield break;
var clone = UnityEngine.Object.Instantiate(av);
try
{
AvatarProcessor.ProcessAvatar(clone);
}
catch (Exception e)
{
Debug.LogException(e);
}
//yield return null;
m_SetRecordingEnabled.Invoke(profWindow, new object[] { false });
yield return null;
UnityEngine.Object.DestroyImmediate(clone);
AvatarProcessor.CleanTemporaryAssets();
}
#endif
}
}