Skip to content

Commit

Permalink
fix(ui): disable cursor and hologram when menus are open (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenira committed Jan 30, 2024
1 parent 02e48d8 commit a1e753c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,35 @@ namespace TechtonicaVR.VRCamera.Patch;
public class TargetRaycastPatch
{

public static Transform cursorTlc;
public static Transform inspectorTlc;
private static Canvas cursorCanvas;
private static Transform _cursorTlc;
public static Transform cursorTlc
{
get => _cursorTlc;
set
{
_cursorTlc = value;
if (value != null)
{
cursorCanvas = value.GetComponentInParent<Canvas>();
}
}
}

private static Canvas inspectorCanvas;
private static Transform _inspectorTlc;
public static Transform inspectorTlc
{
get => _inspectorTlc;
set
{
_inspectorTlc = value;
if (value != null)
{
inspectorCanvas = value.GetComponentInParent<Canvas>();
}
}
}

[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerFirstPersonController), nameof(PlayerFirstPersonController.UpdateAimingRaycasts))]
Expand Down Expand Up @@ -49,7 +76,15 @@ public static bool UpdateAimingRaycastsPostfix(PlayerFirstPersonController __ins
[HarmonyPatch(typeof(CursorDotUI), nameof(PlayerFirstPersonController.LateUpdate))]
public static void LateUpdatePostfix(CursorDotUI __instance)
{
if (!Player.instance.fpcontroller.hasCamHit || VRCameraManager.mainCamera == null)
if (!Player.instance.fpcontroller.hasCamHit || VRCameraManager.mainCamera == null || cursorCanvas == null || inspectorCanvas == null)
{
return;
}

var anyMenuOpen = UIManager.instance.anyMenuOpen;
cursorCanvas.enabled = !anyMenuOpen;
inspectorCanvas.enabled = !anyMenuOpen;
if (anyMenuOpen)
{
return;
}
Expand Down
14 changes: 14 additions & 0 deletions plugin/src/ui/patch/HologramPreviewManagerPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using HarmonyLib;

namespace TechtonicaVR.UI.Patch;

[Harmony]
public class HologramPreviewManagerPatch
{
[HarmonyPatch(typeof(HologramPreviewManager), nameof(HologramPreviewManager.Update))]
[HarmonyPrefix]
public static bool UpdatePrefix(HologramPreviewManager __instance)
{
return (!UIManager.instance?.anyMenuOpen) ?? true;
}
}

0 comments on commit a1e753c

Please sign in to comment.