feat: added basic ship sounds, pitch update method for manageable audio

This commit is contained in:
Jakob Feldmann 2024-04-12 15:37:59 +02:00
parent c635e0a0b7
commit 89970a7d1d
23 changed files with 713 additions and 46 deletions

View File

@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: d6edf602b3baa0741bd59cce098f05d5
AudioImporter:
externalObjects: {}
serializedVersion: 7
defaultSettings:
serializedVersion: 2
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
preloadAudioData: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: 025361f5b3f97a445ad89bc9ac61c30b
AudioImporter:
externalObjects: {}
serializedVersion: 7
defaultSettings:
serializedVersion: 2
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
preloadAudioData: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: 2fffe98b7bb97034a84e2153e8456258
AudioImporter:
externalObjects: {}
serializedVersion: 7
defaultSettings:
serializedVersion: 2
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
preloadAudioData: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: 029b2e37eed317c49841bf21a7a69233
AudioImporter:
externalObjects: {}
serializedVersion: 7
defaultSettings:
serializedVersion: 2
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
preloadAudioData: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
loadInBackground: 0
ambisonic: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@ -12,7 +12,7 @@ GameObject:
- component: {fileID: 3310727599597512245} - component: {fileID: 3310727599597512245}
- component: {fileID: 7696877450501702533} - component: {fileID: 7696877450501702533}
m_Layer: 0 m_Layer: 0
m_Name: Thruster Sound 01 m_Name: Boost Sound 1
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -46,7 +46,9 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
id: 1 id: 1
audioTag: sound audioTag: booster
pitchRange: 0.3
volumeRange: 0.3
--- !u!82 &7696877450501702533 --- !u!82 &7696877450501702533
AudioSource: AudioSource:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -57,18 +59,18 @@ AudioSource:
m_Enabled: 1 m_Enabled: 1
serializedVersion: 4 serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0} OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 82a8d17c2698c834f96370756847edec, type: 3} m_audioClip: {fileID: 8300000, guid: d6edf602b3baa0741bd59cce098f05d5, type: 3}
m_PlayOnAwake: 0 m_PlayOnAwake: 0
m_Volume: 0.112 m_Volume: 0.09
m_Pitch: 0.95 m_Pitch: 0.9
Loop: 1 Loop: 0
Mute: 0 Mute: 0
Spatialize: 0 Spatialize: 0
SpatializePostEffects: 0 SpatializePostEffects: 0
Priority: 128 Priority: 128
DopplerLevel: 0 DopplerLevel: 0
MinDistance: 1 MinDistance: 1
MaxDistance: 500 MaxDistance: 100
Pan2D: 0 Pan2D: 0
rolloffMode: 1 rolloffMode: 1
BypassEffects: 0 BypassEffects: 0

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2d949767c4bbb2d4c84c31779148dd2d
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,147 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4479628772504131522
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6423719894035945655}
- component: {fileID: 3310727599597512245}
- component: {fileID: 7696877450501702533}
m_Layer: 0
m_Name: Critical Tackle 1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6423719894035945655
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4479628772504131522}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3310727599597512245
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4479628772504131522}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 887650ff1f3850a43aa8d1281fc70528, type: 3}
m_Name:
m_EditorClassIdentifier:
id: 1
audioTag: critical_tackle
pitchRange: 0.3
volumeRange: 0.3
--- !u!82 &7696877450501702533
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4479628772504131522}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 029b2e37eed317c49841bf21a7a69233, type: 3}
m_PlayOnAwake: 0
m_Volume: 0.2
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 0
MinDistance: 1
MaxDistance: 100
Pan2D: 0
rolloffMode: 1
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
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
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: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 55bb0ab820069b74ebd9593beb03c465
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -45,11 +45,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 887650ff1f3850a43aa8d1281fc70528, type: 3} m_Script: {fileID: 11500000, guid: 887650ff1f3850a43aa8d1281fc70528, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
maxParallel: 1
id: 1 id: 1
audioTag: music audioTag: main_menu_music
audioSource: {fileID: 7696877450501702533}
audioSources: []
--- !u!82 &7696877450501702533 --- !u!82 &7696877450501702533
AudioSource: AudioSource:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -64,7 +61,7 @@ AudioSource:
m_PlayOnAwake: 0 m_PlayOnAwake: 0
m_Volume: 0.092 m_Volume: 0.092
m_Pitch: 0.95 m_Pitch: 0.95
Loop: 1 Loop: 0
Mute: 0 Mute: 0
Spatialize: 0 Spatialize: 0
SpatializePostEffects: 0 SpatializePostEffects: 0

View File

@ -0,0 +1,147 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4479628772504131522
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6423719894035945655}
- component: {fileID: 3310727599597512245}
- component: {fileID: 7696877450501702533}
m_Layer: 0
m_Name: Normal Tackle 1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6423719894035945655
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4479628772504131522}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3310727599597512245
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4479628772504131522}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 887650ff1f3850a43aa8d1281fc70528, type: 3}
m_Name:
m_EditorClassIdentifier:
id: 1
audioTag: normal_tackle
pitchRange: 0.3
volumeRange: 0.3
--- !u!82 &7696877450501702533
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4479628772504131522}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 2fffe98b7bb97034a84e2153e8456258, type: 3}
m_PlayOnAwake: 0
m_Volume: 0.15
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 0
MinDistance: 1
MaxDistance: 100
Pan2D: 0
rolloffMode: 1
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
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
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: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6c209fe6bd4ff4a4095b661bbd7ebc10
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,147 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4479628772504131522
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6423719894035945655}
- component: {fileID: 3310727599597512245}
- component: {fileID: 7696877450501702533}
m_Layer: 0
m_Name: Thruster Sound 1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6423719894035945655
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4479628772504131522}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3310727599597512245
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4479628772504131522}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 887650ff1f3850a43aa8d1281fc70528, type: 3}
m_Name:
m_EditorClassIdentifier:
id: 1
audioTag: thruster
pitchRange: 0.4
volumeRange: 0.3
--- !u!82 &7696877450501702533
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4479628772504131522}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 025361f5b3f97a445ad89bc9ac61c30b, type: 3}
m_PlayOnAwake: 0
m_Volume: 0.08
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 0
MinDistance: 1
MaxDistance: 100
Pan2D: 0
rolloffMode: 1
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
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
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: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4

