Repository navigation
Expand file tree
/
Copy pathWaypointModule.cs
More file actions
61 lines (49 loc) · 2.09 KB
/
Copy pathWaypointModule.cs
File metadata and controls
61 lines (49 loc) · 2.09 KB
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
using UnityEngine;
using FairPlay.Core;
using FairPlay.Utils;
namespace FairPlay.Modules
{
/// <summary>
/// Saves one spot and teleports you back to it.
///
/// Menu-hand face button saves, free-hand face button returns. Only your own transform is
/// moved, and only to a place you personally stood, so this cannot be used to reach anywhere
/// you could not already walk to.
/// </summary>
public sealed class WaypointModule : Module
{
public override string Name => "Waypoint";
public override string Description => "A/X saves, other A/X returns";
public override ModuleCategory Category => ModuleCategory.Builder;
/// <summary>Shared with <see cref="BeaconModule"/> so the marker can be drawn.</summary>
public static Vector3? Saved { get; private set; }
/// <summary>
/// Dropped on a scene change. Coordinates do not survive one, and a stale waypoint means
/// Beacon plants a light column at a spot that no longer means anything.
/// </summary>
internal static void Forget() => Saved = null;
private static bool MenuHandIsLeft => Settings.MenuHand.Value == Handedness.Left;
public override void Tick()
{
XRInput.Sample();
if (XRInput.PrimaryDown(MenuHandIsLeft)) Save();
if (XRInput.PrimaryDown(!MenuHandIsLeft)) Return();
}
private void Save()
{
Transform root = GameRefs.Root;
if (root == null) return;
Saved = root.position;
if (Settings.Haptics.Value) GameRefs.Vibrate(MenuHandIsLeft, 0.5f, 0.05f);
Plugin.Log.LogInfo("Waypoint saved at " + Saved.Value.ToString("F1"));
}
private void Return()
{
if (!Saved.HasValue) return;
GameRefs.TeleportTo(Saved.Value);
if (Settings.Haptics.Value) GameRefs.Vibrate(!MenuHandIsLeft, 0.8f, 0.08f);
}
/// <summary>The saved point is deliberately kept across a toggle; nothing to undo.</summary>
public override void Revert() { }
}
}