game over UI done, rematch left
This commit is contained in:
@@ -5,6 +5,9 @@ using UnityEngine.SceneManagement;
|
||||
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
const string SfxEnabledPrefsKey = "Audio.SfxEnabled";
|
||||
const string MusicEnabledPrefsKey = "Audio.MusicEnabled";
|
||||
|
||||
[Header("Sources")]
|
||||
public AudioSource musicSource;
|
||||
public AudioSource uiSfxSource;
|
||||
@@ -44,6 +47,7 @@ public class AudioManager : MonoBehaviour
|
||||
instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
_maxMusicVolume = musicSource != null ? musicSource.volume : 1f;
|
||||
LoadAudioPrefs();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
@@ -227,6 +231,82 @@ public class AudioManager : MonoBehaviour
|
||||
|
||||
#region SFX
|
||||
|
||||
void LoadAudioPrefs()
|
||||
{
|
||||
ToggleSFX(PlayerPrefs.GetInt(SfxEnabledPrefsKey, 1) == 1, savePreference: false);
|
||||
ToggleMusic(PlayerPrefs.GetInt(MusicEnabledPrefsKey, 1) == 1, savePreference: false);
|
||||
}
|
||||
|
||||
public void ToggleSFX(bool isOn)
|
||||
{
|
||||
ToggleSFX(isOn, savePreference: true);
|
||||
}
|
||||
|
||||
public void ToggleMusic(bool isOn)
|
||||
{
|
||||
ToggleMusic(isOn, savePreference: true);
|
||||
}
|
||||
|
||||
public bool IsSFXOn()
|
||||
{
|
||||
if (uiSfxSource != null)
|
||||
return !uiSfxSource.mute;
|
||||
if (gameSfxSource != null)
|
||||
return !gameSfxSource.mute;
|
||||
if (crowdSfxSourceA != null)
|
||||
return !crowdSfxSourceA.mute;
|
||||
if (crowdSfxSourceB != null)
|
||||
return !crowdSfxSourceB.mute;
|
||||
return PlayerPrefs.GetInt(SfxEnabledPrefsKey, 1) == 1;
|
||||
}
|
||||
|
||||
public bool IsMusicOn()
|
||||
{
|
||||
if (musicSource != null)
|
||||
return !musicSource.mute;
|
||||
return PlayerPrefs.GetInt(MusicEnabledPrefsKey, 1) == 1;
|
||||
}
|
||||
|
||||
public void SetSfxVolume(float volume)
|
||||
{
|
||||
ToggleSFX(volume > 0f);
|
||||
}
|
||||
|
||||
public void SetMusicVolume(float volume)
|
||||
{
|
||||
ToggleMusic(volume > 0f);
|
||||
}
|
||||
|
||||
void ToggleSFX(bool isOn, bool savePreference)
|
||||
{
|
||||
if (uiSfxSource != null)
|
||||
uiSfxSource.mute = !isOn;
|
||||
if (gameSfxSource != null)
|
||||
gameSfxSource.mute = !isOn;
|
||||
if (crowdSfxSourceA != null)
|
||||
crowdSfxSourceA.mute = !isOn;
|
||||
if (crowdSfxSourceB != null)
|
||||
crowdSfxSourceB.mute = !isOn;
|
||||
|
||||
if (!savePreference)
|
||||
return;
|
||||
|
||||
PlayerPrefs.SetInt(SfxEnabledPrefsKey, isOn ? 1 : 0);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
void ToggleMusic(bool isOn, bool savePreference)
|
||||
{
|
||||
if (musicSource != null)
|
||||
musicSource.mute = !isOn;
|
||||
|
||||
if (!savePreference)
|
||||
return;
|
||||
|
||||
PlayerPrefs.SetInt(MusicEnabledPrefsKey, isOn ? 1 : 0);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
public void PlayWallHit(float vol=1){
|
||||
gameSfxSource.PlayOneShot(audioDirectory.wallHits[Random.Range(0, audioDirectory.wallHits.Length)], vol);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
[RequireComponent(typeof(TMP_Text))]
|
||||
public class TextBlinker : MonoBehaviour
|
||||
{
|
||||
public float duration = 0.5f;
|
||||
public Ease ease = Ease.InOutSine;
|
||||
public float from = 0f;
|
||||
public float to = 1f;
|
||||
public int loops = -1;
|
||||
public LoopType loopType = LoopType.Yoyo;
|
||||
|
||||
void Start()
|
||||
{
|
||||
var txt = GetComponent<TMP_Text>();
|
||||
var c = txt.color;
|
||||
c.a = from;
|
||||
txt.color = c;
|
||||
txt.DOFade(to, duration).SetEase(ease).SetLoops(loops, loopType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 430ada29524e05f41b887541b79adc2c
|
||||
@@ -0,0 +1,30 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
[RequireComponent(typeof(TMP_Text))]
|
||||
public class TextColorFlash : MonoBehaviour
|
||||
{
|
||||
public Color colorA = Color.white;
|
||||
public Color colorB = Color.red;
|
||||
public float duration = 1f;
|
||||
|
||||
float a =0;
|
||||
public float t;
|
||||
TMP_Text txt;
|
||||
|
||||
void Start()
|
||||
{
|
||||
txt = GetComponent<TMP_Text>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(duration <= 0){return;}
|
||||
float sinA = Mathf.Sin(a);
|
||||
t = sinA * 0.5f + 0.5f;
|
||||
Color color = Color.Lerp(colorA, colorB, t);
|
||||
txt.color = color;
|
||||
a += Time.deltaTime * duration;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d2075bb87ea2e44ebc4a00fcdac4ff2
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class ToggleButton : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public ToggleSpriteData[] toggleSpriteData;
|
||||
|
||||
public bool isOn = false;
|
||||
|
||||
Button btn;
|
||||
|
||||
public UnityEvent<bool> onToggleValueChanged = new UnityEvent<bool>();
|
||||
void Start()
|
||||
{
|
||||
btn = GetComponent<Button>();
|
||||
btn.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
void OnClick()
|
||||
{
|
||||
SetIsOn(!isOn);
|
||||
}
|
||||
|
||||
public void SetIsOn(bool isOn)
|
||||
{
|
||||
this.isOn = isOn;
|
||||
foreach (var spriteData in toggleSpriteData)
|
||||
{
|
||||
spriteData.target.sprite = isOn ? spriteData.onSprite : spriteData.offSprite;
|
||||
}
|
||||
onToggleValueChanged.Invoke(isOn);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ToggleSpriteData{
|
||||
public Image target;
|
||||
public Sprite onSprite;
|
||||
public Sprite offSprite;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32dd41e420d0032409b03beba9058456
|
||||
Reference in New Issue
Block a user