a few sound changes, occlusion different approach, test cafeteria ambience
This commit is contained in:
parent
ee6e8d21ac
commit
dddb082288
@ -30,12 +30,12 @@ public class CarDrivingRoutine : MonoBehaviour
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Debug.LogError("AUDIO MANAGER:");
|
||||
Debug.LogError(AudioManager.Instance);
|
||||
Debug.LogError("FMOD EVENTS INSTANCE:");
|
||||
Debug.LogError(FMODEvents.Instance);
|
||||
Debug.LogError("Car Simple Driving:");
|
||||
Debug.LogError(FMODEvents.Instance.BoltCarSimpleDriving);
|
||||
//Debug.LogError("AUDIO MANAGER:");
|
||||
//Debug.LogError(AudioManager.Instance);
|
||||
//Debug.LogError("FMOD EVENTS INSTANCE:");
|
||||
//Debug.LogError(FMODEvents.Instance);
|
||||
//Debug.LogError("Car Simple Driving:");
|
||||
//Debug.LogError(FMODEvents.Instance.BoltCarSimpleDriving);
|
||||
CarMovement = AudioManager.Instance.CreateInstance(FMODEvents.Instance.BoltCarSimpleDriving); //initialising the variable
|
||||
CarMovement.setParameterByName("EasyBoltLogic", 0); //"Driving - 0 in FMOD"
|
||||
CarMovement.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject)); //setting 3d attributes
|
||||
|
||||
@ -1692,7 +1692,7 @@ GameObject:
|
||||
- component: {fileID: 150987804393607111}
|
||||
- component: {fileID: 2849620166313326850}
|
||||
- component: {fileID: 3623653364064856318}
|
||||
- component: {fileID: 7579737766687674392}
|
||||
- component: {fileID: 8520142921819688320}
|
||||
m_Layer: 0
|
||||
m_Name: NetworkManagerUI
|
||||
m_TagString: Untagged
|
||||
@ -1791,7 +1791,7 @@ AudioListener:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8920648335286241163}
|
||||
m_Enabled: 1
|
||||
--- !u!114 &7579737766687674392
|
||||
--- !u!114 &8520142921819688320
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
@ -1800,7 +1800,7 @@ MonoBehaviour:
|
||||
m_GameObject: {fileID: 8920648335286241163}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 1d73fa3572b1bcb498317047ac4154df, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 0be1f6fa249e2b74d80c57af214b930d, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
VRToggle: {fileID: 48284653022802127}
|
||||
|
||||
@ -124,7 +124,6 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 6021721823031538141}
|
||||
- component: {fileID: 4707456952479937532}
|
||||
- component: {fileID: 5921542733598710255}
|
||||
m_Layer: 0
|
||||
m_Name: Portal
|
||||
m_TagString: Untagged
|
||||
@ -292,37 +291,6 @@ AudioSource:
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
--- !u!114 &5921542733598710255
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4777591596180506993}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9a6610d2e704f1648819acc8d7460285, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
CollisionTag:
|
||||
EventReference:
|
||||
Guid:
|
||||
Data1: 214152321
|
||||
Data2: 1136432684
|
||||
Data3: -1979358295
|
||||
Data4: 727957873
|
||||
Path: event:/Ambiences/PortalSpacial
|
||||
Event:
|
||||
EventPlayTrigger: 1
|
||||
EventStopTrigger: 0
|
||||
AllowFadeout: 1
|
||||
TriggerOnce: 0
|
||||
Preload: 0
|
||||
NonRigidbodyVelocity: 0
|
||||
Params: []
|
||||
OverrideAttenuation: 0
|
||||
OverrideMinDistance: 1
|
||||
OverrideMaxDistance: 30
|
||||
--- !u!1 &6014189720456933605
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -442,6 +410,7 @@ GameObject:
|
||||
- component: {fileID: 8089229340536715967}
|
||||
- component: {fileID: 7305371174892849299}
|
||||
- component: {fileID: 3068203956378754948}
|
||||
- component: {fileID: 8075624572819615333}
|
||||
m_Layer: 0
|
||||
m_Name: Portal
|
||||
m_TagString: Untagged
|
||||
@ -588,3 +557,34 @@ Rigidbody:
|
||||
m_Interpolate: 0
|
||||
m_Constraints: 0
|
||||
m_CollisionDetection: 0
|
||||
--- !u!114 &8075624572819615333
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8507770192447112443}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9a6610d2e704f1648819acc8d7460285, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
CollisionTag:
|
||||
EventReference:
|
||||
Guid:
|
||||
Data1: 214152321
|
||||
Data2: 1136432684
|
||||
Data3: -1979358295
|
||||
Data4: 727957873
|
||||
Path: event:/Ambiences/PortalSpacial
|
||||
Event:
|
||||
EventPlayTrigger: 1
|
||||
EventStopTrigger: 2
|
||||
AllowFadeout: 1
|
||||
TriggerOnce: 0
|
||||
Preload: 0
|
||||
NonRigidbodyVelocity: 0
|
||||
Params: []
|
||||
OverrideAttenuation: 0
|
||||
OverrideMinDistance: 1
|
||||
OverrideMaxDistance: 35
|
||||
|
||||
@ -65,7 +65,7 @@ MonoBehaviour:
|
||||
m_GameObject: {fileID: 876842842715561968}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: eec8a9cc39cfe9c4a99a2b3cfef89628, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 57482196a5f80f14e9ad4e37725565db, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
secret: deltavr
|
||||
@ -79,12 +79,12 @@ MonoBehaviour:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 876842842715561968}
|
||||
m_Enabled: 1
|
||||
m_Enabled: 0
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3d1d3aad6cea63b43bf2b8374073066f, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: 311935930cc63b04389ffba3f12e96e1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
networkDiscovery: {fileID: 4784684551416650039}
|
||||
networkDiscovery: {fileID: 0}
|
||||
--- !u!114 &3642215892935434233
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
BIN
Assets/_PROJECT/Scenes/DeltaBuilding_base.unity
(Stored with Git LFS)
BIN
Assets/_PROJECT/Scenes/DeltaBuilding_base.unity
(Stored with Git LFS)
Binary file not shown.
198
Assets/_PROJECT/Scripts/Audio/Occlusion.cs
Normal file
198
Assets/_PROJECT/Scripts/Audio/Occlusion.cs
Normal file
@ -0,0 +1,198 @@
|
||||
using UnityEngine;
|
||||
using FMODUnity;
|
||||
using FMOD.Studio;
|
||||
|
||||
public class FirstPersonOcclusion : MonoBehaviour
|
||||
{
|
||||
[Header("FMOD Event")]
|
||||
[SerializeField]
|
||||
private FMODUnity.EventReference SelectAudio;
|
||||
private EventInstance AudioOccluded;
|
||||
private EventDescription AudioDes;
|
||||
private StudioListener Listener;
|
||||
private PLAYBACK_STATE pb;
|
||||
|
||||
[Header("Occlusion Options")]
|
||||
[SerializeField]
|
||||
[Range(0f, 10f)]
|
||||
private float SoundOcclusionWidening = 1f;
|
||||
[SerializeField]
|
||||
[Range(0f, 10f)]
|
||||
private float PlayerOcclusionWidening = 1f;
|
||||
[SerializeField]
|
||||
private LayerMask OcclusionLayer;
|
||||
|
||||
private bool AudioIsVirtual;
|
||||
private float MaxDistance;
|
||||
private float ListenerDistance;
|
||||
private float lineCastHitCount = 0f;
|
||||
private Color colour;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Debug.Log("--- Start Method ---");
|
||||
|
||||
// 1. Event Instance Creation
|
||||
AudioOccluded = RuntimeManager.CreateInstance(SelectAudio);
|
||||
Debug.Log($"Created FMOD Event Instance for: {SelectAudio.Path}");
|
||||
|
||||
// 2. Attaching Instance
|
||||
RuntimeManager.AttachInstanceToGameObject(AudioOccluded, gameObject);
|
||||
Debug.Log($"Attached FMOD Event Instance to GameObject: {gameObject.name}");
|
||||
|
||||
// 3. Starting Audio
|
||||
AudioOccluded.start();
|
||||
Debug.Log("Started FMOD Event Instance.");
|
||||
|
||||
// 4. Releasing Instance (This allows the event to self-manage its lifetime, which is fine)
|
||||
AudioOccluded.release();
|
||||
Debug.Log("Released FMOD Event Instance.");
|
||||
|
||||
// 5. Getting Event Description and Max Distance
|
||||
AudioDes = RuntimeManager.GetEventDescription(SelectAudio);
|
||||
AudioDes.getMinMaxDistance(out float minDistance, out MaxDistance);
|
||||
Debug.Log($"FMOD Event Min/Max Distance: {minDistance:F2} / {MaxDistance:F2}");
|
||||
|
||||
// 6. Finding Listener
|
||||
Listener = FindObjectOfType<StudioListener>();
|
||||
if (Listener != null)
|
||||
{
|
||||
Debug.Log($"Found FMOD StudioListener on GameObject: {Listener.gameObject.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("FATAL: Could not find FMOD StudioListener in the scene!");
|
||||
}
|
||||
Debug.Log("--- End Start Method ---");
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
// Debug.Log("--- FixedUpdate Method ---"); // Too frequent, only log conditions
|
||||
|
||||
AudioOccluded.isVirtual(out AudioIsVirtual);
|
||||
AudioOccluded.getPlaybackState(out pb);
|
||||
ListenerDistance = Vector3.Distance(transform.position, Listener.transform.position);
|
||||
|
||||
// 7. Check Occlusion Condition
|
||||
if (!AudioIsVirtual && pb == PLAYBACK_STATE.PLAYING && ListenerDistance <= MaxDistance)
|
||||
{
|
||||
Debug.Log($"Occlusion Check: Not Virtual, Playing, Distance {ListenerDistance:F2} <= Max {MaxDistance:F2}. Calling OccludeBetween.");
|
||||
OccludeBetween(transform.position, Listener.transform.position);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Log reasons why occlusion is NOT being checked
|
||||
if (AudioIsVirtual) Debug.Log("Occlusion Skipped: Audio is Virtual.");
|
||||
if (pb != PLAYBACK_STATE.PLAYING) Debug.Log($"Occlusion Skipped: Playback State is not PLAYING. State: {pb}");
|
||||
if (ListenerDistance > MaxDistance) Debug.Log($"Occlusion Skipped: Distance {ListenerDistance:F2} > Max Distance {MaxDistance:F2}.");
|
||||
}
|
||||
|
||||
// 8. Reset Hit Count
|
||||
// Debug.Log($"Resetting lineCastHitCount from {lineCastHitCount:F0} to 0.");
|
||||
lineCastHitCount = 0f;
|
||||
}
|
||||
|
||||
private void OccludeBetween(Vector3 sound, Vector3 listener)
|
||||
{
|
||||
Debug.Log("--- OccludeBetween Method ---");
|
||||
|
||||
// 9. Calculate Points (Log only a few to avoid clutter)
|
||||
Vector3 SoundLeft = CalculatePoint(sound, listener, SoundOcclusionWidening, true);
|
||||
Vector3 SoundRight = CalculatePoint(sound, listener, SoundOcclusionWidening, false);
|
||||
// Debug.Log($"Sound Positions: Center {sound}, Left {SoundLeft}, Right {SoundRight}");
|
||||
|
||||
Vector3 ListenerLeft = CalculatePoint(listener, sound, PlayerOcclusionWidening, true);
|
||||
Vector3 ListenerRight = CalculatePoint(listener, sound, PlayerOcclusionWidening, false);
|
||||
// Debug.Log($"Listener Positions: Center {listener}, Left {ListenerLeft}, Right {ListenerRight}");
|
||||
|
||||
Vector3 SoundAbove = new Vector3(sound.x, sound.y + SoundOcclusionWidening, sound.z);
|
||||
Vector3 SoundBelow = new Vector3(sound.x, sound.y - SoundOcclusionWidening, sound.z);
|
||||
Vector3 ListenerAbove = new Vector3(listener.x, listener.y + PlayerOcclusionWidening * 0.5f, listener.z);
|
||||
Vector3 ListenerBelow = new Vector3(listener.x, listener.y - PlayerOcclusionWidening * 0.5f, listener.z);
|
||||
|
||||
// 10. Casting Lines (The line casts themselves will log hits)
|
||||
CastLine(SoundLeft, ListenerLeft);
|
||||
CastLine(SoundLeft, listener);
|
||||
CastLine(SoundLeft, ListenerRight);
|
||||
|
||||
CastLine(sound, ListenerLeft);
|
||||
CastLine(sound, listener);
|
||||
CastLine(sound, ListenerRight);
|
||||
|
||||
CastLine(SoundRight, ListenerLeft);
|
||||
CastLine(SoundRight, listener);
|
||||
CastLine(SoundRight, ListenerRight);
|
||||
|
||||
CastLine(SoundAbove, ListenerAbove);
|
||||
CastLine(SoundBelow, ListenerBelow);
|
||||
|
||||
if (PlayerOcclusionWidening == 0f || SoundOcclusionWidening == 0f)
|
||||
{
|
||||
colour = Color.blue;
|
||||
}
|
||||
else
|
||||
{
|
||||
colour = Color.green;
|
||||
}
|
||||
|
||||
SetParameter();
|
||||
Debug.Log("--- End OccludeBetween Method ---");
|
||||
}
|
||||
|
||||
private Vector3 CalculatePoint(Vector3 a, Vector3 b, float m, bool posOrneg)
|
||||
{
|
||||
// Debug.Log($"Calculating offset point for: {a} to {b} with magnitude {m} and posOrneg {posOrneg}");
|
||||
float x;
|
||||
float z;
|
||||
// n is the 2D distance between a and b
|
||||
float n = Vector3.Distance(new Vector3(a.x, 0f, a.z), new Vector3(b.x, 0f, b.z));
|
||||
float mn = (m / n);
|
||||
|
||||
// Safety check for division by zero (if sound and listener are exactly on top of each other horizontally)
|
||||
if (n == 0f)
|
||||
{
|
||||
// If points are on the same XZ position, just return the point 'a'
|
||||
// Debug.LogWarning("CalculatePoint: Division by zero avoided. Sound and Listener are at the same XZ position.");
|
||||
return a;
|
||||
}
|
||||
|
||||
if (posOrneg)
|
||||
{
|
||||
x = a.x + (mn * (a.z - b.z));
|
||||
z = a.z - (mn * (a.x - b.x));
|
||||
}
|
||||
else
|
||||
{
|
||||
x = a.x - (mn * (a.z - b.z));
|
||||
z = a.z + (mn * (a.x - b.x));
|
||||
}
|
||||
return new Vector3(x, a.y, z);
|
||||
}
|
||||
|
||||
private void CastLine(Vector3 Start, Vector3 End)
|
||||
{
|
||||
RaycastHit hit;
|
||||
// 11. Raycast result
|
||||
bool isHit = Physics.Linecast(Start, End, out hit, OcclusionLayer);
|
||||
|
||||
if (isHit)
|
||||
{
|
||||
lineCastHitCount++;
|
||||
Debug.Log($"Linecast HIT! Hit Count: {lineCastHitCount:F0}/11. Object hit: {hit.collider.name}.");
|
||||
Debug.DrawLine(Start, End, Color.red);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.DrawLine(Start, End, colour);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetParameter()
|
||||
{
|
||||
float occlusionValue = lineCastHitCount / 11; // 11 is the total number of line casts
|
||||
// 12. Final Parameter Value
|
||||
Debug.Log($"Setting FMOD Parameter 'Occlusion' to: {occlusionValue:F2} (Hits: {lineCastHitCount:F0}/11)");
|
||||
AudioOccluded.setParameterByName("Occlusion", occlusionValue);
|
||||
}
|
||||
}
|
||||
11
Assets/_PROJECT/Scripts/Audio/Occlusion.cs.meta
Normal file
11
Assets/_PROJECT/Scripts/Audio/Occlusion.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c6205a218222364ca440c740b7a6b8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
DeltaVRFMOD/.cache/fsbcache/Desktop/9A9A0CD9.fobj
Normal file
BIN
DeltaVRFMOD/.cache/fsbcache/Desktop/9A9A0CD9.fobj
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user