mirror of
https://github.com/rmroc451/TweaksAndThings.git
synced 2025-12-16 09:19:37 -06:00
Merge pull request #36 from rmroc451/33-double-click-to-follow-car
#33 double primary click any car/loco to follow
This commit is contained in:
52
TweaksAndThings/Patches/CarPickable_Activate_Patch.cs
Normal file
52
TweaksAndThings/Patches/CarPickable_Activate_Patch.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using Railloader;
|
||||||
|
using RollingStock;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
||||||
|
namespace RMROC451.TweaksAndThings.Patches;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(CarPickable))]
|
||||||
|
[HarmonyPatch(nameof(CarPickable.Activate), typeof(PickableActivateEvent))]
|
||||||
|
[HarmonyPatchCategory("RMROC451TweaksAndThings")]
|
||||||
|
internal class CarPickable_Activate_Patch
|
||||||
|
{
|
||||||
|
|
||||||
|
static float clicked = 0;
|
||||||
|
static float clicktime = 0;
|
||||||
|
static float clickdelay = 0.5f;
|
||||||
|
|
||||||
|
private static bool Prefix(CarPickable __instance, PickableActivateEvent evt)
|
||||||
|
{
|
||||||
|
TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase<TweaksAndThingsPlugin>.Shared;
|
||||||
|
if (!tweaksAndThings.IsEnabled) return true;
|
||||||
|
|
||||||
|
if (OnPointerDown(evt))
|
||||||
|
{
|
||||||
|
CameraSelector.shared.FollowCar(__instance.car);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool OnPointerDown(PickableActivateEvent evt)
|
||||||
|
{
|
||||||
|
bool output = false;
|
||||||
|
if (evt.Activation == PickableActivation.Primary)
|
||||||
|
{
|
||||||
|
clicked++;
|
||||||
|
if (clicked == 1) clicktime = Time.time;
|
||||||
|
|
||||||
|
if (clicked > 1 && Time.time - clicktime < clickdelay)
|
||||||
|
{
|
||||||
|
clicked = 0;
|
||||||
|
clicktime = 0;
|
||||||
|
output = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (clicked > 2 || Time.time - clicktime > 1) clicked = 0;
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user