-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMultiAvatarManager.cs
75 lines (64 loc) · 2.65 KB
/
MultiAvatarManager.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
using UnityEditor;
using UnityEngine;
using VRC.Core;
#if VRCHAT_API_TOOLS_IMPORTED
using BocuD.VRChatApiTools;
#endif
namespace AvatarImageReader.Editor
{
public class MultiAvatarManager : EditorWindow
{
public static void SpawnEditor(RuntimeDecoderEditor prefabEditor)
{
MultiAvatarManager window = GetWindow<MultiAvatarManager>();
window.titleContent = new GUIContent("Linked Avatar Editor");
window.minSize = new Vector2(450, 400);
window.prefabEditor = prefabEditor;
}
public RuntimeDecoderEditor prefabEditor;
private Vector2 scrollView;
#if VRCHAT_API_TOOLS_IMPORTED
private void OnGUI()
{
EditorGUILayout.LabelField($"Multi Avatar Manager for {prefabEditor.reader.name}");
scrollView = EditorGUILayout.BeginScrollView(scrollView);
bool ownershipError = false;
for (int a = 0; a < prefabEditor.reader.linkedAvatars.Length; a++)
{
VRChatApiToolsGUI.DrawBlueprintInspector(prefabEditor.reader.linkedAvatars[a], true, () =>
{
if (GUILayout.Button("Change Avatar"))
{
BlueprintPicker.BlueprintSelector<ApiAvatar>(avatar => prefabEditor.AvatarSelected(avatar, a));
}
if (GUILayout.Button("Remove Avatar"))
{
ArrayUtility.RemoveAt(ref prefabEditor.reader.linkedAvatars, a);
prefabEditor.OnLinkedAvatarsUpdated();
}
});
if (VRChatApiTools.blueprintCache.TryGetValue(prefabEditor.reader.linkedAvatars[a], out ApiModel m))
{
if (m is ApiAvatar avatar && avatar.authorId != APIUser.CurrentUser.id)
{
ownershipError = true;
}
}
}
if (ownershipError)
{
EditorGUILayout.HelpBox("One or more avatars isn't owned by the currently logged in user",
MessageType.Error);
}
EditorGUILayout.EndScrollView();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Current avatar count: ", prefabEditor.reader.linkedAvatars.Length.ToString());
if (GUILayout.Button("Add new Avatar"))
{
BlueprintPicker.BlueprintSelector<ApiAvatar>(avatar => prefabEditor.AvatarSelected(avatar, prefabEditor.reader.linkedAvatars.Length));
}
EditorGUILayout.EndHorizontal();
}
#endif
}
}