Add music system

This commit is contained in:
Jens Pitkänen 2019-08-19 00:26:49 +03:00
parent c27c634faa
commit b5de77f807
19 changed files with 647 additions and 11 deletions

8
Assets/Audio.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a2f22fc2af5ca93428d49f6995dc11a6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

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

View File

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

Binary file not shown.

View File

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

Binary file not shown.

View File

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

Binary file not shown.

View File

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

View File

@ -195,6 +195,152 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 31108448}
m_PrefabAsset: {fileID: 0}
--- !u!1 &63561975
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 63561978}
- component: {fileID: 63561976}
- component: {fileID: 63561977}
m_Layer: 0
m_Name: Music Channel
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &63561976
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 63561975}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3d1e321cb8a85244c889d04f9b308b44, type: 3}
m_Name:
m_EditorClassIdentifier:
FadingOut: 0
FadingIn: 0
FadeDuration: 1
NextClip: {fileID: 0}
Volume: 0
Loop: 0
--- !u!82 &63561977
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 63561975}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_PlayOnAwake: 0
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
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: 0
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!4 &63561978
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 63561975}
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_Children: []
m_Father: {fileID: 2128473093}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &78398875
PrefabInstance:
m_ObjectHideFlags: 0
@ -14709,7 +14855,7 @@ PrefabInstance:
- target: {fileID: 8489029732530782807, guid: 14a47f86f9e45da45863a81716f2378b,
type: 3}
propertyPath: m_RootOrder
value: 5
value: 6
objectReference: {fileID: 0}
- target: {fileID: 8489029732530782807, guid: 14a47f86f9e45da45863a81716f2378b,
type: 3}
@ -14976,7 +15122,7 @@ Transform:
- {fileID: 628992541}
- {fileID: 1125139377}
m_Father: {fileID: 0}
m_RootOrder: 8
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &402096464
PrefabInstance:
@ -20014,6 +20160,152 @@ Rigidbody2D:
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!1 &632288128
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 632288131}
- component: {fileID: 632288129}
- component: {fileID: 632288130}
m_Layer: 0
m_Name: Ambience Channel
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &632288129
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 632288128}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3d1e321cb8a85244c889d04f9b308b44, type: 3}
m_Name:
m_EditorClassIdentifier:
FadingOut: 0
FadingIn: 0
FadeDuration: 1
NextClip: {fileID: 0}
Volume: 0
Loop: 0
--- !u!82 &632288130
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 632288128}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_PlayOnAwake: 0
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
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: 0
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!4 &632288131
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 632288128}
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_Children: []
m_Father: {fileID: 2128473093}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &639044074 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 1716831649928674037, guid: 597da139881c95c4893daac7d142af6c,
@ -20548,7 +20840,7 @@ Transform:
- {fileID: 800967889}
- {fileID: 982133696}
m_Father: {fileID: 0}
m_RootOrder: 10
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &729817018 stripped
Transform:
@ -21993,7 +22285,7 @@ Transform:
- {fileID: 750521286}
- {fileID: 794582329}
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &1056137387 stripped
Transform:
@ -111075,7 +111367,7 @@ Transform:
- {fileID: 1822937580}
- {fileID: 1619207830}
m_Father: {fileID: 0}
m_RootOrder: 9
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &1616078557 stripped
Transform:
@ -111914,7 +112206,7 @@ PrefabInstance:
- target: {fileID: 2690120730931629368, guid: aae49ec2806ad9941a301b7928af198a,
type: 3}
propertyPath: m_RootOrder
value: 12
value: 13
objectReference: {fileID: 0}
- target: {fileID: 2690120730931629368, guid: aae49ec2806ad9941a301b7928af198a,
type: 3}
@ -112765,7 +113057,7 @@ Transform:
- {fileID: 166998417}
- {fileID: 695076217}
m_Father: {fileID: 0}
m_RootOrder: 11
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &2099407198
PrefabInstance:
@ -112842,6 +113134,64 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 816864857}
m_PrefabAsset: {fileID: 0}
--- !u!1 &2128473091
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2128473093}
- component: {fileID: 2128473092}
m_Layer: 0
m_Name: Music Player
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &2128473092
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2128473091}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2810ad0730404124180b61ba43becb4b, type: 3}
m_Name:
m_EditorClassIdentifier:
MusicClips:
- {fileID: 8300000, guid: dc38876eefffefa48a872efb29330ee6, type: 3}
- {fileID: 8300000, guid: ae9eac1e06f113f4bba16d1122000b66, type: 3}
- {fileID: 8300000, guid: b98c1cde2e4eecc4d8e9cc8cf79656bc, type: 3}
- {fileID: 8300000, guid: b6a1333bf5f328c43b3a0410abe0ed91, type: 3}
AmbienceClips:
- {fileID: 8300000, guid: f0435c87049550543bb5bab74f62d280, type: 3}
ChannelPlayerForMusic: {fileID: 63561976}
ChannelPlayerForAmbience: {fileID: 632288129}
DebugMusicTrack: -1
DebugSetMusicTrack: 0
DebugAmbienceTrack: -1
DebugSetAmbienceTrack: 0
--- !u!4 &2128473093
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2128473091}
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_Children:
- {fileID: 63561978}
- {fileID: 632288131}
m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &2130862024 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 592487110401094196, guid: 1a0e05447c8cf2a4fa9b9dc697884a66,
@ -112968,7 +113318,7 @@ PrefabInstance:
- target: {fileID: 11699643827672082, guid: 254d8b252b63a6547810dd3729ddc91b,
type: 3}
propertyPath: m_RootOrder
value: 7
value: 8
objectReference: {fileID: 0}
- target: {fileID: 11699643827672082, guid: 254d8b252b63a6547810dd3729ddc91b,
type: 3}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f647facd3a8115a418f13b39efb1d157
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,43 @@
using UnityEngine;
namespace Saltosion.OneWeapon.Audio {
[RequireComponent(typeof(AudioSource))]
public class MusicChannelPlayer : MonoBehaviour {
public bool FadingOut;
public bool FadingIn;
public float FadeDuration;
public AudioClip NextClip;
public float Volume;
public bool Loop;
public bool CurrentlyPlaying { get { return Source.clip != null; } }
private AudioSource Source;
private void Start() {
Source = GetComponent<AudioSource>();
}
private void Update() {
if (!FadingOut && !FadingIn) {
Source.volume = Volume;
} else if (FadingIn && Source.clip == null) {
Source.clip = NextClip;
Source.loop = Loop;
if (Source.clip != null) {
Source.Play();
}
NextClip = null;
} else if (FadingOut && Source.volume > 0) {
Source.volume = Mathf.Clamp(Source.volume - Time.deltaTime / FadeDuration / Volume, 0, Volume);
} else if (FadingOut && Source.volume == 0) {
Source.Stop();
Source.clip = null;
FadingOut = false;
} else if (FadingIn && Source.volume < Volume) {
Source.volume = Mathf.Clamp(Source.volume + Time.deltaTime / FadeDuration / Volume, 0, Volume);
} else if (FadingIn && Source.volume == Volume) {
FadingIn = false;
}
}
}
}

