added music triggers

This commit is contained in:
cyndrdev 2021-03-24 11:50:07 +00:00
parent 7d786ecdf6
commit 9bcde1e028
8 changed files with 380 additions and 6 deletions

View File

@ -44,7 +44,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 27f3f5345a3cb684195f070b3d44bc05, type: 3} m_Script: {fileID: 11500000, guid: 27f3f5345a3cb684195f070b3d44bc05, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_musicId: event:/Music/WIPMusic _musicId: event:/Music/MultiMusic
_trackDeltaPerSecond: 2.5
_musicBus: _musicBus:
BusName: Music BusName: Music
PlayerPref: {fileID: 11400000, guid: 45598e626e9c27c428f33cca2dd341e2, type: 2} PlayerPref: {fileID: 11400000, guid: 45598e626e9c27c428f33cca2dd341e2, type: 2}

View File

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

View File

@ -0,0 +1,60 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1670603406037581903
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1670603406037581902}
- component: {fileID: 1670603406037581897}
- component: {fileID: 1670603406037581898}
m_Layer: 0
m_Name: MusicTriggerZone
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1670603406037581902
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1670603406037581903}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -26, y: 0, z: 57}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &1670603406037581897
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1670603406037581903}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 10, y: 10, z: 1}
m_Center: {x: 0, y: 5, z: 0}
--- !u!114 &1670603406037581898
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1670603406037581903}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 42ae269bbe33edf4fb811511820ba248, type: 3}
m_Name:
m_EditorClassIdentifier:
_track: 7

View File

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

View File

