Initial commit: Unity WordConnect project
This commit is contained in:
22
Assets/WordConnectGameToolkit/Scripts/Audio/IAudioService.cs
Normal file
22
Assets/WordConnectGameToolkit/Scripts/Audio/IAudioService.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace WordsToolkit.Scripts.Audio
|
||||
{
|
||||
public interface IAudioService
|
||||
{
|
||||
void PlaySound(AudioClip clip);
|
||||
void PlayDelayed(AudioClip clip, float delay);
|
||||
void PlaySoundsRandom(AudioClip[] clips);
|
||||
void PlayPopupShow();
|
||||
void PlayPopupClose();
|
||||
void PlayClick(AudioClip overrideClickSound);
|
||||
void PlayCoins();
|
||||
void PlayIncremental(int selectedLettersCount);
|
||||
void PlayOpenWord();
|
||||
void PlayBonus();
|
||||
void PlayWrong();
|
||||
void PlayWin();
|
||||
void PlayBonusGetting();
|
||||
void PlaySoundExclusive(AudioClip sound);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a6c574fa191a41adbc3fc0eebaebc90
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/WordConnectGameToolkit/Scripts/Audio/MusicBase.cs
Normal file
33
Assets/WordConnectGameToolkit/Scripts/Audio/MusicBase.cs
Normal file
@ -0,0 +1,33 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
using WordsToolkit.Scripts.System;
|
||||
|
||||
namespace WordsToolkit.Scripts.Audio
|
||||
{
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class MusicBase : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private AudioMixer mixer;
|
||||
|
||||
[SerializeField]
|
||||
private string musicParameter = "musicVolume";
|
||||
|
||||
private void Start()
|
||||
{
|
||||
mixer.SetFloat(musicParameter, PlayerPrefs.GetInt("Music", 1) == 0 ? -80 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 948bdbeeb220479ba6e36947c8f043f6
|
||||
timeCreated: 1704217383
|
||||
173
Assets/WordConnectGameToolkit/Scripts/Audio/SoundBase.cs
Normal file
173
Assets/WordConnectGameToolkit/Scripts/Audio/SoundBase.cs
Normal file
@ -0,0 +1,173 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
using WordsToolkit.Scripts.System;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace WordsToolkit.Scripts.Audio
|
||||
{
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class SoundBase : MonoBehaviour, IAudioService
|
||||
{
|
||||
[SerializeField]
|
||||
private AudioMixer mixer;
|
||||
|
||||
[SerializeField]
|
||||
private string soundParameter = "soundVolume";
|
||||
|
||||
[SerializeField]
|
||||
public AudioClip click;
|
||||
|
||||
public AudioClip[] swish;
|
||||
public AudioClip coins;
|
||||
public AudioClip coinsSpend;
|
||||
public AudioClip luckySpin;
|
||||
public AudioClip warningTime;
|
||||
public AudioClip bonus;
|
||||
public AudioClip gemSound;
|
||||
public AudioClip[] combo;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
private readonly HashSet<AudioClip> clipsPlaying = new();
|
||||
[SerializeField]
|
||||
private AudioClip openWord;
|
||||
|
||||
[SerializeField]
|
||||
private AudioClip wrong;
|
||||
|
||||
[SerializeField]
|
||||
private AudioClip win;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
mixer.SetFloat(soundParameter, PlayerPrefs.GetInt("Sound", 1) == 0 ? -80 : 0);
|
||||
}
|
||||
|
||||
public void PlaySound(AudioClip clip)
|
||||
{
|
||||
if (clip != null)
|
||||
{
|
||||
audioSource.PlayOneShot(clip);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayDelayed(AudioClip clip, float delay)
|
||||
{
|
||||
StartCoroutine(PlayDelayedCoroutine(clip, delay));
|
||||
}
|
||||
|
||||
private IEnumerator PlayDelayedCoroutine(AudioClip clip, float delay)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
PlaySound(clip);
|
||||
}
|
||||
|
||||
public void PlaySoundsRandom(AudioClip[] clip)
|
||||
{
|
||||
PlaySound(clip[Random.Range(0, clip.Length)]);
|
||||
}
|
||||
|
||||
public void PlayPopupShow()
|
||||
{
|
||||
// PlaySound(swish[0]);
|
||||
}
|
||||
|
||||
public void PlayPopupClose()
|
||||
{
|
||||
// PlaySound(swish[1]);
|
||||
}
|
||||
|
||||
public void PlayClick(AudioClip overrideClickSound)
|
||||
{
|
||||
PlaySound(overrideClickSound != null ? overrideClickSound : click);
|
||||
}
|
||||
|
||||
public void PlayCoins()
|
||||
{
|
||||
PlaySound(coins);
|
||||
}
|
||||
|
||||
public void PlayBonusGetting()
|
||||
{
|
||||
PlaySound(gemSound);
|
||||
}
|
||||
|
||||
public void PlaySoundExclusive([NotNull] AudioClip sound)
|
||||
{
|
||||
if (sound == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (clipsPlaying.Add(sound))
|
||||
{
|
||||
audioSource.PlayOneShot(sound);
|
||||
StartCoroutine(WaitForCompleteSound(sound, 1));
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayIncremental(int selectedLettersCount)
|
||||
{
|
||||
if (selectedLettersCount > 0 && selectedLettersCount <= combo.Length)
|
||||
{
|
||||
PlaySound(combo[selectedLettersCount - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayOpenWord()
|
||||
{
|
||||
PlayLimitSound(openWord, 1);
|
||||
}
|
||||
|
||||
public void PlayBonus()
|
||||
{
|
||||
PlaySound(bonus);
|
||||
}
|
||||
|
||||
public void PlayWrong()
|
||||
{
|
||||
PlaySound(wrong);
|
||||
}
|
||||
|
||||
public void PlayWin()
|
||||
{
|
||||
PlaySound(win);
|
||||
}
|
||||
|
||||
public void PlayLimitSound(AudioClip clip, int sec)
|
||||
{
|
||||
if (clipsPlaying.Add(clip))
|
||||
{
|
||||
PlaySound(clip);
|
||||
StartCoroutine(WaitForCompleteSound(clip, sec));
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator WaitForCompleteSound(AudioClip clip, int sec)
|
||||
{
|
||||
yield return new WaitForSeconds(sec);
|
||||
clipsPlaying.Remove(clip);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2dcae87cba276d84da88cca70d5ab1cc
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@ -0,0 +1,45 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace WordsToolkit.Scripts.Audio
|
||||
{
|
||||
public class UISoundSequence : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private AudioClip[] clips;
|
||||
|
||||
private int _index;
|
||||
private IAudioService _audioService;
|
||||
|
||||
public void Construct(IAudioService audioService)
|
||||
{
|
||||
_audioService = audioService;
|
||||
}
|
||||
|
||||
public void PlaySound()
|
||||
{
|
||||
if (clips.Length == 0 || _audioService == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_audioService.PlaySound(clips[_index]);
|
||||
_index++;
|
||||
if (_index >= clips.Length)
|
||||
{
|
||||
_index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec4f308c3c4449aead46df19c04c56fe
|
||||
timeCreated: 1704730324
|
||||
Reference in New Issue
Block a user