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
1,447 changes: 1,392 additions & 55 deletions Assets/Gothic-VR/Resources/VR/Prefabs/Vobs/oCMobContainer.prefab

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Assets/Gothic-VR/Resources/VR/Prefabs/Vobs/oCNpc.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier: Gothic.VR::Gothic.VR.Adapters.VRNpcLoot
_socketPrefab: {fileID: 5861164055357080340, guid: 2dd29fe4a7e819740af535267b7cc113, type: 3}
_slotPrefab: {fileID: 7034454508457674463, guid: e970795bd5895ed4d8a7686f050c5832, type: 3}
--- !u!1 &2815092147823170342
GameObject:
m_ObjectHideFlags: 0
Expand Down
12 changes: 11 additions & 1 deletion Assets/Gothic-VR/Scripts/Adapters/VRNpcLoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Gothic.Core.Extensions;
using Gothic.Core.Manager;
using Gothic.Core.Models.Container;
using Gothic.Core.Models.Context;
using Gothic.Core.Models.Vm;
using Gothic.Core.Models.Vob;
using Gothic.Core.Services;
Expand All @@ -33,8 +34,14 @@ public class VRNpcLoot : MonoBehaviour
private const float SocketHeight = 0.8f;
private const float SocketSpacing = 0.22f;

[Tooltip("Loot slot on the HVR backend (HVR socket).")]
[SerializeField] private GameObject _socketPrefab;

[Tooltip("Loot slot on the other backends (VrSocketSlot, e.g. \"VR Socket Slot.prefab\" for XRI).")]
[SerializeField] private GameObject _slotPrefab;

[Inject] private readonly IVrBackend _vrBackend;