View File

@ -263,10 +263,10 @@ BoxCollider:
m_Bits: 0 m_Bits: 0
m_LayerOverridePriority: 0 m_LayerOverridePriority: 0
m_IsTrigger: 0 m_IsTrigger: 0
m_ProvidesContacts: 0 m_ProvidesContacts: 1
m_Enabled: 1 m_Enabled: 1
serializedVersion: 3 serializedVersion: 3
m_Size: {x: 2.5, y: 0.5, z: 0.3} m_Size: {x: 2.5, y: 0.6, z: 0.6}
m_Center: {x: 0, y: 1.2, z: 0} m_Center: {x: 0, y: 1.2, z: 0}
--- !u!65 &4924634183815263034 --- !u!65 &4924634183815263034
BoxCollider: BoxCollider:
@ -284,10 +284,10 @@ BoxCollider:
m_Bits: 0 m_Bits: 0
m_LayerOverridePriority: 0 m_LayerOverridePriority: 0
m_IsTrigger: 0 m_IsTrigger: 0
m_ProvidesContacts: 0 m_ProvidesContacts: 1
m_Enabled: 1 m_Enabled: 1
serializedVersion: 3 serializedVersion: 3
m_Size: {x: 0.5, y: 2.5, z: 0.3} m_Size: {x: 0.6, y: 2.5, z: 0.6}
m_Center: {x: 0, y: 0.5, z: 0} m_Center: {x: 0, y: 0.5, z: 0}
--- !u!114 &2704141135220834432 --- !u!114 &2704141135220834432
MonoBehaviour: MonoBehaviour:

View File

