-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): attched inspector to aim location (#23)
- Loading branch information
Showing
7 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using HarmonyLib; | ||
using Plugin.Input; | ||
using UnityEngine; | ||
|
||
namespace TechtonicaVR.VRCamera.Patch.Builder; | ||
|
||
[HarmonyPatch] | ||
public class PlayerInspectorPatch | ||
{ | ||
private const int EXPECTED_INSPECTOR_UPDATE_PATCH_COUNT = 1; | ||
|
||
static MethodInfo raycastMethod = typeof(Physics).GetMethod(nameof(Physics.Raycast), [typeof(Vector3), typeof(Vector3), typeof(RaycastHit).MakeByRefType(), typeof(float), typeof(int)]); | ||
static MethodInfo raycastPatchMethod = typeof(PlayerInspectorPatch).GetMethod(nameof(PatchedRaycast)); | ||
|
||
[HarmonyPatch(typeof(PlayerInspector), nameof(PlayerInspector.LateUpdate))] | ||
[HarmonyTranspiler] | ||
public static IEnumerable<CodeInstruction> InspectorUpdateTranspiler(IEnumerable<CodeInstruction> instructions) | ||
{ | ||
var patchCnt = 0; | ||
foreach (var instruction in instructions) | ||
{ | ||
if (instruction.Calls(raycastMethod)) | ||
{ | ||
yield return new CodeInstruction(OpCodes.Call, raycastPatchMethod); | ||
patchCnt++; | ||
} | ||
else | ||
{ | ||
yield return instruction; | ||
} | ||
} | ||
|
||
if (patchCnt != EXPECTED_INSPECTOR_UPDATE_PATCH_COUNT) | ||
{ | ||
Plugin.Logger.LogError($"[PlayerInspector.LateUpdate] Patch count mismatch: {patchCnt} != {EXPECTED_INSPECTOR_UPDATE_PATCH_COUNT}"); | ||
} | ||
} | ||
|
||
public static bool PatchedRaycast(Vector3 _origin, Vector3 _direction, out RaycastHit hitInfo, float maxDistance, int layerMask) | ||
{ | ||
return Physics.Raycast(SteamVRInputMapper.rightHandObject.transform.position, -SteamVRInputMapper.rightHandObject.transform.up, out hitInfo, maxDistance, layerMask); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using TechtonicaVR.VRCamera.Patch; | ||
using UnityEngine; | ||
|
||
namespace TechtonicaVR.Patches.MainGame.UI; | ||
|
||
class InspectorCanvasPatch : GameComponentPatch<InspectorUI> | ||
|
||
{ | ||
protected override bool Apply(InspectorUI gameObject) | ||
{ | ||
var tlc = gameObject.transform.GetChild(0); | ||
if (tlc == null) | ||
{ | ||
return false; | ||
} | ||
|
||
var sharedInspector = tlc.transform.GetChild(0); | ||
if (sharedInspector == null) | ||
{ | ||
return false; | ||
} | ||
sharedInspector.transform.localPosition = new Vector3(23.8832f, -21.9059f, 0); | ||
|
||
var scannableInspector = tlc.gameObject.transform.GetChild(1).transform.GetChild(0); | ||
if (scannableInspector == null) | ||
{ | ||
return false; | ||
} | ||
scannableInspector.transform.localPosition = new Vector3(211.4383f, -22.6601f, 0); | ||
|
||
|
||
TargetRaycastPatch.inspectorTlc = tlc; | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters