Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Assets/Gothic-Core/Scripts/GlobalEventDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public static class GlobalEventDispatcher


// Fight events

/// <summary>
/// HINT: Left/Right have other values than Gothic.VR.Interaction.Models.VrHandSide (Left=0, Right=1).
/// Map them with VrHandSideExtensions, never cast.
/// </summary>
public enum HandSide
{
None = 0,
Expand Down Expand Up @@ -99,7 +104,8 @@ public enum HandSide
// LockPicking events
// 1. VobContainer -> LockPick
// 2. VobContainer -> Door/Chest
// 3. HandSide (for VR) -> (0 = Left, 1 = Right)
// 3. HandSide (for VR) -> int of Gothic.VR.Interaction.Models.VrHandSide (0 = Left, 1 = Right),
// not GlobalEventDispatcher.HandSide.
public static readonly UnityEvent<VobContainer, VobContainer, int> LockPickComboCorrect = new();
public static readonly UnityEvent<VobContainer, VobContainer, int> LockPickComboWrong = new();
public static readonly UnityEvent<VobContainer, VobContainer, int> LockPickComboFinished = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Gothic.Core.Services;
using Gothic.Core.Services.Config;
using Gothic.VR.Adapters.UI;
using Gothic.VR.Interaction.Backends.Hvr;
using Gothic.VR.Interaction.Models;
using HurricaneVR.Framework.Core.Player;
using MyBox;
using Reflex.Attributes;
Expand Down Expand Up @@ -64,29 +66,35 @@ public void SetNormalControls(bool useDefaultValues = false)
// We have our player created before Gothic inis are loaded. We therefore need to set some default values.
if (useDefaultValues)
{
CameraRig.SetSitStandMode(HVRSitStand.PlayerHeight);
DirectionStyle = PlayerDirectionMode.Camera;
RotationType = RotationType.Snap;
SnapAmount = 45f;
SmoothTurnSpeed = 90f;

ApplyComfortSettings(VrSitStand.PlayerHeight, VrMoveDirection.Camera, VrTurnType.Snap, 45f, 90f);
return;
}

var sitStandSetting =
_configService.Gothic.GetInt(VRConstants.IniNames.SitStand, (int)HVRSitStand.PlayerHeight);
CameraRig.SetSitStandMode((HVRSitStand)sitStandSetting);

DirectionStyle = (PlayerDirectionMode)_configService.Gothic.GetInt(VRConstants.IniNames.MoveDirection, (int)PlayerDirectionMode.Camera);
RotationType = (RotationType)_configService.Gothic.GetInt(VRConstants.IniNames.RotationType, (int)RotationType.Snap);
var gothicIni = _configService.Gothic;
var sitStand = (VrSitStand)gothicIni.GetInt(VRConstants.IniNames.SitStand, (int)VrSitStand.PlayerHeight);
var moveDirection =
(VrMoveDirection)gothicIni.GetInt(VRConstants.IniNames.MoveDirection, (int)VrMoveDirection.Camera);
var turnType = (VrTurnType)gothicIni.GetInt(VRConstants.IniNames.RotationType, (int)VrTurnType.Snap);

var snapSetting = _configService.Gothic.GetInt(VRConstants.IniNames.SnapRotationAmount, VRConstants.SnapRotationDefaultValue);
var snapSetting = gothicIni.GetInt(VRConstants.IniNames.SnapRotationAmount, VRConstants.SnapRotationDefaultValue);
// e.g., 20° = 5° + 3*5°
SnapAmount = VRConstants.SnapRotationAmountSettingTickAmount + VRConstants.SnapRotationAmountSettingTickAmount * snapSetting;
var smoothSetting = _configService.Gothic.GetFloat(VRConstants.IniNames.SmoothRotationSpeed, VRConstants.SmoothRotationDefaultValue);
var snapDegrees = VRConstants.SnapRotationAmountSettingTickAmount + VRConstants.SnapRotationAmountSettingTickAmount * snapSetting;

var smoothSetting = gothicIni.GetFloat(VRConstants.IniNames.SmoothRotationSpeed, VRConstants.SmoothRotationDefaultValue);
// e.g., 50 = 5 + 90 * 0.5f
SmoothTurnSpeed = VRConstants.SmoothRotationMinSpeed + VRConstants.SmoothRotationMaxAdditionalSpeed * smoothSetting;
var smoothSpeed = VRConstants.SmoothRotationMinSpeed + VRConstants.SmoothRotationMaxAdditionalSpeed * smoothSetting;

ApplyComfortSettings(sitStand, moveDirection, turnType, snapDegrees, smoothSpeed);
}