@ -153,10 +153,10 @@ BoxCollider:
m_Bits: 0 m_Bits: 0
m_LayerOverridePriority: 0 m_LayerOverridePriority: 0
m_IsTrigger: 0 m_IsTrigger: 0
m_ProvidesContacts: 0 m_ProvidesContacts: 1
m_Enabled: 1 m_Enabled: 1
serializedVersion: 3 serializedVersion: 3
m_Size: {x: 2.5, y: 0.5, z: 0.3} m_Size: {x: 2.5, y: 0.6, z: 0.6}
m_Center: {x: 0, y: 1.2, z: 0} m_Center: {x: 0, y: 1.2, z: 0}
--- !u!65 &6404226307182575358 --- !u!65 &6404226307182575358
BoxCollider: BoxCollider:
@ -174,10 +174,10 @@ BoxCollider:
m_Bits: 0 m_Bits: 0
m_LayerOverridePriority: 0 m_LayerOverridePriority: 0
m_IsTrigger: 0 m_IsTrigger: 0
m_ProvidesContacts: 0 m_ProvidesContacts: 1
m_Enabled: 1 m_Enabled: 1
serializedVersion: 3 serializedVersion: 3
m_Size: {x: 0.5, y: 2.5, z: 0.3} m_Size: {x: 0.6, y: 2.5, z: 0.6}
m_Center: {x: 0, y: 0.5, z: 0} m_Center: {x: 0, y: 0.5, z: 0}
--- !u!1 &5332524459205227969 --- !u!1 &5332524459205227969
GameObject: GameObject:

View File

@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Reflection; using System.Reflection;
using log4net; using log4net;
using PrimeTween; using PrimeTween;
using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
public class ManageableAudio : MonoBehaviour public class ManageableAudio : MonoBehaviour
@ -12,15 +13,23 @@ public class ManageableAudio : MonoBehaviour
public int id = 0; public int id = 0;
public string audioTag = "audio"; public string audioTag = "audio";
public float pitchRange = 0.3f;
public float volumeRange = 0.3f;
public AudioSource AudioSource { get; set; } public AudioSource AudioSource { get; set; }
private float initialVolume;
private float initialPitch;
private bool IsUpdating = false; private bool IsUpdating = false;
private bool WasOneShotTriggered = false;
void Awake() void Awake()
{ {
if (gameObject.TryGetComponent(out AudioSource audioS)) if (gameObject.TryGetComponent(out AudioSource audioS))
{ {
AudioSource = audioS; AudioSource = audioS;
initialVolume = AudioSource.volume;
initialPitch = AudioSource.pitch;
} }
else else
{ {
@ -30,16 +39,27 @@ public class ManageableAudio : MonoBehaviour
} }
} }
public void PlayAudio() /// <summary>
/// Start playing the sound source.
/// </summary>
/// <param name="playLooping">Should the sound loop</param>
/// <param name="isOneShot">Play sound only once until reset</param>
public void PlayAudio(bool playLooping, bool isOneShot = false)
{ {
if (AudioSource == null || IsUpdating || AudioSource.isPlaying) if (AudioSource == null
|| IsUpdating
|| AudioSource.isPlaying
|| WasOneShotTriggered)
{ {
return; return;
} }
if (!AudioSource.enabled) if (isOneShot)
{ {
AudioSource.enabled = true; WasOneShotTriggered = true;
} }
AudioSource.enabled = true;
AudioSource.loop = playLooping;
AudioSource.Play(); AudioSource.Play();
} }
@ -52,9 +72,26 @@ public class ManageableAudio : MonoBehaviour
if (AudioSource.isPlaying) if (AudioSource.isPlaying)
{ {
AudioSource.Stop(); AudioSource.Stop();
// TODO: Reset audio properties?
} }
} }
/// <summary>
/// Updates the pitch of the audio clip.
/// </summary>
/// <param name="changeValue">-1 to 1 times the max pitch range
/// of this sound. </param>
public void ChangePitch(float changeValue)
{
changeValue = Mathf.Clamp(changeValue, -1, 1);
AudioSource.pitch = initialPitch + (changeValue * pitchRange);
}
public void ChangeVolume(float changeValue)
{
AudioSource.volume = initialVolume + (changeValue * volumeRange);
}
public void FadeOutAudio(float duration = 1) public void FadeOutAudio(float duration = 1)
{ {
if (IsUpdating) if (IsUpdating)
@ -63,12 +100,35 @@ public class ManageableAudio : MonoBehaviour
} }
IsUpdating = true; IsUpdating = true;
float initVolume = AudioSource.volume; float initVolume = AudioSource.volume;
Tween.Custom(initVolume, 0, duration, onValueChange: value => AudioSource.volume = value) Tween.Custom(initVolume, 0, duration, onValueChange: value =>
{
if (AudioSource.IsDestroyed())
{
return;
}
AudioSource.volume = value;
})
.OnComplete(() => .OnComplete(() =>
{ {
if (AudioSource.IsDestroyed())
{
return;
}
IsUpdating = false; IsUpdating = false;
StopAudio(); StopAudio();
AudioSource.volume = initVolume; AudioSource.volume = initVolume;
}); });
} }
/// <summary>
/// Makes starting this sound possible again,
/// if it was set to only play once.
/// </summary>
public void ResetOneShot()
{
if (!AudioSource.isPlaying)
{
WasOneShotTriggered = false;
}
}
} }

