-
Notifications
You must be signed in to change notification settings - Fork 2
/
VrcPlayspaceMover.cs
112 lines (94 loc) · 3.46 KB
/
VrcPlayspaceMover.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using UnityEngine;
using System.Diagnostics;
using MelonLoader;
using Object = UnityEngine.Object;
using UnhollowerRuntimeLib;
[assembly: MelonInfo(typeof(VrcPlayspaceMover.VrcPlayspaceMover),
"VrcPlayspaceMover",
"1.0.0",
"avail",
"https://github.com/nekoclient/VrcOculusPlayspace/releases")]
[assembly: MelonGame("VRChat", "VRChat")]
namespace VrcPlayspaceMover
{
public class VrcPlayspaceMover : MelonMod
{
private static Dictionary<OVRInput.Button, bool> ms_wasPressed = new Dictionary<OVRInput.Button, bool>()
{
{ OVRInput.Button.Three, false },
{ OVRInput.Button.One, false }
};
private static bool IsKeyJustPressed(OVRInput.Button key)
{
if (!ms_wasPressed.ContainsKey(key))
{
ms_wasPressed.Add(key, false);
}
if (OVRInput.Get(key, OVRInput.Controller.Touch))
{
if (!ms_wasPressed[key])
{
ms_wasPressed[key] = true;
return true;
}
}
else
{
if (ms_wasPressed[key])
{
ms_wasPressed[key] = false;
}
}
return false;
}
private Vector3 m_startingOffset = new Vector3();
public override void OnUpdate()
{
bool leftJustPressed = IsKeyJustPressed(OVRInput.Button.Three);
bool rightJustPressed = IsKeyJustPressed(OVRInput.Button.One);
if (leftJustPressed)
{
m_startingOffset = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch);
}
if (rightJustPressed)
{
m_startingOffset = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);
}
bool leftTrigger = OVRInput.Get(OVRInput.Button.Three, OVRInput.Controller.Touch);
bool rightTrigger = OVRInput.Get(OVRInput.Button.One, OVRInput.Controller.Touch);
if (leftTrigger || rightTrigger)
{
Object[] ctrls = Object.FindObjectsOfType(Il2CppType.Of<VRCVrCameraOculus>());
VRCVrCameraOculus ctrl;
if (ctrls.Length > 0)
{
ctrl = ctrls[0].TryCast<VRCVrCameraOculus>();
}
else
{
Trace.WriteLine("camera not found?");
return;
}
if (leftTrigger)
{
Vector3 currentOffset = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch);
Vector3 calculatedOffset = (currentOffset - m_startingOffset) * -1.0f;
m_startingOffset = currentOffset;
ctrl.cameraLiftTransform.localPosition += calculatedOffset;
}
if (rightTrigger)
{
Vector3 currentOffset = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);
Vector3 calculatedOffset = (currentOffset - m_startingOffset) * -1.0f;
m_startingOffset = currentOffset;
ctrl.cameraLiftTransform.localPosition += calculatedOffset;
}
}
}
}
}