public void ApplyComfortSettings(VrSitStand sitStand, VrMoveDirection moveDirection, VrTurnType turnType,
float snapDegrees, float smoothSpeed)
{
CameraRig.SetSitStandMode(sitStand.ToHvr());
DirectionStyle = moveDirection.ToHvr();
RotationType = turnType.ToHvr();
SnapAmount = snapDegrees;
SmoothTurnSpeed = smoothSpeed;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Gothic.Core.Models.Marvin;
using Gothic.Core.Models.Vm;
using Gothic.Core.Services;
using Gothic.VR.Interaction.Backends.Hvr;
using Gothic.VR.Models.Vob;
using Gothic.VR.Services;
using HurricaneVR.Framework.Core;
Expand Down Expand Up @@ -56,7 +57,7 @@ public void OnGrabbed(HVRGrabberBase hand, HVRGrabbable item)
if (itemInstance!.MainFlag != (int)VmGothicEnums.ItemFlags.ItemKatNf)
return;

_weaponService.OnGrabbed(((HVRHandGrabber)hand).HandSide, vobContainer, GetWeaponPhysicsConfig());
_weaponService.OnGrabbed(((HVRHandGrabber)hand).HandSide.ToVr(), vobContainer, GetWeaponPhysicsConfig());
SyncEquippedWeaponToHero(itemInstance, equip: true);
}

Expand All @@ -75,7 +76,7 @@ public void OnReleased(HVRGrabberBase hand, HVRGrabbable item)
if (itemInstance!.MainFlag != (int)VmGothicEnums.ItemFlags.ItemKatNf)
return;