View File

@ -1,8 +1,10 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using log4net; using log4net;
using UnityEditor; using UnityEditor;
using UnityEditor.PackageManager;
using UnityEngine; using UnityEngine;
namespace Managers namespace Managers
@ -173,16 +175,24 @@ namespace Managers
private GameObject SearchSound(string audioTag = null, int id = -1, private GameObject SearchSound(string audioTag = null, int id = -1,
string prefabName = null) string prefabName = null)
{ {
if (prefabName == null) try
{ {
return audioDictionary. if (prefabName == null)
Where(manageableAudio => manageableAudio.Key.audioTag == audioTag). {
First(manageableAudio => manageableAudio.Key.id == id).Value; return audioDictionary.
Where(manageableAudio => manageableAudio.Key.audioTag == audioTag)?.
First(manageableAudio => manageableAudio.Key.id == id).Value;
}
else
{
return audioDictionary.
First(manageableAudio => manageableAudio.Value.name == prefabName).Value;
}
} }
else catch (Exception e)
{ {
return audioDictionary. Log.Error(e.Message);
First(manageableAudio => manageableAudio.Value.name == prefabName).Value; return null;
} }
} }

View File

@ -28,6 +28,13 @@ public class Ship : MonoBehaviour
private Zone zone = Zone.NimbleZone; private Zone zone = Zone.NimbleZone;
private ManageableAudio ThrusterSound; private ManageableAudio ThrusterSound;
private ManageableAudio BoosterSound;
private ManageableAudio ZoneChangeSound;
private ManageableAudio TackleOpponentSound;
private ManageableAudio CriticalTackleOpponentSound;
private ManageableAudio BeingTackledSound;
private ManageableAudio BeingCriticallyTackledSound;
private ManageableAudio CrashOutOfBoundsSound;
void Awake() void Awake()
{ {
@ -37,7 +44,11 @@ public class Ship : MonoBehaviour
GetComponent<AffectingForcesManager>(); GetComponent<AffectingForcesManager>();
} }
body = GetComponent<Rigidbody>(); body = GetComponent<Rigidbody>();
ThrusterSound = AudioManager.G.GetLocalSound("sound", 1, gameObject.transform); ThrusterSound = AudioManager.G.GetLocalSound("thruster", 1, gameObject.transform);
BoosterSound = AudioManager.G.GetLocalSound("booster", 1, gameObject.transform);
BeingTackledSound = AudioManager.G.GetLocalSound("normal_tackle", 1, gameObject.transform);
BeingCriticallyTackledSound = AudioManager.G.GetLocalSound("critical_tackle", 1, gameObject.transform);
//ZoneChangeSound = AudioManager.G.GetLocalSound("thruster_sound", 1, gameObject.transform);
} }
// Start is called before the first frame update // Start is called before the first frame update
@ -88,6 +99,7 @@ public class Ship : MonoBehaviour
// Rotate the vehicle with the current steer velocity // Rotate the vehicle with the current steer velocity
// Calculate the magnitude of the acceleration with the current thrust // Calculate the magnitude of the acceleration with the current thrust
UpdateMovement(); UpdateMovement();
UpdateSounds();
BoostStateUpdate(Time.deltaTime); BoostStateUpdate(Time.deltaTime);
UpdateTackleResponse(isCriticalTackle); UpdateTackleResponse(isCriticalTackle);
} }
@ -97,19 +109,10 @@ public class Ship : MonoBehaviour
/// </summary> /// </summary>
void UpdateMovement() void UpdateMovement()
{ {
if (math.abs(state.thrustInput) > 0)
{
ThrusterSound.PlayAudio();
}
else
{
ThrusterSound.FadeOutAudio(0.3f);
}
//Debug.Log("inupdatemove " + currentThrustInput); //Debug.Log("inupdatemove " + currentThrustInput);
// Player rotation is always possible and same speed // Player rotation is always possible and same speed
transform.Rotate(0, 0, -props.steerVelocity * state.steerInput * Time.deltaTime); transform.Rotate(0, 0, -props.steerVelocity * state.steerInput * Time.deltaTime);
transform.localEulerAngles = new Vector3(0, 0, transform.localEulerAngles.z);
// Get and apply the current Gravity // Get and apply the current Gravity
state.currentGravity = forceManager.GetGravityForInstance(InstanceID)(transform); state.currentGravity = forceManager.GetGravityForInstance(InstanceID)(transform);
@ -159,7 +162,9 @@ public class Ship : MonoBehaviour
Debug.DrawRay(transform.position, transform.up * (currentVelocity.magnitude + 3) * 0.5f, Debug.DrawRay(transform.position, transform.up * (currentVelocity.magnitude + 3) * 0.5f,
Color.black); Color.black);
body.transform.localPosition = body.transform.localPosition - new Vector3(0, 0, body.transform.localPosition.z); // Fix the ship to the virtual 2D plane of the game
transform.localEulerAngles = new Vector3(0, 0, transform.localEulerAngles.z);
body.transform.localPosition -= new Vector3(0, 0, transform.localPosition.z);
} }
/// <summary> /// <summary>
@ -324,10 +329,49 @@ public class Ship : MonoBehaviour
} }
Vector3 colliderVelocity = collider.attachedRigidbody.velocity; Vector3 colliderVelocity = collider.attachedRigidbody.velocity;
Vector3 tackleDirection = transform.position - collider.transform.position; Vector3 tackleDirection = transform.position - collider.transform.position;
tackleDirection = Vector3.ProjectOnPlane(tackleDirection, Vector3.Cross(transform.up, transform.right));
// tackleDirection = Vector3.ProjectOnPlane(tackleDirection,
// Vector3.Cross(transform.up, transform.right));
body.AddForce(colliderVelocity.magnitude * tackleDirection * tacklePowerFactor, body.AddForce(colliderVelocity.magnitude * tackleDirection * tacklePowerFactor,
ForceMode.Acceleration); ForceMode.Acceleration);
UpdateTackleResponse(true); UpdateTackleResponse(true);
} }
void UpdateSounds()
{
if (math.abs(state.thrustInput) > 0 || IsBoosting())
{
ThrusterSound.PlayAudio(true);
ThrusterSound.ChangePitch(
math.smoothstep(0, props.normalMaxVelocity, body.velocity.magnitude));
}
else
{
ThrusterSound.FadeOutAudio(0.3f);
}
if (IsBoosting())
{
BoosterSound.PlayAudio(false, true);
}
else
{
BoosterSound.ResetOneShot();
}
if (isTackled && !isCriticalTackle)
{
BeingTackledSound.PlayAudio(false, true);
}
if (isCriticalTackle)
{
BeingCriticallyTackledSound.PlayAudio(false, true);
}
if (!isTackled)
{
BeingCriticallyTackledSound.ResetOneShot();
BeingTackledSound.ResetOneShot();
}
}
} }

View File

@ -100,8 +100,8 @@ namespace SlimUI.ModernMenu
firstMenu.SetActive(true); firstMenu.SetActive(true);
// Position1(); // Position1();
SetThemeColors(); SetThemeColors();
MainMenuMusic = AudioManager.G.GetGlobalSound("music", 1, true); MainMenuMusic = AudioManager.G.GetGlobalSound("main_menu_music", 1, true);
MainMenuMusic.PlayAudio(); MainMenuMusic.PlayAudio(true);
} }
void SetThemeColors() void SetThemeColors()