-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
ShipHorn.cs
90 lines (71 loc) · 2.63 KB
/
ShipHorn.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
using HarmonyLib;
using LCVR.Assets;
using LCVR.Patches;
using LCVR.Player;
using UnityEngine;
namespace LCVR.Physics.Interactions;
internal class ShipHorn : MonoBehaviour, VRInteractable
{
private ShipAlarmCord shipHorn;
private InteractTrigger trigger;
private Animator animator;
private Transform pullCord;
private Transform targetTransform;
private float grabYPosition;
public InteractableFlags Flags => InteractableFlags.BothHands;
private void Awake()
{
shipHorn = GetComponentInParent<ShipAlarmCord>();
trigger = GetComponentInParent<InteractTrigger>();
animator = GetComponentInParent<Animator>();
pullCord = transform.parent.parent;
}
private void Update()
{
if (targetTransform is null)
return;
var heightOffset = Mathf.Clamp(targetTransform.position.y - grabYPosition, -0.105f, 0);
pullCord.localPosition = new Vector3(pullCord.transform.localPosition.x, 2.994f + heightOffset, pullCord.localPosition.z);
if (heightOffset < -0.08f)
shipHorn.HoldCordDown();
}
public bool OnButtonPress(VRInteractor interactor)
{
if (shipHorn.otherClientHoldingCord || !trigger.interactable)
return false;
targetTransform = interactor.transform;
animator.enabled = false;
grabYPosition = targetTransform.position.y;
interactor.FingerCurler.ForceFist(true);
return true;
}
public void OnButtonRelease(VRInteractor interactor)
{
if (targetTransform is not null)
{
shipHorn.StopHorn();
targetTransform = null;
animator.enabled = true;
}
interactor.FingerCurler.ForceFist(false);
}
public void OnColliderEnter(VRInteractor _) { }
public void OnColliderExit(VRInteractor _) { }
}
[LCVRPatch]
[HarmonyPatch]
internal static class ShipAlarmCordPatches
{
[HarmonyPatch(typeof(ShipAlarmCord), nameof(ShipAlarmCord.Start))]
[HarmonyPostfix]
private static void OnShipHornInitialized(ShipAlarmCord __instance)
{
if (Plugin.Config.DisableShipHornInteraction.Value)
return;
__instance.gameObject.name = "ShipHornPullInteractable";
var interactableObject = Object.Instantiate(AssetManager.Interactable, __instance.transform);
interactableObject.transform.localPosition = new Vector3(0, 0, -0.28f);
interactableObject.transform.localScale = Vector3.one * 0.33f;
interactableObject.AddComponent<ShipHorn>();
}
}