[Inject] private readonly NpcInventoryService _npcInventoryService;
[Inject] private readonly VobService _vobService;
[Inject] private readonly AudioService _audioService;
Expand Down Expand Up @@ -108,10 +115,13 @@ private void PlayOpenSound()
private void CreateSockets()
{
var totalWidth = (MaxVisibleSlots - 1) * SocketSpacing;
var prefab = _vrBackend == null || _vrBackend.Kind == VrInteractionBackend.Hvr
? _socketPrefab
: _slotPrefab;

for (var i = 0; i < MaxVisibleSlots; i++)
{
var socketGo = Instantiate(_socketPrefab, transform);
var socketGo = Instantiate(prefab, transform);
var xOffset = -totalWidth / 2f + i * SocketSpacing;
socketGo.transform.localPosition = new Vector3(xOffset, SocketHeight, 0f);
socketGo.transform.localRotation = Quaternion.identity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace Gothic.VR.Adapters.Vob.Container
/// <summary>
/// Handle Socket-events for a whole Container (e.g., chest) and its corresponding sockets (rings where we put items into).
/// Plays the weapon (un)draw sound when a weapon is put into or taken out of a socket.
/// No sound is played while the IVrSocketContainer on this GameObject (if any) is silent, e.g. while a chest
/// spawns its content.
/// </summary>
public class VRVobContainerSocketInventory : MonoBehaviour
{
Expand All @@ -23,9 +25,11 @@ public class VRVobContainerSocketInventory : MonoBehaviour
[SerializeField] private GameObject[] _additionalSockets;

private readonly List<IVrSocket> _sockets = new();
private IVrSocketContainer _container;

private void Awake()
{
_container = GetComponent<IVrSocketContainer>();
_sockets.AddRange(GetComponentsInChildren<IVrSocket>(true));
foreach (var socketGo in _additionalSockets)
{
Expand All @@ -51,7 +55,7 @@ private void OnDestroy()

private void OnBeforeGrabbed(VrGrabArgs args)
{
if (args.Interactable == null)
if (args.Interactable == null || IsSilent)
return;

var container = args.Interactable.GetComponentInParent<VobLoader>()?.Container;
Expand All @@ -62,7 +66,7 @@ private void OnBeforeGrabbed(VrGrabArgs args)

private void OnReleased(VrGrabArgs args)
{
if (args.Interactable == null)
if (args.Interactable == null || IsSilent)
return;

var container = args.Interactable.GetComponentInParent<VobLoader>()?.Container;
Expand All @@ -71,6 +75,8 @@ private void OnReleased(VrGrabArgs args)
_vrWeaponService.PlayDrawSound(container);
}

private bool IsSilent => _container != null && _container.IsSilent;

private bool IsWeapon(VobContainer container)
{
var itemInstance = container?.GetItemInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Gothic.Core.Services.Vm;
using Gothic.VR.Services;
using Gothic.VR.Adapters.Vob.VobItem;
using Gothic.VR.Interaction.Components;
using Gothic.VR.Interaction.Models;
using Gothic.VR.Interaction.Ports;
using Reflex.Attributes;
Expand Down Expand Up @@ -52,8 +53,8 @@ private void Start()
{
var vobLoader = GetComponentInParent<VobLoader>();
_lockable = vobLoader.Container;
// Every door and chest has exactly one hinge (the door wing or the chest lid).
_hinge = vobLoader.GetComponentInChildren<IVrHinge>(true);
// Every door and chest has one hinge (the door wing or the chest lid) per backend which supports it.
_hinge = VrHinges.FindActive(vobLoader);
switch (_lockable.Vob)
{
case IDoor door:
Expand Down Expand Up @@ -86,7 +87,7 @@ private IEnumerator StartDelayed()
yield return null;

// Deactivate rotation
_hinge.Lock();
_hinge?.Lock();
}

private void OnTriggerEnter(Collider other)
Expand Down Expand Up @@ -235,6 +236,12 @@ private void TryUnlockWithKey(Collider other)
private void UnlockAndPushOpen()
{
// Reactivate rotation
if (_hinge == null)
{
gameObject.SetActive(false);
return;
}

_hinge.Unlock();

// Apply force in the door's forward direction (world space)
Expand Down
6 changes: 3 additions & 3 deletions Assets/Gothic-VR/Scripts/Adapters/Vob/VRVobContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Gothic.Core.Logging;
using Gothic.Core.Manager;
using Gothic.Core.Services.Caches;
using Gothic.VR.Interaction.Ports;
using Gothic.VR.Interaction.Components;
using Reflex.Attributes;
using UnityEngine;
using UnityEngine.SceneManagement;
Expand Down Expand Up @@ -74,8 +74,8 @@ private void PrepareSounds(IContainer vobContainer)
}

// We leverage the same "door" script for containers (As it's also just an object to be rotated.
var hinge = GetComponentInChildren<IVrHinge>();
hinge.SetSounds(_containerOpenedClips[mdsName.ToLower()], _containerClosedClips[mdsName.ToLower()]);
var hinge = VrHinges.FindActive(this);
hinge?.SetSounds(_containerOpenedClips[mdsName.ToLower()], _containerClosedClips[mdsName.ToLower()]);
}
}
}
6 changes: 3 additions & 3 deletions Assets/Gothic-VR/Scripts/Adapters/Vob/VRVobDoor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Gothic.Core.Services.Caches;
using Gothic.Core;
using Gothic.Core.Extensions;
using Gothic.VR.Interaction.Ports;
using Gothic.VR.Interaction.Components;
using Reflex.Attributes;
using UnityEngine;
using ZenKit.Vobs;
Expand Down Expand Up @@ -64,8 +64,8 @@ private void PrepareSounds(IDoor props)
_doorClosedClips.Add(mdsName.ToLower(), _audioService.GetRandomSoundClip(closeSoundEffect));
}

var hinge = GetComponentInChildren<IVrHinge>();
hinge.SetSounds(_doorOpenedClips[mdsName.ToLower()], _doorClosedClips[mdsName.ToLower()]);
var hinge = VrHinges.FindActive(this);
hinge?.SetSounds(_doorOpenedClips[mdsName.ToLower()], _doorClosedClips[mdsName.ToLower()]);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if GOTHIC_HVR_INSTALLED
using Gothic.Core.Models.Context;
using Gothic.VR.Interaction.Ports;
using Reflex.Core;

Expand All @@ -7,6 +8,7 @@ namespace Gothic.VR.Interaction.Backends.Hvr
public class HvrBackend : IVrBackend
{
public string Name => "HurricaneVR";
public VrInteractionBackend Kind => VrInteractionBackend.Hvr;

public void InstallBindings(ContainerBuilder containerBuilder)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if GOTHIC_HVR_INSTALLED
using Gothic.VR.Interaction.Ports;
using HurricaneVR.Framework.Components;
using Reflex.Attributes;
using UnityEngine;

namespace Gothic.VR.Interaction.Backends.Hvr
Expand All @@ -10,6 +11,8 @@ namespace Gothic.VR.Interaction.Backends.Hvr
/// </summary>
public class HvrHingeBridge : MonoBehaviour, IVrHinge
{
[Inject] private readonly IVrBackend _vrBackend;

private HVRPhysicsDoor _door;

private HVRPhysicsDoor Door
Expand All @@ -22,6 +25,7 @@ private HVRPhysicsDoor Door
}
}

public bool IsActive => _vrBackend == null || _vrBackend is HvrBackend;
public Transform Transform => transform;
public Rigidbody Rigidbody => GetComponent<Rigidbody>();

Expand Down
Loading