mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 22:39:22 +00:00
[AvatarScaleMod] Refactor & Avatar Parameters
This commit is contained in:
parent
5b7b586298
commit
acacc21050
5 changed files with 322 additions and 162 deletions
|
@ -3,6 +3,8 @@ using ABI_RC.Core.Savior;
|
|||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using ABI_RC.Systems.IK;
|
||||
using RootMotion.FinalIK;
|
||||
|
||||
namespace NAK.AvatarScaleMod.HarmonyPatches;
|
||||
|
||||
|
@ -14,7 +16,8 @@ class PlayerSetupPatches
|
|||
{
|
||||
try
|
||||
{
|
||||
__instance._avatar.AddComponent<AvatarScaleManager>().Initialize(__instance._initialAvatarHeight, __instance.initialScale);
|
||||
__instance._avatar.AddComponent<AvatarScaleManager>().Initialize(__instance._initialAvatarHeight, __instance.initialScale, true);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -22,6 +25,54 @@ class PlayerSetupPatches
|
|||
AvatarScaleMod.Logger.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
static Vector3 originalPosition;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetPlaySpaceScale))]
|
||||
static void Prefix_PlayerSetup_SetPlaySpaceScale(ref PlayerSetup __instance)
|
||||
{
|
||||
originalPosition = __instance.vrCamera.transform.position;
|
||||
originalPosition.y = __instance.transform.position.y;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.SetPlaySpaceScale))]
|
||||
static void Postfix_PlayerSetup_SetPlaySpaceScale(ref PlayerSetup __instance)
|
||||
{
|
||||
Vector3 newPosition = __instance.vrCamera.transform.position;
|
||||
newPosition.y = __instance.transform.position.y;
|
||||
|
||||
Vector3 offset = newPosition - originalPosition;
|
||||
|
||||
// Apply the offset to the VR camera rig's position
|
||||
__instance.transform.position -= offset;
|
||||
|
||||
//if (IKSystem.vrik != null)
|
||||
//{
|
||||
// IKSystem.vrik.solver.locomotion.AddDeltaPosition(offset * 2);
|
||||
// IKSystem.vrik.solver.raycastOriginPelvis += offset * 2;
|
||||
// IKSystem.vrik.solver.Reset();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
class PuppetMasterPatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PuppetMaster), nameof(PuppetMaster.AvatarInstantiated))]
|
||||
static void Postfix_PuppetMaster_AvatarInstantiated(ref PuppetMaster __instance)
|
||||
{
|
||||
try
|
||||
{
|
||||
__instance.avatarObject.AddComponent<AvatarScaleManager>().Initialize(__instance._initialAvatarHeight, __instance.initialAvatarScale, false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AvatarScaleMod.Logger.Error($"Error during the patched method {nameof(Postfix_PuppetMaster_AvatarInstantiated)}");
|
||||
AvatarScaleMod.Logger.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GesturePlaneTestPatches
|
||||
|
@ -33,24 +84,45 @@ class GesturePlaneTestPatches
|
|||
try
|
||||
{
|
||||
// nicked from Kafe >:))))
|
||||
|
||||
// This requires arms far outward- pull inward with fist and triggers.
|
||||
// Release triggers while still holding fist to readjust.
|
||||
|
||||
var gesture = new CVRGesture
|
||||
{
|
||||
name = "avatarScale",
|
||||
name = "avatarScaleIn",
|
||||
type = CVRGesture.GestureType.Hold,
|
||||
};
|
||||
// TODO: Expose these settings in-game and tune till they feel right
|
||||
gesture.steps.Add(new CVRGestureStep
|
||||
{
|
||||
firstGesture = CVRGestureStep.Gesture.Fist,
|
||||
secondGesture = CVRGestureStep.Gesture.Fist,
|
||||
startDistance = 0.5f,
|
||||
endDistance = 0.4f,
|
||||
startDistance = 1f,
|
||||
endDistance = 0.25f,
|
||||
direction = CVRGestureStep.GestureDirection.MovingIn,
|
||||
});
|
||||
gesture.onStart.AddListener(new UnityAction<float, Transform, Transform>(AvatarScaleGesture.OnScaleStart));
|
||||
gesture.onStay.AddListener(new UnityAction<float, Transform, Transform>(AvatarScaleGesture.OnScaleStay));
|
||||
gesture.onEnd.AddListener(new UnityAction<float, Transform, Transform>(AvatarScaleGesture.OnScaleEnd));
|
||||
CVRGestureRecognizer.Instance.gestures.Add(gesture);
|
||||
|
||||
gesture = new CVRGesture
|
||||
{
|
||||
name = "avatarScaleOut",
|
||||
type = CVRGesture.GestureType.Hold,
|
||||
};
|
||||
gesture.steps.Add(new CVRGestureStep
|
||||
{
|
||||
firstGesture = CVRGestureStep.Gesture.Fist,
|
||||
secondGesture = CVRGestureStep.Gesture.Fist,
|
||||
startDistance = 0.25f,
|
||||
endDistance = 1f,
|
||||
direction = CVRGestureStep.GestureDirection.MovingOut,
|
||||
});
|
||||
gesture.onStart.AddListener(new UnityAction<float, Transform, Transform>(AvatarScaleGesture.OnScaleStart));
|
||||
gesture.onStay.AddListener(new UnityAction<float, Transform, Transform>(AvatarScaleGesture.OnScaleStay));
|
||||
gesture.onEnd.AddListener(new UnityAction<float, Transform, Transform>(AvatarScaleGesture.OnScaleEnd));
|
||||
CVRGestureRecognizer.Instance.gestures.Add(gesture);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue