Some fixes made, object picking logic added

This commit is contained in:
Timur Nizamov
2025-12-21 00:01:28 +02:00
parent 27d5fdd68c
commit 50dba2cd81
82 changed files with 1464 additions and 1390 deletions

View File

@@ -78,7 +78,7 @@ public class KeyboardManager : NetworkBehaviour
string letter = label.text;
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.LetterEnter, gameObject);
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.LetterEnter, button.gameObject);
switch (_shiftMode)
{
case ShiftMode.Lowercase:
@@ -99,7 +99,7 @@ public class KeyboardManager : NetworkBehaviour
void OnShiftPressed()
{
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.LetterEnter, gameObject);
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.LetterEnter, shiftButton.gameObject);
_shiftMode = _shiftMode switch
{
@@ -114,7 +114,7 @@ public class KeyboardManager : NetworkBehaviour
void OnBackspacePressed()
{
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.LetterEnter, gameObject);
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.LetterEnter, backspaceButton.gameObject);
if (_input.Length > 0)
_input = _input.Substring(0, _input.Length - 1);
@@ -123,7 +123,7 @@ public class KeyboardManager : NetworkBehaviour
void OnEnterPressed()
{
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Click, gameObject);
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.LetterEnter, enterButton.gameObject);
if (_input.Length > 0)
{
@@ -134,7 +134,7 @@ public class KeyboardManager : NetworkBehaviour
void OnSpacePressed()
{
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.LetterEnter, gameObject);
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.LetterEnter, spaceButton.gameObject);
addToInput(" ");
UpdateOutput();

View File

@@ -4960,7 +4960,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 5
_componentIndexCache: 4
_addedNetworkObject: {fileID: 1717143407103097221}
_networkObjectCache: {fileID: 1717143407103097221}
_synchronizeParent: 0
@@ -5130,6 +5130,7 @@ GameObject:
- component: {fileID: 933290339694180838}
- component: {fileID: 2246675829434997248}
- component: {fileID: 1717143407103097221}
- component: {fileID: 2818003123056565107}
m_Layer: 0
m_Name: PaintGun
m_TagString: Untagged
@@ -5153,7 +5154,7 @@ Transform:
- {fileID: 4826320045276546127}
- {fileID: 316164716384481213}
m_Father: {fileID: 0}
m_RootOrder: 0
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 15}
--- !u!95 &894335529310106930
Animator:
@@ -5426,7 +5427,6 @@ MonoBehaviour:
- {fileID: 2246675829434997248}
- {fileID: 7380372828037789915}
- {fileID: 6466137562046178737}
- {fileID: 0}
- {fileID: 6641346233749009521}
- {fileID: 7265139984553989061}
<ParentNetworkObject>k__BackingField: {fileID: 0}
@@ -5442,6 +5442,19 @@ MonoBehaviour:
<SceneId>k__BackingField: 0
<AssetPathHash>k__BackingField: 8708812106909896480
_sceneNetworkObjects: []
--- !u!114 &2818003123056565107
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5253637933564617113}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7405dee79e06eca4795d2d3f39801f47, type: 3}
m_Name:
m_EditorClassIdentifier:
grabSoundType: 2
--- !u!1 &8789365678454855824
GameObject:
m_ObjectHideFlags: 0
@@ -5486,7 +5499,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a2836e36774ca1c4bbbee976e17b649c, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 4
_componentIndexCache: 3
_addedNetworkObject: {fileID: 1717143407103097221}
_networkObjectCache: {fileID: 1717143407103097221}
_synchronizeParent: 0

View File

@@ -32,7 +32,7 @@ public class FloorButtonVisualizer : MonoBehaviour
{
buttonImage.sprite = ActiveSprite;
// Play FMOD sound here
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Hover, gameObject);
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Hover, buttonImage.gameObject);
}
public void OnDeselect(BaseEventData eventData) // joystick moves away

View File

