forked from Unity-Technologies/ECS-Network-Racing-Sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudio.cs
More file actions
40 lines (37 loc) · 1.21 KB
/
Copy pathAudio.cs
File metadata and controls
40 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using Unity.Mathematics;
using Unity.Physics;
using Unity.Transforms;
namespace Unity.Entities.Racing.Common
{
/// <summary>
/// Points to the Entities with AudioSource attached
/// </summary>
public struct AudioSourceTag : IComponentData
{
}
/// <summary>
/// Stores Volume Data
/// </summary>
public struct VolumeData : IComponentData
{
public float Min;
public float Max;
}
/// <summary>
/// References the components to Calculate volume according to the velocity.
/// </summary>
public readonly partial struct AudioAspect : IAspect
{
public readonly Entity Self;
readonly RefRO<PhysicsVelocity> m_Velocity;
readonly RefRO<LocalToWorld> m_LocalToWorld;
private readonly RefRO<VolumeData> m_VolumeData;
public LocalToWorld LocalToWorld => m_LocalToWorld.ValueRO;
public float GetVolumeRange()
{
var audioVolumeRange = new float2(m_VolumeData.ValueRO.Min, m_VolumeData.ValueRO.Max);
var linearVelocityMagnitude = math.length(m_Velocity.ValueRO.Linear);
return math.min(audioVolumeRange.y, audioVolumeRange.x + (linearVelocityMagnitude / 100f));
}
}
}