From 6c5cb5a65983014d3034a0d4057ae3ce00fbb852 Mon Sep 17 00:00:00 2001 From: Yann Dupont 01 Date: Sun, 3 Apr 2022 17:59:59 -0400 Subject: [PATCH] Wave start SFX --- Assets/Prefabs/Arena.prefab | 106 ++++++++++++++ Assets/Prefabs/Audio Source 2D.prefab | 129 +++++++++++++++++ Assets/Prefabs/Audio Source 2D.prefab.meta | 7 + Assets/Scripts/Arena.cs | 152 ++++++++++++--------- 4 files changed, 326 insertions(+), 68 deletions(-) create mode 100644 Assets/Prefabs/Audio Source 2D.prefab create mode 100644 Assets/Prefabs/Audio Source 2D.prefab.meta diff --git a/Assets/Prefabs/Arena.prefab b/Assets/Prefabs/Arena.prefab index 38322f7..56f9575 100644 --- a/Assets/Prefabs/Arena.prefab +++ b/Assets/Prefabs/Arena.prefab @@ -60693,6 +60693,37 @@ Transform: m_Father: {fileID: 9196727425507610130} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &7733931892361074138 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6491101087853085319} + m_Layer: 0 + m_Name: Audio Sources + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6491101087853085319 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7733931892361074138} + 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: 7795525019298260169} + m_Father: {fileID: 9196727425507610130} + m_RootOrder: 12 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8205972623206729468 GameObject: m_ObjectHideFlags: 0 @@ -62319,6 +62350,7 @@ Transform: - {fileID: 1787272690} - {fileID: 1853140661} - {fileID: 7588367539711513062} + - {fileID: 6491101087853085319} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -62353,6 +62385,13 @@ MonoBehaviour: k__BackingField: {fileID: 793317230} k__BackingField: {fileID: 1787272690} k__BackingField: {fileID: 1550580935} + currWaveSize: 0 + waveSource: {fileID: 3547338400796300921} + waveSounds: + - {fileID: 8300000, guid: f485fbe748a48b446b4e06c349ae2107, type: 3} + - {fileID: 8300000, guid: 4eb309ec26566484d9843c15f85f1d72, type: 3} + - {fileID: 8300000, guid: c374925f1f2c1f84286b9d9917bbdb80, type: 3} + soundManager: {fileID: 0} --- !u!114 &1359990806 MonoBehaviour: m_ObjectHideFlags: 0 @@ -63439,6 +63478,73 @@ Transform: m_CorrespondingSourceObject: {fileID: 1933134022928666816, guid: 4da2d7c3520f17b4ebee7e57a5908d12, type: 3} m_PrefabInstance: {fileID: 2093421722} m_PrefabAsset: {fileID: 0} +--- !u!1001 &1542312141482263668 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 6491101087853085319} + m_Modifications: + - target: {fileID: 2758730940586161386, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + propertyPath: m_Name + value: Wave Source + objectReference: {fileID: 0} + - target: {fileID: 8739270309622046909, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + propertyPath: m_RootOrder + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8739270309622046909, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8739270309622046909, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8739270309622046909, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8739270309622046909, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8739270309622046909, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8739270309622046909, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8739270309622046909, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8739270309622046909, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8739270309622046909, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8739270309622046909, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} +--- !u!82 &3547338400796300921 stripped +AudioSource: + m_CorrespondingSourceObject: {fileID: 2620472399707132429, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + m_PrefabInstance: {fileID: 1542312141482263668} + m_PrefabAsset: {fileID: 0} +--- !u!4 &7795525019298260169 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 8739270309622046909, guid: e44eba2abf026f34c9d225a115f5d55a, type: 3} + m_PrefabInstance: {fileID: 1542312141482263668} + m_PrefabAsset: {fileID: 0} --- !u!1001 &3218203505444173496 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Audio Source 2D.prefab b/Assets/Prefabs/Audio Source 2D.prefab new file mode 100644 index 0000000..2abcf2e --- /dev/null +++ b/Assets/Prefabs/Audio Source 2D.prefab @@ -0,0 +1,129 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &2758730940586161386 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 8739270309622046909} + - component: {fileID: 2620472399707132429} + m_Layer: 0 + m_Name: Audio Source 2D + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &8739270309622046909 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2758730940586161386} + 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: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!82 &2620472399707132429 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2758730940586161386} + 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 diff --git a/Assets/Prefabs/Audio Source 2D.prefab.meta b/Assets/Prefabs/Audio Source 2D.prefab.meta new file mode 100644 index 0000000..bfe8506 --- /dev/null +++ b/Assets/Prefabs/Audio Source 2D.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e44eba2abf026f34c9d225a115f5d55a +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Arena.cs b/Assets/Scripts/Arena.cs index d3140e2..cc45e4a 100644 --- a/Assets/Scripts/Arena.cs +++ b/Assets/Scripts/Arena.cs @@ -6,84 +6,100 @@ using UnityEngine; using Random = UnityEngine.Random; public class Arena : MonoBehaviour { - [Serializable] - struct GladiatorEntrance { - public Vector2 position; - public Vector2 direction; - } - - [SerializeField] [Required] - GameFlowManager gameFlowManager = null!; + [Serializable] + struct GladiatorEntrance { + public Vector2 position; + public Vector2 direction; + } - //TODO Add some kind of "MinLength(1)" attribute - [SerializeField] - GladiatorEntrance[] spawners = null!; - [SerializeField] [Required] - ArenaStats stats = null!; - [SerializeField] [Required] - GameObject entityPrefab = null!; + [SerializeField] + [Required] + GameFlowManager gameFlowManager = null!; - [field: SerializeField] [field: Required] - public Transform gladiatorParent { get; private set; } = null!; + //TODO Add some kind of "MinLength(1)" attribute + [SerializeField] + GladiatorEntrance[] spawners = null!; + [SerializeField] + [Required] + ArenaStats stats = null!; + [SerializeField] + [Required] + GameObject entityPrefab = null!; - [field: SerializeField] [field: Required] - public Transform minionParent { get; private set; } = null!; + [field: SerializeField] + [field: Required] + public Transform gladiatorParent { get; private set; } = null!; - [field: SerializeField] [field: Required] - public Transform graveyard { get; private set; } = null!; + [field: SerializeField] + [field: Required] + public Transform minionParent { get; private set; } = null!; - SafeZone safeZone = null!; - [field: SerializeField]int currWaveSize = 0; - - void Awake() => safeZone = GetComponentInChildren(); + [field: SerializeField] + [field: Required] + public Transform graveyard { get; private set; } = null!; - void Start() => StartCoroutine(SpawnEnemies()); + SafeZone safeZone = null!; + [field: SerializeField] int currWaveSize = 0; - void SpawnEnemy(int spawnerIndex) { - if (!gameFlowManager.CanDoAction) - return; - - var gladiator = Instantiate(entityPrefab, gladiatorParent).GetComponent(); - gladiator.arena = this; - float randFloat = Random.Range(0.1f, 0.5f); - Vector2 offset = new Vector2(randFloat, randFloat); - gladiator.transform.position = spawners[spawnerIndex].position + offset; - gladiator.direction = spawners[spawnerIndex].direction; - gladiator.gameFlowManager = gameFlowManager; - } + [SerializeField] AudioSource waveSource; + [SerializeField] AudioClip[] waveSounds; + [HideInInspector] public SoundManager soundManager; - IEnumerator SpawnEnemies() { - yield return new WaitForSeconds(stats.initWaitToSpawn); - currWaveSize = stats.initWaveSize; - int currentSpawner = 0; - int amountSpawned = 0; - int wave = 1; - while(true){ - while (amountSpawned < currWaveSize) { - currentSpawner = Random.Range(0, spawners.Length); - SpawnEnemy(currentSpawner); - amountSpawned++; - } - if(wave++ >= stats.increaseWaveStep){ - if((currWaveSize += stats.waveIncrease) > stats.maxWaveSize) currWaveSize=stats.maxWaveSize; - } - amountSpawned = 0; - yield return new WaitForSeconds(stats.secondsBetweenSpawners); - } - - } - public Vector3 GetMoatExtents(){ - return safeZone.GetMoatExtents(); - } + void Awake() { + safeZone = GetComponentInChildren(); + soundManager = FindObjectOfType(); + } + + void Start() => StartCoroutine(SpawnEnemies()); + + void SpawnEnemy(int spawnerIndex) { + if (!gameFlowManager.CanDoAction) + return; + + var gladiator = Instantiate(entityPrefab, gladiatorParent).GetComponent(); + gladiator.arena = this; + float randFloat = Random.Range(0.1f, 0.5f); + Vector2 offset = new Vector2(randFloat, randFloat); + gladiator.transform.position = spawners[spawnerIndex].position + offset; + gladiator.direction = spawners[spawnerIndex].direction; + gladiator.gameFlowManager = gameFlowManager; + } + + IEnumerator SpawnEnemies() { + yield return new WaitForSeconds(stats.initWaitToSpawn); + currWaveSize = stats.initWaveSize; + int currentSpawner = 0; + int amountSpawned = 0; + int wave = 1; + while (true) { + + soundManager.PlaySound(waveSource, waveSounds, randomPitch: true, createTempSourceIfBusy: true); + while (amountSpawned < currWaveSize) { + currentSpawner = Random.Range(0, spawners.Length); + SpawnEnemy(currentSpawner); + amountSpawned++; + } + if (wave++ >= stats.increaseWaveStep) { + if ((currWaveSize += stats.waveIncrease) > stats.maxWaveSize) currWaveSize = stats.maxWaveSize; + } + amountSpawned = 0; + yield return new WaitForSeconds(stats.secondsBetweenSpawners); + } + + } + + public Vector3 GetMoatExtents() { + return safeZone.GetMoatExtents(); + } #if UNITY_EDITOR - void OnDrawGizmosSelected() { - Gizmos.color = Color.blue; - foreach (GladiatorEntrance entrance in spawners) { - Gizmos.DrawWireCube(entrance.position, Vector3.one); - Gizmos.DrawLine(entrance.position, entrance.position + entrance.direction); - } - } + void OnDrawGizmosSelected() { + Gizmos.color = Color.blue; + foreach (GladiatorEntrance entrance in spawners) { + Gizmos.DrawWireCube(entrance.position, Vector3.one); + Gizmos.DrawLine(entrance.position, entrance.position + entrance.direction); + } + } #endif } \ No newline at end of file