Skip to content

Commit

Permalink
feat: add sounds pack and SoundController script
Browse files Browse the repository at this point in the history
  • Loading branch information
PottierLoic committed Jun 11, 2024
1 parent fc046e1 commit d3427cd
Show file tree
Hide file tree
Showing 134 changed files with 1,837 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.wav filter=lfs diff=lfs merge=lfs -text
153 changes: 153 additions & 0 deletions Assets/Scenes/Overworld.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 84dd3b136997e6847ba290bdd6cbc182, type: 3}
m_Name:
m_EditorClassIdentifier:
target: {fileID: 0}
--- !u!1 &535217824
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -4143,6 +4144,157 @@ SpriteRenderer:
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1 &2138242348
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2138242350}
- component: {fileID: 2138242349}
- component: {fileID: 2138242351}
m_Layer: 0
m_Name: AudioController
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!82 &2138242349
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2138242348}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 1591a192142d8244f99cad42bcbe6060, type: 3}
m_PlayOnAwake: 1
m_Volume: 0.1
m_Pitch: 1
Loop: 1
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 &2138242350
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2138242348}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 255.57622, y: -197.27144, z: -0.041661486}
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 &2138242351
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2138242348}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 09c996ea91fd0ac4b921c49fca0d4325, type: 3}
m_Name:
m_EditorClassIdentifier:
ambientSounds:
- {fileID: 8300000, guid: 5b8ccd7337897014a8f6e00c001692cb, type: 3}
- {fileID: 8300000, guid: 780b1d078a03f0c4aa8d6cde6e01a68f, type: 3}
stepSounds:
- {fileID: 8300000, guid: 5d29567606ea9254b856e5c8cff283d0, type: 3}
- {fileID: 8300000, guid: e0ce243c0fa28f24b887d4e536c955f0, type: 3}
- {fileID: 8300000, guid: cc391033b385f28448423754f9bb2002, type: 3}
harvestSounds:
- {fileID: 8300000, guid: 3fcbbc1daf0e713419497273962b1eb5, type: 3}
- {fileID: 8300000, guid: 62e20edab80ecae40ad015eb7830e38b, type: 3}
--- !u!1 &2144208184
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -4260,3 +4412,4 @@ SceneRoots:
- {fileID: 658727431}
- {fileID: 1548304763}
- {fileID: 251996530}
- {fileID: 2138242350}
2 changes: 1 addition & 1 deletion Assets/Scripts/Camera/CameraFollow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class CameraFollow : MonoBehaviour {
private float _smoothSpeed = 0.4f;
private Vector3 _velocity = Vector3.zero;

private Transform target;
[SerializeField] public Transform target;
private Transform oldTarget;

void Start() {
Expand Down
6 changes: 5 additions & 1 deletion Assets/Scripts/CharacterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ public class CharacterController2D : MonoBehaviour {
private FieldTile _currentNearestTile = null;
private List<FieldTile> nearbyTiles = new List<FieldTile>();
private Vector2 _movement = Vector2.zero;
private AudioController _audioController;

void Start() {
_animator = GetComponent<Animator>();
_rigidbody = GetComponent<Rigidbody2D>();
_audioController = GameObject.Find("AudioController").GetComponent<AudioController>();
_currentSpeed = _walkSpeed;
}

Expand All @@ -32,8 +34,9 @@ void Update() {
if (Input.GetKey(KeyCode.S)) _movement.y = -1;
if (Input.GetKey(KeyCode.A)) _movement.x = -1;
if (Input.GetKey(KeyCode.D)) _movement.x = 1;
_currentSpeed = (Input.GetKey(KeyCode.LeftControl)) ? _runSpeed : _walkSpeed;
_currentSpeed = (Input.GetKey(KeyCode.LeftShift)) ? _runSpeed : _walkSpeed;
HandleAnimation(_movement);
_audioController.HandleStepSounds(_movement.magnitude > 0);
}

UpdateNearestTile();
Expand All @@ -48,6 +51,7 @@ void HandleAnimation(Vector2 movement) {
}

void StartGathering() {
_audioController.PlayHarvestSound(0.3f);
if (_currentNearestTile != null) {
Vector2 toTile = _currentNearestTile.transform.position - transform.position;
DetermineDirection(toTile);
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/Sounds.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions Assets/Scripts/Sounds/AudioController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioController : MonoBehaviour {
public AudioClip[] ambientSounds;
public AudioClip[] stepSounds;
public AudioClip[] harvestSounds;

private AudioSource audioSource;

private float _stepSoundTimer = 0f;
private float _stepSoundDelay = 0.6f;

void Start() {
audioSource = GetComponent<AudioSource>();
PlayAmbientSound();
}

void Update() {
// TODO: Change ambient theme based on time of day
}

public void PlayStepSound() {
int index = Random.Range(0, stepSounds.Length);
audioSource.PlayOneShot(stepSounds[index]);
}

public void HandleStepSounds(bool isMoving) {
if (isMoving) {
_stepSoundTimer += Time.deltaTime;
if (_stepSoundTimer >= _stepSoundDelay) {
PlayStepSound();
_stepSoundTimer = 0f;
}
} else {
_stepSoundTimer = 0f;
}
}

public void PlayHarvestSound(float delay = 0f) {
StartCoroutine(PlayHarvestSoundWithDelay(delay));
}

private IEnumerator PlayHarvestSoundWithDelay(float delay) {
yield return new WaitForSeconds(delay);
int index = Random.Range(0, harvestSounds.Length);
audioSource.PlayOneShot(harvestSounds[index]);
}

public void PlayAmbientSound() {
int index = Random.Range(0, ambientSounds.Length);
audioSource.PlayOneShot(ambientSounds[index]);
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Sounds/AudioController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Sounds/Ambient.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Sounds/Ambient/Overworld.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Git LFS file not shown

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Git LFS file not shown

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Sounds/Farm_SFX_Pack_Minifantasy_Compatible.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d3427cd

Please sign in to comment.