@@ -0,0 +1,9 @@
using UnityEngine;
using static FMODEvents;
public class GrabAudioProfile : MonoBehaviour
{
[SerializeField] private GrabSoundType grabSoundType = GrabSoundType.Default;
public GrabSoundType GrabSoundType => grabSoundType;
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7405dee79e06eca4795d2d3f39801f47
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -23,7 +23,7 @@ public class HoverSlideButton : MonoBehaviour, IPointerEnterHandler, IPointerExi
public void OnPointerEnter(PointerEventData eventData)
{
SlideToPosition(onPosition);
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Hover, gameObject); //3d oneshot sound
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Hover, buttonTransform.gameObject); //3d oneshot sound
}
public void OnPointerExit(PointerEventData eventData)

View File

@@ -91,7 +91,7 @@ public class MenuTeleportButton : MonoBehaviour
button.targetGraphic.GetComponent<Image>().sprite = HoverSprite;
}
// Play FMOD hover sound
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Hover, gameObject);
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Hover, button.gameObject);
}
public void OnDeselect(BaseEventData eventData)

View File

@@ -2,6 +2,8 @@ using _PROJECT.NewHandPresence;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.XR.Interaction.Toolkit;
using static FMODEvents;
using FMODUnity;
public class TutorialAudioListener : MonoBehaviour
{
@@ -61,6 +63,9 @@ public class TutorialAudioListener : MonoBehaviour
locomotionConfigurator.OnLocomotionToggled += HandleLocomotionToggled;
locomotionConfigurator.OnSpeedChanged += HandleSpeedChanged;
}
if (tutorialController != null)
tutorialController.OnGrab += HandleGrab;
}
private void OnDisable()
@@ -82,6 +87,8 @@ public class TutorialAudioListener : MonoBehaviour
locomotionConfigurator.OnLocomotionToggled -= HandleLocomotionToggled;
locomotionConfigurator.OnSpeedChanged -= HandleSpeedChanged;
}
if (tutorialController != null)
tutorialController.OnGrab -= HandleGrab;
}
private void HandleLocomotionToggled(bool enabled)
@@ -158,4 +165,42 @@ public class TutorialAudioListener : MonoBehaviour
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Steps, gameObject);
Debug.Log("[TeleportationListen] Teleport sound played.");
}
private EventReference GetGrabEvent(GrabSoundType type)
{
switch (type)
{
case GrabSoundType.Bow:
return FMODEvents.Instance.BowGrab;
case GrabSoundType.Sprayer:
return FMODEvents.Instance.SprayerGrab;
//Add more objects for grabbing here and do not forget to define them in FMODEvents.cs
//Add the GrabAudioProfile.cs component to an object instance
default:
return FMODEvents.Instance.DefaultGrab;
}
}
private void HandleGrab(XRGrabInteractable grab)
{
if (grab == null)
return;
var profile = grab.GetComponent<GrabAudioProfile>();
GrabSoundType type = profile != null
? profile.GrabSoundType
: GrabSoundType.Default;
EventReference grabEvent = GetGrabEvent(type);
Debug.Log(grabEvent);
AudioManager.Instance.PlayAttachedInstance(grabEvent, grab.gameObject);
}
}

View File