_weaponService.OnReleased(((HVRHandGrabber)hand).HandSide, GetWeaponPhysicsConfig());
_weaponService.OnReleased(((HVRHandGrabber)hand).HandSide.ToVr(), GetWeaponPhysicsConfig());
SyncEquippedWeaponToHero(itemInstance, equip: false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using Gothic.Core.Services.Vm;
using Gothic.VR.Services;
using Gothic.VR.Adapters.Vob.VobItem;
using Gothic.VR.Interaction.Models;
using HurricaneVR.Framework.Components;
using HurricaneVR.Framework.Shared;
using Reflex.Attributes;
using UnityEngine;
using ZenKit.Vobs;
Expand All @@ -33,7 +33,7 @@ public class VRContainerDoorPickingInteraction : MonoBehaviour
private bool _isLocked;
private string _combination;
private string _keyInstance;
private HVRHandSide _handSide;
private VrHandSide _handSide;
private VobContainer _lockPick;
private VobContainer _lockable;

Expand Down Expand Up @@ -101,12 +101,12 @@ private void OnTriggerEnter(Collider other)
if (IsHeldItem(_vrPlayerService.GrabbedItemLeft, other.gameObject))
{
holdingHand = _vrPlayerService.GrabbedItemLeft.transform;
_handSide = HVRHandSide.Left;
_handSide = VrHandSide.Left;
}
else if (IsHeldItem(_vrPlayerService.GrabbedItemRight, other.gameObject))
{
holdingHand = _vrPlayerService.GrabbedItemRight.transform;
_handSide = HVRHandSide.Right;
_handSide = VrHandSide.Right;
}
else
{
Expand All @@ -115,7 +115,7 @@ private void OnTriggerEnter(Collider other)

_combinationPos = 0;
PlaySound(_vmService.DoorLockSoundName);
_hapticsService.Vibrate(_handSide, VrHapticsService.VibrationType.Info);
_hapticsService.Vibrate(_handSide, VrHapticPreset.Info);

// For later event usage.
_lockPick = other.gameObject.GetComponentInParent<VobLoader>().Container;
Expand Down Expand Up @@ -213,13 +213,13 @@ private void TryUnlockWithKey(Collider other)
return;

// The player must actively hold the key (not just a dropped/flying item).
HVRHandSide hand;
VrHandSide hand;
var leftRoot = _vrPlayerService.GrabbedItemLeft;
var rightRoot = _vrPlayerService.GrabbedItemRight;
if (leftRoot != null && leftRoot.GetComponentInParent<VobLoader>() == vobLoader)
hand = HVRHandSide.Left;
hand = VrHandSide.Left;
else if (rightRoot != null && rightRoot.GetComponentInParent<VobLoader>() == vobLoader)
hand = HVRHandSide.Right;
hand = VrHandSide.Right;
else
return;

Expand Down
18 changes: 9 additions & 9 deletions Assets/Gothic-VR/Scripts/Domain/Player/VrWeaponAttackDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
using Gothic.Core.Models.Vm;
using Gothic.Core.Services.Caches;
using Gothic.VR.Models.Vob;
using Gothic.VR.Interaction.Models;
using Gothic.VR.Services;
using HurricaneVR.Framework.Core.Utils;
using HurricaneVR.Framework.Shared;
using Reflex.Attributes;
using UnityEngine;
using ZenKit;
Expand Down Expand Up @@ -87,7 +87,7 @@ private static readonly (float attackWindowTime, float comboWindowStart, float c
/// FALSE, when:
/// 1. Already handling one weapon, but another one is provided.
/// </summary>
public bool TryHandle(VobContainer vobContainer, WeaponPhysicsConfig weaponConfig, HVRHandSide handSide, NpcContainer playerNpcContainer)
public bool TryHandle(VobContainer vobContainer, WeaponPhysicsConfig weaponConfig, VrHandSide handSide, NpcContainer playerNpcContainer)
{
if (!CanHandle(vobContainer))
return false;
Expand Down Expand Up @@ -135,9 +135,9 @@ public bool TryHandle(VobContainer vobContainer, WeaponPhysicsConfig weaponConfi
windowTimes.comboWindowStart, windowTimes.comboWindowTime);
}

if (handSide == HVRHandSide.Left)
if (handSide == VrHandSide.Left)
_handlesLeftHand = true;
else if (handSide == HVRHandSide.Right)
else if (handSide == VrHandSide.Right)
_handlesRightHand = true;

AlterWeaponWeights(weaponConfig);
Expand Down Expand Up @@ -168,14 +168,14 @@ private bool CanHandle(VobContainer newWeapon)
return false;
}

public bool TryUnHandle(WeaponPhysicsConfig weaponConfig, HVRHandSide handSide)
public bool TryUnHandle(WeaponPhysicsConfig weaponConfig, VrHandSide handSide)
{
if (!CanUnHandle(handSide))
return false;

if (handSide == HVRHandSide.Left)
if (handSide == VrHandSide.Left)
_handlesLeftHand = false;
else if (handSide == HVRHandSide.Right)
else if (handSide == VrHandSide.Right)
_handlesRightHand = false;

// Alter weight now, before we potentially unset VobContainer and Rigidbody.
Expand All @@ -191,9 +191,9 @@ public bool TryUnHandle(WeaponPhysicsConfig weaponConfig, HVRHandSide handSide)
/// Unhandle means: Do we released item in hand which we handled?
/// Hint: We can only have one item in a hand at a time. Therefore, we don't need to check for the rigidbody itself.
/// </summary>
private bool CanUnHandle(HVRHandSide releasedHandSide)
private bool CanUnHandle(VrHandSide releasedHandSide)
{
if (releasedHandSide == HVRHandSide.Left)
if (releasedHandSide == VrHandSide.Left)
return _handlesLeftHand;
else
return _handlesRightHand;
Expand Down
8 changes: 8 additions & 0 deletions Assets/Gothic-VR/Scripts/Interaction.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Gothic-VR/Scripts/Interaction/Backends.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Gothic-VR/Scripts/Interaction/Backends/Hvr.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#if GOTHIC_HVR_INSTALLED
using System;
using Gothic.VR.Interaction.Models;
using HurricaneVR.Framework.Core.Player;
using HurricaneVR.Framework.Shared;

namespace Gothic.VR.Interaction.Backends.Hvr
{
/// <summary>
/// Maps our VR models to HVR types and back. Only used inside the HVR backend.
/// </summary>
public static class HvrEnumExtensions
{
public static HVRHandSide ToHvr(this VrHandSide side)
{
return side == VrHandSide.Left ? HVRHandSide.Left : HVRHandSide.Right;
}

public static VrHandSide ToVr(this HVRHandSide side)
{
return side == HVRHandSide.Left ? VrHandSide.Left : VrHandSide.Right;
}

public static HVRButtons ToHvr(this VrButton button)
{
return button switch
{
VrButton.Grip => HVRButtons.Grip,
VrButton.Trigger => HVRButtons.Trigger,
VrButton.Primary => HVRButtons.Primary,
VrButton.Secondary => HVRButtons.Secondary,
VrButton.Menu => HVRButtons.Menu,
VrButton.JoystickButton => HVRButtons.JoystickButton,
_ => throw new ArgumentOutOfRangeException(nameof(button), button, null)
};
}

public static VrButtonState ToVr(this HVRButtonState state)
{
return new VrButtonState(state.Active, state.JustActivated, state.JustDeactivated);
}

public static HVRSitStand ToHvr(this VrSitStand sitStand)
{
return sitStand switch
{
VrSitStand.Sitting => HVRSitStand.Sitting,
VrSitStand.Standing => HVRSitStand.Standing,
_ => HVRSitStand.PlayerHeight
};
}

public static PlayerDirectionMode ToHvr(this VrMoveDirection direction)
{
return direction switch
{
VrMoveDirection.LeftController => PlayerDirectionMode.LeftController,
VrMoveDirection.RightController => PlayerDirectionMode.RightController,
_ => PlayerDirectionMode.Camera
};
}

public static RotationType ToHvr(this VrTurnType turnType)
{
return turnType == VrTurnType.Smooth ? RotationType.Smooth : RotationType.Snap;
}
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Gothic-VR/Scripts/Interaction/Models.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Assets/Gothic-VR/Scripts/Interaction/Models/VrButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Gothic.VR.Interaction.Models
{
/// <summary>
/// Controller buttons we read in game code. The active VR backend maps them to the device buttons.
/// </summary>
public enum VrButton
{
Grip,
Trigger,
Primary,
Secondary,
Menu,
JoystickButton
}
}
2 changes: 2 additions & 0 deletions Assets/Gothic-VR/Scripts/Interaction/Models/VrButton.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Assets/Gothic-VR/Scripts/Interaction/Models/VrButtonState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Gothic.VR.Interaction.Models
{
/// <summary>
/// State of a controller button in the current frame.
/// </summary>
public readonly struct VrButtonState
{
/// <summary>
/// The button is held down.
/// </summary>
public readonly bool IsActive;

/// <summary>
/// The button went down this frame.
/// </summary>
public readonly bool IsJustActivated;

/// <summary>
/// The button went up this frame.
/// </summary>
public readonly bool IsJustDeactivated;

public VrButtonState(bool isActive, bool isJustActivated, bool isJustDeactivated)
{
IsActive = isActive;
IsJustActivated = isJustActivated;
IsJustDeactivated = isJustDeactivated;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading