-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVRCClipboard.cs
141 lines (120 loc) · 4.74 KB
/
VRCClipboard.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MelonLoader;
using UnityEngine;
using VRC;
using VRC.Core;
using VRChatUtilityKit.Utilities;
using UIExpansionKit.API;
using VRC.SDK3.Video.Components.AVPro;
using VRC.SDK3.Components;
using VRC.SDKBase;
using System.Reflection;
using VRC.Udon;
using VRC.SDK3.Video.Components;
using UnityEngine.UI;
namespace VRCClipboard
{
public class VRCClipboard : MelonMod
{
public override void OnApplicationStart()
{
ExpansionKitApi.GetExpandedMenu(ExpandedMenu.QuickMenu).AddSimpleButton("Play URL", ShowVideoMenu);
ExpansionKitApi.GetExpandedMenu(ExpandedMenu.QuickMenu).AddSimpleButton("Play/Pause", PlayPause);
LoggerInstance.Msg("Initialized!");
}
private void ShowVideoMenu()
{
VRCUrlInputField[] foundUrlInputFields = GameObject.FindObjectsOfType<VRCUrlInputField>();
InputField[] foundInputFields = GameObject.FindObjectsOfType<InputField>();
if (foundUrlInputFields.Length == 1 && foundInputFields.Length == 0)
{
VRCUrlInputField inputField = foundUrlInputFields[0];
LoggerInstance.Msg("Found VRCUrlInputField: " + inputField.name);
HandleVRCUrlInputField(inputField);
}
else if(foundUrlInputFields.Length > 1 || foundInputFields.Length > 0)
{
var menu = ExpansionKitApi.CreateCustomQuickMenuPage(LayoutDescription.QuickMenu4Columns);
foreach (VRCUrlInputField inputField in foundUrlInputFields)
{
LoggerInstance.Msg("Found VRCUrlInputField: " + inputField.name);
menu.AddSimpleButton(inputField.name, () => {
HandleVRCUrlInputField(inputField);
});
}
foreach (InputField inputField in foundInputFields)
{
LoggerInstance.Msg("Found InputField: " + inputField.name);
menu.AddSimpleButton(inputField.name, () => {
HandleInputField(inputField);
});
}
menu.Show();
}
else
{
LoggerInstance.Msg("No VRCUrlInputField or InputField found!");
}
}
private void HandleVRCUrlInputField(VRCUrlInputField inputField)
{
VRCUrl url = new VRCUrl(Clipboard);
inputField.SetUrl(url);
inputField.onEndEdit.Invoke(inputField.text);
}
private void HandleInputField(InputField inputField)
{
inputField.text = Clipboard;
inputField.onEndEdit.Invoke(inputField.text);
}
private void PlayPause()
{
string playPauseFunction = "OnPlayButtonPress";
UdonBehaviour[] foundUdonBehaviours = GameObject.FindObjectsOfType<UdonBehaviour>();
List<UdonBehaviour> foundPlayerUdonBehaviours = new List<UdonBehaviour>();
foreach (UdonBehaviour udonBehaviour in foundUdonBehaviours)
{
foreach (string eventName in udonBehaviour.GetPrograms())
{
if(eventName == playPauseFunction)
{
foundPlayerUdonBehaviours.Add(udonBehaviour);
//udonBehaviour.SendCustomEvent(playPauseFunction);
//return;
}
}
}
if (foundPlayerUdonBehaviours.Count == 0)
{
LoggerInstance.Msg("No Player Buttons found!");
}
else if (foundPlayerUdonBehaviours.Count == 1)
{
UdonBehaviour udonBehaviour = foundPlayerUdonBehaviours.First();
LoggerInstance.Msg("Found Button: " + udonBehaviour.name);
udonBehaviour.SendCustomEvent(playPauseFunction);
}
else
{
var menu = ExpansionKitApi.CreateCustomQuickMenuPage(LayoutDescription.QuickMenu4Columns);
foreach (UdonBehaviour udonBehaviour in foundPlayerUdonBehaviours)
{
LoggerInstance.Msg("Found Button: " + udonBehaviour.name);
menu.AddSimpleButton(udonBehaviour.name, () => {
udonBehaviour.SendCustomEvent(playPauseFunction);
});
}
menu.Show();
}
}
public static string Clipboard
{
get { return GUIUtility.systemCopyBuffer; }
set { GUIUtility.systemCopyBuffer = value; }
}
}
}