@@ -40,6 +40,7 @@ namespace _PROJECT.NewHandPresence
private List<XRGrabInteractable> _grabInteractables = new List<XRGrabInteractable>();
private XRGrabInteractable _grabInteractable;
public event Action<XRGrabInteractable> OnGrab;
private GameObject _billboard;
@@ -219,6 +220,11 @@ namespace _PROJECT.NewHandPresence
private void OnGripPerformed(SelectEnterEventArgs arg0)
{
var grab = arg0.interactableObject as XRGrabInteractable;
// Notify any listeners
OnGrab?.Invoke(grab);
if (_state != TutorialState.Grip) return;
Debug.Log("Grip performed");
UpdateState(_state.Next());

View File

@@ -2,42 +2,35 @@ using System.Collections;
using System.Collections.Generic;
using System.Runtime.Remoting.Messaging;
using UnityEngine;
using UnityEngine.PlayerLoop;
using UnityEngine.XR.Content.Interaction;
using FMOD.Studio;
public class AlarmTrigger : MonoBehaviour
{
public XRPushButton PushButton;
public AudioSource AlarmSequence;
public AudioSource VentilationSequence;
private EventInstance RoomHum;
private EventInstance AlarmSound;
private FirstPersonOcclusion occlusion;
private bool hasAlarm = false;
private void Awake()
{
RoomHum = AudioManager.Instance.CreateInstance(FMODEvents.Instance.ServerRoomHumming); //initialise the instance
RoomHum.setParameterByName("AlarmLogic", 1);
RoomHum.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject)); //make it 3d
//AlarmSound = AudioManager.Instance.CreateInstance(FMODEvents.Instance.ServerRoomAlarm); //initialise the instance
//AlarmSound.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject)); //make it 3d
AlarmSound = AudioManager.Instance.CreateInstance(FMODEvents.Instance.ServerRoomAlarm); //initialise the instance
occlusion = GetComponent<FirstPersonOcclusion>();
occlusion = GetComponent<FirstPersonOcclusion>(); //apply occlusion
if (occlusion != null)
{
occlusion.InitialiseWithInstance(RoomHum);
occlusion.InitialiseWithInstance(AlarmSound);
//occlusion.InitialiseWithInstance(AlarmSound);
}
}
void Start()
{
RoomHum.start();
//start playing the sound
//start playing the Server overall sound
//RoomHum.start();
if (PushButton != null)
{
@@ -51,8 +44,9 @@ public class AlarmTrigger : MonoBehaviour
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ServerRoomButton, PushButton.gameObject); //3d oneshot instance
Debug.Log("Alarm button Pressed!");
RoomHum.setParameterByName("AlarmLogic", 0);
hasAlarm = true;
RoomHum.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
AlarmSound.start();
}
void Update()
@@ -60,13 +54,11 @@ public class AlarmTrigger : MonoBehaviour
RoomHum.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject)); //updating 3d attributes
AlarmSound.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject)); //updating 3d attributes
VentilationSequence.Play(); // Return to normal.
RoomHum.start();
AlarmSound.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
hasAlarm = false;
// If alarm finished, restart hum once
if (!AudioManager.IsPlaying(AlarmSound) && !AudioManager.IsPlaying(RoomHum))
{
//RoomHum.start();
}
}
}

View File

@@ -96,10 +96,6 @@ PrefabInstance:
type: 3}
insertIndex: -1
addedObject: {fileID: 3964068808109647281}
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: ac65e655dd40bcd48b72b3f8ddcf45bd,
type: 3}
insertIndex: -1
addedObject: {fileID: 2488785156293713400}
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: ac65e655dd40bcd48b72b3f8ddcf45bd,
type: 3}
insertIndex: -1
@@ -133,129 +129,6 @@ MeshCollider:
m_Convex: 1
m_CookingOptions: 30
m_Mesh: {fileID: 6074735673208717538, guid: ac65e655dd40bcd48b72b3f8ddcf45bd, type: 3}
--- !u!82 &2488785156293713400
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7023167506039495560}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 5bcb02b6a0d913d4c90781538c787b2f, type: 3}
m_PlayOnAwake: 1
m_Volume: 0.05
m_Pitch: 1
Loop: 1
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 10
Pan2D: 0
rolloffMode: 2
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0.1
value: 1
inSlope: -10.0039835
outSlope: -10.0039835
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 0.2
value: 0.5
inSlope: -2.5009959
outSlope: -2.5009959
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 0.4
value: 0.25
inSlope: -0.62524897
outSlope: -0.62524897
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 0.7940491
value: 0.057891846
inSlope: -0.27374932
outSlope: -0.27374932
tangentMode: 0
weightedMode: 0
inWeight: 0.24773687
outWeight: 0
- serializedVersion: 3
time: 1
value: 0.018304445
inSlope: -0.10003988
outSlope: -0.10003988
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!114 &7307865721977554787
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@@ -234,6 +234,7 @@ GameObject:
- component: {fileID: 7888619987859216817}
- component: {fileID: 4423156612440135391}
- component: {fileID: 7492444969113415356}
- component: {fileID: 7342908215105292480}
m_Layer: 2
m_Name: TwoHandedBow
m_TagString: Untagged
@@ -258,7 +259,7 @@ Transform:
- {fileID: 390935087474091724}
- {fileID: 4619910383191300727}
m_Father: {fileID: 0}
m_RootOrder: 0
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!136 &6168004718997640786
CapsuleCollider:
@@ -663,7 +664,19 @@ MonoBehaviour:
arrowPrefab: {fileID: 5016704277711162129, guid: 5c51937e899ec9443a1757aefe9d49cb,
type: 3}
_arrowNetworkObject: {fileID: 0}
lastKnownLaunchDirection: {x: 0, y: 0, z: 0}
--- !u!114 &7342908215105292480
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6208239738837795797}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7405dee79e06eca4795d2d3f39801f47, type: 3}
m_Name:
m_EditorClassIdentifier:
grabSoundType: 1
--- !u!1 &6812977384739690676
GameObject:
m_ObjectHideFlags: 0
@@ -817,9 +830,9 @@ LineRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_Positions:
- {x: -76.62825, y: 6.285376, z: -11.368651}
- {x: -76.61169, y: 5.785746, z: -11.358892}
- {x: -76.59347, y: 5.2361526, z: -11.348157}
- {x: -4.723722, y: 5.7963943, z: 73.294556}
- {x: -4.7137837, y: 5.496616, z: 73.30041}
- {x: -4.702852, y: 5.1668596, z: 73.30685}
m_Parameters:
serializedVersion: 3
widthMultiplier: 0.01

