-
-
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(input): use right hand as target origin
- Loading branch information
Showing
9 changed files
with
164 additions
and
2 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
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,53 @@ | ||
using HarmonyLib; | ||
using Plugin.Input; | ||
using UnityEngine; | ||
|
||
namespace TechtonicaVR.VRCamera.Patch; | ||
|
||
[HarmonyPatch] | ||
public class TargetRaycastPatch | ||
{ | ||
|
||
public static Transform cursorTlc; | ||
|
||
[HarmonyPrefix] | ||
[HarmonyPatch(typeof(PlayerFirstPersonController), nameof(PlayerFirstPersonController.UpdateAimingRaycasts))] | ||
public static bool Postfix(PlayerFirstPersonController __instance) | ||
{ | ||
var right_hand_transform = SteamVRInputMapper.rightHandObject.transform; | ||
var forward = right_hand_transform.forward; | ||
|
||
// Rotate the forward vector 45 degrees down | ||
var rotation = Quaternion.Euler(45f, 0f, 0f); | ||
forward = rotation * forward; | ||
|
||
__instance._hasCamHit = Physics.Raycast(new Ray(right_hand_transform.position, forward), out __instance._camHit, __instance.cam.farClipPlane, __instance.aimLayer, QueryTriggerInteraction.Collide); | ||
if (__instance.hasCamHit) | ||
{ | ||
__instance.lookAtTarget.position = __instance.camHit.point; | ||
__instance._hasPlayerAimHit = __instance._hasCamHit; | ||
} | ||
else | ||
{ | ||
__instance.lookAtTarget.position = __instance.cam.transform.position + __instance.cam.transform.forward * __instance.cam.farClipPlane; | ||
__instance._camHit = default; | ||
__instance._playerAimHit = default; | ||
} | ||
UIManager.instance.hud.cursorDotUI.cursorSetting = CursorDotUI.CursorSetting.Default; | ||
|
||
return false; | ||
} | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(CursorDotUI), nameof(PlayerFirstPersonController.LateUpdate))] | ||
public static void Postfix(CursorDotUI __instance) | ||
{ | ||
if (cursorTlc != null && Player.instance.fpcontroller.hasCamHit) | ||
{ | ||
var camHit = Player.instance.fpcontroller.camHit; | ||
Vector3 screenPoint = Player.instance.fpcontroller.cam.WorldToScreenPoint(camHit.point); | ||
Vector3 canvasPoint = cursorTlc.parent.GetComponent<Canvas>().worldCamera.ScreenToWorldPoint(screenPoint); | ||
cursorTlc.position = canvasPoint; | ||
} | ||
} | ||
} |
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,31 @@ | ||
using UnityEngine; | ||
|
||
namespace TechtonicaVR.Debug; | ||
|
||
public class DebugLine : MonoBehaviour | ||
{ | ||
public Transform start; | ||
public Transform end; | ||
|
||
private LineRenderer line; | ||
|
||
private void Start() | ||
{ | ||
if (ModConfig.DebugLineEnabled() == false) | ||
{ | ||
Destroy(this); | ||
return; | ||
} | ||
|
||
line = gameObject.AddComponent<LineRenderer>(); | ||
line.startWidth = 0.01f; | ||
line.endWidth = 0.01f; | ||
line.positionCount = 2; | ||
} | ||
|
||
private void Update() | ||
{ | ||
line.SetPosition(0, start.position); | ||
line.SetPosition(1, end.position); | ||
} | ||
} |
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,33 @@ | ||
using BepInEx.Configuration; | ||
|
||
namespace TechtonicaVR; | ||
|
||
public class ModConfig | ||
{ | ||
// General | ||
public static ConfigEntry<bool> modEnabled; | ||
|
||
// Debug | ||
public static ConfigEntry<bool> debugMode; | ||
public static ConfigEntry<bool> debugLineEnabled; | ||
|
||
public static void Init(ConfigFile config) | ||
{ | ||
// General | ||
modEnabled = config.Bind("General", "Enabled", true, "Enable mod"); | ||
|
||
// Debug | ||
debugMode = config.Bind("Debug", "Debug Mode", false, "Enable debug mode"); | ||
debugLineEnabled = config.Bind("Debug", "Debug Line Enabled", false, "Enable debug lines"); | ||
} | ||
|
||
public static bool ModEnabled() | ||
{ | ||
return modEnabled.Value; | ||
} | ||
|
||
public static bool DebugLineEnabled() | ||
{ | ||
return debugMode.Value && debugLineEnabled.Value; | ||
} | ||
} |
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,26 @@ | ||
using Plugin.Input; | ||
using TechtonicaVR.Debug; | ||
using TechtonicaVR.VRCamera.Patch; | ||
using UnityEngine; | ||
|
||
namespace TechtonicaVR.Patches.MainGame.UI; | ||
|
||
public class CursorCanvasPatch : GameObjectPatch | ||
{ | ||
public CursorCanvasPatch() : base("Cursor Canvas") | ||
{ | ||
} | ||
|
||
protected override bool Apply(GameObject gameObject) | ||
{ | ||
var tlc = gameObject.transform.GetChild(0); | ||
TargetRaycastPatch.cursorTlc = tlc; | ||
|
||
// Debug | ||
var line = tlc.gameObject.AddComponent<DebugLine>(); | ||
line.start = tlc; | ||
line.end = SteamVRInputMapper.rightHandObject.transform; | ||
|
||
return true; | ||
} | ||
} |
Binary file not shown.