@ -662,6 +662,39 @@ Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 3ea432459c1408040880f4c027fab559, type: 3} m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 3ea432459c1408040880f4c027fab559, type: 3}
m_PrefabInstance: {fileID: 3060674078935020117} m_PrefabInstance: {fileID: 3060674078935020117}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1 &239903584
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 239903585}
m_Layer: 0
m_Name: MusicTriggers
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &239903585
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 239903584}
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: 796404683}
- {fileID: 1869566704}
- {fileID: 1060814304}
m_Father: {fileID: 0}
m_RootOrder: 13
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &240211937 stripped --- !u!1 &240211937 stripped
GameObject: GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: e73358a549de9664fa0a48ccdea07e1c, type: 3} m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: e73358a549de9664fa0a48ccdea07e1c, type: 3}
@ -2358,6 +2391,11 @@ Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: e20114b5c13a067488940c5cc8e13b60, type: 3} m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: e20114b5c13a067488940c5cc8e13b60, type: 3}
m_PrefabInstance: {fileID: 3060674078300009146} m_PrefabInstance: {fileID: 3060674078300009146}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!4 &796404683 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
m_PrefabInstance: {fileID: 1670603406786800517}
m_PrefabAsset: {fileID: 0}
--- !u!1 &797647646 stripped --- !u!1 &797647646 stripped
GameObject: GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 506f92c064b9c494f981ac4216e033a8, type: 3} m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 506f92c064b9c494f981ac4216e033a8, type: 3}
@ -3096,6 +3134,84 @@ Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: ef7a51de2c5c5c5438ce6fea733533b2, type: 3} m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: ef7a51de2c5c5c5438ce6fea733533b2, type: 3}
m_PrefabInstance: {fileID: 3060674079011159413} m_PrefabInstance: {fileID: 3060674079011159413}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1001 &1060814303
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 239903585}
m_Modifications:
- target: {fileID: 1670603406037581897, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_Size.x
value: 18
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581897, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_Size.y
value: 18
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581897, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_Size.z
value: 18
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581898, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: _track
value: 4
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalPosition.x
value: 14.5
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalPosition.z
value: -31
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581903, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_Name
value: MusicTriggerZone (2)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
--- !u!4 &1060814304 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
m_PrefabInstance: {fileID: 1060814303}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &1063558645 --- !u!1001 &1063558645
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -5997,6 +6113,72 @@ Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 4a31c57c3ca869448a5849436b526efa, type: 3} m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 4a31c57c3ca869448a5849436b526efa, type: 3}
m_PrefabInstance: {fileID: 3060674078962375218} m_PrefabInstance: {fileID: 3060674078962375218}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1001 &1869566703
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 239903585}
m_Modifications:
- target: {fileID: 1670603406037581898, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: _track
value: 3
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalPosition.x
value: -7
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalPosition.z
value: 27
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalRotation.w
value: 0.97629607
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalRotation.y
value: -0.21643952
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: -25
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581903, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_Name
value: MusicTriggerZone (1)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
--- !u!4 &1869566704 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
m_PrefabInstance: {fileID: 1869566703}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1871781663 stripped --- !u!1 &1871781663 stripped
GameObject: GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: e20114b5c13a067488940c5cc8e13b60, type: 3} m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: e20114b5c13a067488940c5cc8e13b60, type: 3}
@ -6768,6 +6950,67 @@ GameObject:
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!1001 &1670603406786800517
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 239903585}
m_Modifications:
- target: {fileID: 1670603406037581898, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: _track
value: 2
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalPosition.x
value: -26
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalPosition.z
value: 57
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581902, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1670603406037581903, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
propertyPath: m_Name
value: MusicTriggerZone
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 69243a66990c1e7459a7579bf6208a7d, type: 3}
--- !u!1001 &3060674077596672761 --- !u!1001 &3060674077596672761
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -1,9 +1,10 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine; using UnityEngine;
using FMOD; using FMOD;
using FMOD.Studio;
using FMODUnity; using FMODUnity;
using EventInstance = FMOD.Studio.EventInstance;
[RequireComponent(typeof(FMODUnity.StudioBankLoader))] [RequireComponent(typeof(FMODUnity.StudioBankLoader))]
public class AudioManager : MonoBehaviour public class AudioManager : MonoBehaviour
@ -26,6 +27,14 @@ public class AudioManager : MonoBehaviour
[EventRef] [EventRef]
private string _musicId; private string _musicId;
[SerializeField]
private float _trackDeltaPerSecond;
private const string TRACK_PARAM = "Track";
private float _currentTrack = 1f;
private int _targetTrack = 1;
[SerializeField] [SerializeField]
private AdjustableAudioBus _musicBus; private AdjustableAudioBus _musicBus;
@ -38,19 +47,35 @@ public class AudioManager : MonoBehaviour
[SerializeField] [SerializeField]
private AdjustableAudioBus _uiBus; private AdjustableAudioBus _uiBus;
public AudioManager Instance { get; private set; } private static AudioManager _instance;
private EventInstance _musicInstance; private EventInstance _musicInstance;
public static void SetTrack( int track, bool forceLower = false )
{
if ( forceLower || track > _instance._targetTrack )
{
_instance._targetTrack = track;
}
}
void Update()
{
float dt = Time.deltaTime;
float maxDelta = dt * _trackDeltaPerSecond;
_currentTrack = Mathf.MoveTowards( _currentTrack, (float) _targetTrack, maxDelta );
_musicInstance.setParameterByName( TRACK_PARAM, _currentTrack );
}
void Awake() void Awake()
{ {
if ( Instance != null ) if ( _instance != null )
{ {
Destroy( gameObject ); Destroy( gameObject );
return; return;
} }
Instance = this; _instance = this;
GetComponent<StudioBankLoader>().enabled = true; GetComponent<StudioBankLoader>().enabled = true;

View File

@ -0,0 +1,19 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MusicTriggerZone : MonoBehaviour
{
[SerializeField]
[Range( 1, 7 )]
private int _track = 1;
[SerializeField]
private bool _forceIfLower;
private void OnTriggerEnter( Collider other )
{
AudioManager.SetTrack( _track, _forceIfLower );
}
}

View File

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