View File

@@ -30,7 +30,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 35
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2377358742638333032
MonoBehaviour:
@@ -55,4 +55,4 @@ MonoBehaviour:
PlayerOcclusionWidening: 1
OcclusionLayer:
serializedVersion: 2
m_Bits: 2048
m_Bits: 268438528

View File

@@ -11,7 +11,6 @@ using STOP_MODE = FMOD.Studio.STOP_MODE;
public class AudioManager : MonoBehaviour
{
//VCAs (VCA buses) are mainly used for volume control
//Regular routing buses routing are for the remaining logic, for example, within the FMOD itself to put FMOD events inside the Mixer (Mixer Routing).
//Regular routing buses are used when we make some attenuation based on parameters and write the logic in code for Unity.
@@ -272,12 +271,6 @@ public class AudioManager : MonoBehaviour
}
public static bool IsPlaying()
{
musicEventInstance.getPlaybackState(out PLAYBACK_STATE state);
return state != PLAYBACK_STATE.STOPPED;
}
//=====//
//=====//

View File

@@ -14,7 +14,9 @@ public class FMODEvents : MonoBehaviour
[field: SerializeField] public EventReference Teleport { get; private set; }
[field: SerializeField] public EventReference UFODestroy { get; private set; }
[field: SerializeField] public EventReference PortalEnter { get; private set; }
[field: SerializeField] public EventReference SprayerTake { get; private set; }
[field: SerializeField] public EventReference SprayerGrab { get; private set; }
[field: SerializeField] public EventReference DefaultGrab { get; private set; }
[field: SerializeField] public EventReference BowGrab { get; private set; }
[field: SerializeField] public EventReference Spray { get; private set; }
[field: Header("CAR")]
@@ -60,6 +62,14 @@ public class FMODEvents : MonoBehaviour
public static FMODEvents Instance { get; private set; }
public enum GrabSoundType
{
Default,
Bow,
Sprayer
}
private void Awake()
{
if (Instance != null)

View File

@@ -29,8 +29,6 @@ public class FirstPersonOcclusion : MonoBehaviour
// ADDED: now stores ALL event instances that must be occluded
private List<EventInstance> managedInstances = new List<EventInstance>();
public void InitialiseWithInstance(EventInstance instance)
{
AudioOccluded = instance;
@@ -42,6 +40,8 @@ public class FirstPersonOcclusion : MonoBehaviour
GetComponent<Rigidbody>()
);
//instance.setParameterByName("Occlusion", 1f, true);
managedInstances.Add(AudioOccluded); // ADDED
AudioOccluded.getDescription(out AudioDes);
@@ -63,7 +63,6 @@ public class FirstPersonOcclusion : MonoBehaviour
}
}
private IEnumerator Start()
{
// If already initialised, skip internal creation