car occlusion, space ambience done
This commit is contained in:
@@ -27,7 +27,7 @@ public class CarDrivingRoutine : NetworkBehaviour
|
||||
|
||||
|
||||
private EventInstance CarMovement;
|
||||
|
||||
private FirstPersonOcclusion occlusion;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -41,6 +41,13 @@ public class CarDrivingRoutine : NetworkBehaviour
|
||||
CarMovement.setParameterByName("EasyBoltLogic", 0); //"Driving - 0 in FMOD"
|
||||
CarMovement.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject)); //setting 3d attributes
|
||||
|
||||
occlusion = GetComponent<FirstPersonOcclusion>();
|
||||
|
||||
if (occlusion != null)
|
||||
{
|
||||
occlusion.InitialiseWithInstance(CarMovement);
|
||||
}
|
||||
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.XR.CoreUtils;
|
||||
using UnityEngine;
|
||||
using FMOD.Studio;
|
||||
|
||||
public class ElevatorOuter : NetworkBehaviour
|
||||
{
|
||||
@@ -25,10 +26,24 @@ public class ElevatorOuter : NetworkBehaviour
|
||||
public ElevatorStatusPlate statusPlate;
|
||||
public AudioSource arrivalBeeper;
|
||||
|
||||
private EventInstance arrivalBeep;
|
||||
private FirstPersonOcclusion occlusion;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
doorOpenTime = box.doorOpenTime;
|
||||
doorCloseTime = box.doorCloseTime;
|
||||
|
||||
arrivalBeep = AudioManager.Instance.CreateInstance(FMODEvents.Instance.ElevatorArrival); //initialising the variable
|
||||
arrivalBeep.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject)); //setting 3d attributes
|
||||
|
||||
occlusion = GetComponent<FirstPersonOcclusion>();
|
||||
|
||||
if (occlusion != null)
|
||||
{
|
||||
occlusion.InitialiseWithInstance(arrivalBeep);
|
||||
}
|
||||
|
||||
}
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
@@ -77,6 +92,11 @@ public class ElevatorOuter : NetworkBehaviour
|
||||
Debug.Log("Outer Doors moved");
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
arrivalBeep.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject)); //updating the attributes
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -23,15 +23,15 @@ public class FloorButtonVisualizer : MonoBehaviour
|
||||
{
|
||||
this.ActiveState = true;
|
||||
buttonImage.sprite = ActiveSprite;
|
||||
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Hover, gameObject);
|
||||
// --- Only play hover if selection actually changed ---
|
||||
if (initialized && lastActiveButton != this)
|
||||
{
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Hover, gameObject);
|
||||
}
|
||||
//if (initialized && lastActiveButton != this)
|
||||
//{
|
||||
// AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Hover, gameObject);
|
||||
//}
|
||||
|
||||
lastActiveButton = this;
|
||||
initialized = true;
|
||||
//lastActiveButton = this;
|
||||
//initialized = true;
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
using FMOD.Studio;
|
||||
using FMODUnity;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.XR.CoreUtils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
using FMOD.Studio;
|
||||
using FMODUnity;
|
||||
|
||||
public class MenuTeleportButton : MonoBehaviour
|
||||
{
|
||||
@@ -28,6 +29,10 @@ public class MenuTeleportButton : MonoBehaviour
|
||||
private static MenuTeleportButton lastSelectedButton = null;
|
||||
private static bool initialized = false;
|
||||
|
||||
// External state: map must be held/visible
|
||||
public static bool MapIsOpen = false;
|
||||
private Menu menu;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
TeleportingSound = AudioManager.Instance.CreateInstance(FMODEvents.Instance.Teleport); //initialise the instance
|
||||
@@ -39,6 +44,7 @@ public class MenuTeleportButton : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
button = GetComponent<Button>();
|
||||
menu = FindObjectOfType<Menu>();
|
||||
|
||||
// Subscribe to button events
|
||||
button.onClick.AddListener(TeleportPlayer);
|
||||
@@ -66,13 +72,18 @@ public class MenuTeleportButton : MonoBehaviour
|
||||
button.targetGraphic.GetComponent<Image>().sprite = HoverSprite;
|
||||
|
||||
// --- Only play hover sound if selection actually changed ---
|
||||
if (initialized && lastSelectedButton != this)
|
||||
{
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Hover, gameObject);
|
||||
}
|
||||
//if (initialized && lastSelectedButton != this)
|
||||
//{
|
||||
// if (!Menu.IsMapOpen) return;
|
||||
// if (!menu.MapTab.activeSelf) return; // ensures only map page buttons make sound
|
||||
// AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Hover, gameObject);
|
||||
//}
|
||||
if (!Menu.IsMapOpen) return;
|
||||
if (!menu.MapTab.activeSelf) return; // ensures only map page buttons make sound
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Hover, gameObject);
|
||||
|
||||
lastSelectedButton = this;
|
||||
initialized = true;
|
||||
//lastSelectedButton = this;
|
||||
//initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,9 @@ public class Menu : MonoBehaviour
|
||||
|
||||
private bool hasFloorButtonSoundInitialized = false;
|
||||
private bool hasMapButtonSoundInitialized = false;
|
||||
|
||||
|
||||
public static bool IsMapOpen { get; private set; }
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -93,6 +95,8 @@ public class Menu : MonoBehaviour
|
||||
hasMapButtonSoundInitialized = true;
|
||||
|
||||
SetActiveTab(MenuTab.Map);
|
||||
|
||||
IsMapOpen = canvas.enabled;
|
||||
}
|
||||
|
||||
private void activateOptionsPanel()
|
||||
@@ -125,6 +129,8 @@ public class Menu : MonoBehaviour
|
||||
public void setCanvasVisibility(bool enabled)
|
||||
{
|
||||
canvas.enabled = enabled;
|
||||
|
||||
IsMapOpen = enabled;
|
||||
}
|
||||
|
||||
private void ToggleMenu(InputAction.CallbackContext context)
|
||||
|
||||
@@ -3376,6 +3376,22 @@ MonoBehaviour:
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
- eventID: 1
|
||||
callback:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 9130699439852735294}
|
||||
m_TargetAssemblyTypeName: FloorButtonVisualizer, Assembly-CSharp
|
||||
m_MethodName: Deactivate
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
--- !u!1 &4122378368372937094
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -3580,6 +3596,22 @@ MonoBehaviour:
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
- eventID: 1
|
||||
callback:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 2993125651756248496}
|
||||
m_TargetAssemblyTypeName: FloorButtonVisualizer, Assembly-CSharp
|
||||
m_MethodName: Deactivate
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
--- !u!1 &4552840262979230797
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -7838,6 +7870,26 @@ PrefabInstance:
|
||||
value:
|
||||
objectReference: {fileID: 21300000, guid: 50a077641946fcb48b05e51ec4936afc,
|
||||
type: 3}
|
||||
- target: {fileID: 2420913116824796466, guid: f2ade1e8dce12be43ab14956a6244406,
|
||||
type: 3}
|
||||
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.size
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2420913116824796466, guid: f2ade1e8dce12be43ab14956a6244406,
|
||||
type: 3}
|
||||
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Mode
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2420913116824796466, guid: f2ade1e8dce12be43ab14956a6244406,
|
||||
type: 3}
|
||||
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target
|
||||
value:
|
||||
objectReference: {fileID: 6428633840807731315}
|
||||
- target: {fileID: 2420913116824796466, guid: f2ade1e8dce12be43ab14956a6244406,
|
||||
type: 3}
|
||||
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_CallState
|
||||
value: 2
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3841795681097067811, guid: f2ade1e8dce12be43ab14956a6244406,
|
||||
type: 3}
|
||||
propertyPath: m_Pivot.x
|
||||
@@ -8068,9 +8120,9 @@ MonoBehaviour:
|
||||
callback:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 6428633840807731315}
|
||||
- m_Target: {fileID: 2839451055893527412}
|
||||
m_TargetAssemblyTypeName: MenuTeleportButton, Assembly-CSharp
|
||||
m_MethodName:
|
||||
m_MethodName: SetStateDefault
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
|
||||
@@ -8,11 +8,16 @@ public class SpaceEnterCollider : MonoBehaviour
|
||||
{
|
||||
public GameObject InstructionText;
|
||||
|
||||
private EventInstance PortalEntrance;
|
||||
private EventInstance PortalEntrance;
|
||||
private EventInstance SpaceMusic;
|
||||
|
||||
private bool musicStarted = false;
|
||||
private void Awake()
|
||||
{
|
||||
PortalEntrance = AudioManager.Instance.CreateInstance(FMODEvents.Instance.PortalEnter);
|
||||
|
||||
SpaceMusic = AudioManager.Instance.CreateInstance(FMODEvents.Instance.Kosmos);
|
||||
SpaceMusic.setParameterByName("KosmosMusicVolume", 1.0f);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
@@ -46,6 +51,15 @@ public class SpaceEnterCollider : MonoBehaviour
|
||||
|
||||
PortalEntrance.start();
|
||||
|
||||
if (!musicStarted)
|
||||
{
|
||||
SpaceMusic.start();
|
||||
musicStarted = true;
|
||||
}
|
||||
|
||||
// Fade music in on entering
|
||||
SpaceMusic.setParameterByName("KosmosMusicVolume", 0f);
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
@@ -63,7 +77,8 @@ public class SpaceEnterCollider : MonoBehaviour
|
||||
Debug.Log(other + " left space.");
|
||||
|
||||
PortalEntrance.start();
|
||||
|
||||
// Fade music out on leaving
|
||||
SpaceMusic.setParameterByName("KosmosMusicVolume", 1.0f);
|
||||
}
|
||||
|
||||
private IEnumerator DelayExit(GravityHandler playerGravity)
|
||||
|
||||
Binary file not shown.
@@ -3,6 +3,10 @@ using UnityEngine;
|
||||
|
||||
public class FMODEvents : MonoBehaviour
|
||||
{
|
||||
[field: Header("Musical Ambiences")]
|
||||
|
||||
[field: SerializeField] public EventReference Kosmos { get; private set; }
|
||||
|
||||
[field: Header("SFX")]
|
||||
[field: SerializeField] public EventReference Steps { get; private set; }
|
||||
[field: SerializeField] public EventReference StepSpin { get; private set; }
|
||||
|
||||
@@ -26,9 +26,6 @@ public class FirstPersonOcclusion : MonoBehaviour
|
||||
|
||||
private bool initialisedExternally = false;
|
||||
|
||||
// ============================================================
|
||||
// NEW <20> Optional external initialiser
|
||||
// ============================================================
|
||||
public void InitialiseWithInstance(EventInstance instance)
|
||||
{
|
||||
AudioOccluded = instance;
|
||||
@@ -43,32 +40,30 @@ public class FirstPersonOcclusion : MonoBehaviour
|
||||
AudioOccluded.getDescription(out AudioDes);
|
||||
AudioDes.getMinMaxDistance(out float min, out MaxDistance);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// ORIGINAL START <20> kept exactly the same unless external init used
|
||||
// ============================================================
|
||||
private IEnumerator Start()
|
||||
{
|
||||
// If already initialised, skip internal creation
|
||||
// 1. Event Instance Creation
|
||||
if (!initialisedExternally)
|
||||
{
|
||||
AudioOccluded = RuntimeManager.CreateInstance(SelectAudio);
|
||||
// 2. Attaching Instance
|
||||
RuntimeManager.AttachInstanceToGameObject(AudioOccluded, gameObject);
|
||||
// 3. Starting Audio
|
||||
AudioOccluded.start();
|
||||
// 4. Releasing Instance (This allows the event to self-manage its lifetime, which is fine)
|
||||
AudioOccluded.release();
|
||||
|
||||
// 5. Getting Event Description and Max Distance
|
||||
AudioDes = RuntimeManager.GetEventDescription(SelectAudio);
|
||||
AudioDes.getMinMaxDistance(out float minDistance, out MaxDistance);
|
||||
}
|
||||
|
||||
// Find listener (kept exactly as before)
|
||||
// 6. Finding Listener
|
||||
yield return new WaitUntil(() => FindObjectOfType<StudioListener>() != null);
|
||||
Listener = FindObjectOfType<StudioListener>();
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// UNCHANGED core functionality
|
||||
// ============================================================
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (Listener == null) return;
|
||||
@@ -77,16 +72,19 @@ public class FirstPersonOcclusion : MonoBehaviour
|
||||
AudioOccluded.getPlaybackState(out pb);
|
||||
ListenerDistance = Vector3.Distance(transform.position, Listener.transform.position);
|
||||
|
||||
// 7. Check Occlusion Condition
|
||||
if (!AudioIsVirtual && pb == PLAYBACK_STATE.PLAYING && ListenerDistance <= MaxDistance)
|
||||
{
|
||||
OccludeBetween(transform.position, Listener.transform.position);
|
||||
}
|
||||
|
||||
// 8. Reset Hit Count
|
||||
lineCastHitCount = 0f;
|
||||
}
|
||||
|
||||
private void OccludeBetween(Vector3 sound, Vector3 listener)
|
||||
{
|
||||
// 9. Calculate Points (Log only a few to avoid clutter)
|
||||
Vector3 SoundLeft = CalculatePoint(sound, listener, SoundOcclusionWidening, true);
|
||||
Vector3 SoundRight = CalculatePoint(sound, listener, SoundOcclusionWidening, false);
|
||||
|
||||
@@ -98,6 +96,7 @@ public class FirstPersonOcclusion : MonoBehaviour
|
||||
Vector3 ListenerAbove = new Vector3(listener.x, listener.y + PlayerOcclusionWidening * .5f, listener.z);
|
||||
Vector3 ListenerBelow = new Vector3(listener.x, listener.y - PlayerOcclusionWidening * .5f, listener.z);
|
||||
|
||||
// 10. Casting Lines (The line casts themselves will log hits)
|
||||
CastLine(SoundLeft, ListenerLeft);
|
||||
CastLine(SoundLeft, listener);
|
||||
CastLine(SoundLeft, ListenerRight);
|
||||
@@ -143,6 +142,7 @@ public class FirstPersonOcclusion : MonoBehaviour
|
||||
private void CastLine(Vector3 Start, Vector3 End)
|
||||
{
|
||||
RaycastHit hit;
|
||||
// 11. Raycast result
|
||||
bool isHit = Physics.Linecast(Start, End, out hit, OcclusionLayer);
|
||||
|
||||
if (isHit)
|
||||
@@ -159,6 +159,7 @@ public class FirstPersonOcclusion : MonoBehaviour
|
||||
private void SetParameter()
|
||||
{
|
||||
float occlusionValue = lineCastHitCount / 11;
|
||||
// 12. Final Parameter Value
|
||||
AudioOccluded.setParameterByName("Occlusion", occlusionValue);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user