View File

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

View File

@ -0,0 +1,87 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using Saltosion.OneWeapon.Utils;
namespace Saltosion.OneWeapon.Audio {
public enum MusicTrack {
None = -1,
Elevator = 0,
SetFireToReality, // 1, and so on
SpaceDimensions,
ThrustSequence,
}
public enum AmbienceTrack {
None = -1,
Dark = 0,
}
enum Channel {
Music, Ambience, Count
}
public class MusicPlayer : MonoBehaviour {
private static MusicPlayer Singleton;
private static int SingletonSceneIndex;
[Header("Audio files")]
public AudioClip[] MusicClips;
public AudioClip[] AmbienceClips;
[Header("Other")]
public MusicChannelPlayer ChannelPlayerForMusic;
public MusicChannelPlayer ChannelPlayerForAmbience;
public MusicTrack DebugMusicTrack = MusicTrack.None;
public bool DebugSetMusicTrack = false;
public AmbienceTrack DebugAmbienceTrack = AmbienceTrack.None;
public bool DebugSetAmbienceTrack = false;
private MusicChannelPlayer[] Channels;
private void Start() {
int Index = SceneManager.GetActiveScene().buildIndex;
if (SingletonSceneIndex == Index) {
Debug.LogWarning($"The scene '{SceneManager.GetActiveScene().name}' has multiple MusicPlayers!\nOnly the last to run Start() will be used.");
}
SingletonSceneIndex = Index;
Singleton = this;
Channels = new MusicChannelPlayer[(int)Channel.Count];
Channels[(int)Channel.Music] = ChannelPlayerForMusic;
Channels[(int)Channel.Ambience] = ChannelPlayerForAmbience;
}
private void Update() {
ChannelPlayerForMusic.Volume = Options.MusicVolume;
ChannelPlayerForAmbience.Volume = Options.AmbienceVolume;
if (DebugSetMusicTrack) {
DebugSetMusicTrack = false;
SetMusicTrack(DebugMusicTrack, true);
}
if (DebugSetAmbienceTrack) {
DebugSetAmbienceTrack = false;
SetAmbienceTrack(DebugAmbienceTrack, true);
}
}
private void SetChannelTrack(Channel channel, AudioClip clip, bool fade) {
int channelIndex = (int)channel;
if (Channels[channelIndex].CurrentlyPlaying) {
Channels[channelIndex].FadingOut = fade;
}
if (clip != null) {
Channels[channelIndex].FadingIn = fade;
Channels[channelIndex].NextClip = clip;
}
}
public static void SetMusicTrack(MusicTrack track, bool fade) {
Singleton.SetChannelTrack(Channel.Music, track == MusicTrack.None ? null : Singleton.MusicClips[(int)track], fade);
}
public static void SetAmbienceTrack(AmbienceTrack track, bool fade) {
Singleton.SetChannelTrack(Channel.Ambience, track == AmbienceTrack.None ? null : Singleton.AmbienceClips[(int)track], fade);
}
}
}

View File

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

View File

@ -1,6 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
using UnityEngine.SceneManagement;
using Saltosion.OneWeapon.Utils;
namespace Saltosion.OneWeapon.Effects {
@ -10,6 +9,8 @@ namespace Saltosion.OneWeapon.Effects {
public class DebrisLauncher : MonoBehaviour {
private static DebrisLauncher Singleton;
private static int SingletonSceneIndex;
public GameObject StructuralParticlePrefab;
public GameObject WoodParticlePrefab;
public GameObject BloodParticlePrefab;
@ -40,6 +41,11 @@ namespace Saltosion.OneWeapon.Effects {
}
private void Start() {
int Index = SceneManager.GetActiveScene().buildIndex;
if (SingletonSceneIndex == Index) {
Debug.LogWarning($"The scene '{SceneManager.GetActiveScene().name}' has multiple DebrisLaunchers!\nOnly the last to run Start() will be used.");
}
SingletonSceneIndex = Index;
Singleton = this;
}

View File

@ -1,5 +1,7 @@
namespace Saltosion.OneWeapon.Utils {
public class Options {
public static bool CensorGore = false;
public static float MusicVolume = 0.2f;
public static float AmbienceVolume = 0.1f;
}
}