Advertisement
ihatetn931

Untitled

May 9th, 2021
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using HarmonyLib;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using UnityEngine.UI;
  5.  
  6. namespace VRTweaks.Fixes
  7. {
  8.     class gazeLayerFix
  9.     {
  10.         public static bool actualGazedBasedCursor;
  11.  
  12.         [HarmonyPatch(typeof(FPSInputModule), "UpdateCursor")]
  13.         public static class UpdateCursorPrefix
  14.         {
  15.             [HarmonyPrefix]
  16.             public static void Prefix(FPSInputModule __instance)
  17.             {
  18.                 //save the original value so we can set it back in the postfix
  19.                 actualGazedBasedCursor = VROptions.gazeBasedCursor;
  20.                 //trying make flag in UpdateCursor be true if Cursor.lockState != CursorLockMode.Locked)
  21.                 if (Cursor.lockState != CursorLockMode.Locked)
  22.                 {
  23.                     VROptions.gazeBasedCursor = true;
  24.                 }
  25.             }
  26.         }
  27.  
  28.         [HarmonyPatch(typeof(FPSInputModule), "UpdateCursor")]
  29.         public static class UpdateCursorPostfix
  30.         {
  31.             [HarmonyPostfix]
  32.             public static void UpdateCursor_Postfix(FPSInputModule __instance)
  33.             {
  34.                 VROptions.gazeBasedCursor = actualGazedBasedCursor;
  35.                 //Fix the problem with the cursor rendering behind UI elements.
  36.                 Canvas cursorCanvas = __instance._cursor.GetComponentInChildren<Graphic>().canvas;
  37.                 RaycastResult lastRaycastResult = Traverse.Create(__instance).Field("lastRaycastResult").GetValue<RaycastResult>();
  38.                 if (cursorCanvas && lastRaycastResult.isValid)
  39.                 {
  40.                     cursorCanvas.sortingLayerID = lastRaycastResult.sortingLayer;//put the cursor on the same layer as whatever was hit by the cursor raycast.
  41.                 }
  42.             }
  43.         }
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement