game over UI done, rematch left
This commit is contained in:
@@ -307,6 +307,9 @@ public class GameManager : NetworkBehaviour
|
||||
void OnSelectedPuckChanged(Puck oldPuck, Puck newPuck){
|
||||
// Logger.Log($"Selected puck changed from {oldPuck} to {newPuck}");
|
||||
GameEvents.OnSelectedPuckChanged?.Invoke(newPuck);
|
||||
if (newPuck == null && isClient && CameraEffects.instance != null){
|
||||
CameraEffects.instance.ReleaseStretchFactor();
|
||||
}
|
||||
}
|
||||
public static Puck SelectedPuck{
|
||||
get{
|
||||
@@ -393,6 +396,11 @@ public class GameManager : NetworkBehaviour
|
||||
}
|
||||
|
||||
turnTimerCounter = 0;
|
||||
// Clear any active drag/selection before changing turns.
|
||||
// This prevents stale selected-puck visuals when the timer expires mid-hold.
|
||||
if (selectedPuck != null){
|
||||
SetSelectedPuck(null);
|
||||
}
|
||||
|
||||
SelectedTeam = SelectedTeam == Team.Red ? Team.Blue : Team.Red;
|
||||
OnTeamChanged?.Invoke(SelectedTeam);
|
||||
@@ -683,7 +691,8 @@ public class GameManager : NetworkBehaviour
|
||||
StopClient();
|
||||
|
||||
LevelLoadManager.instance.SetupGameOver(team,redScore,blueScore);
|
||||
LevelLoadManager.LoadLevel("MainMenu");
|
||||
GameOverCanvas.instance.Show(team, MyTeam, redScore, blueScore);
|
||||
// LevelLoadManager.LoadLevel("MainMenu");
|
||||
}
|
||||
|
||||
public void Leave(){
|
||||
|
||||
@@ -0,0 +1,263 @@
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
public class GameOverCanvas : MonoBehaviour
|
||||
{
|
||||
public bool showOnLoad = false;
|
||||
CanvasGroup canvasGroup;
|
||||
[Header("Intro items")]
|
||||
public RectTransform[] middleScalingItems;
|
||||
public RectTransform[] comingFromMiddle;
|
||||
public RectTransform[] prizeFrames;
|
||||
public RectTransform[] comingDown;
|
||||
|
||||
Dictionary<RectTransform, Vector3> OriginalPositions;
|
||||
Dictionary<RectTransform, Vector3> OriginalScales;
|
||||
|
||||
[Header("Values")]
|
||||
public TMP_Text p1_name;
|
||||
public TMP_Text p1_l10;
|
||||
public TMP_Text p2_name;
|
||||
public TMP_Text p2_l10;
|
||||
|
||||
public GameObject p1_red,p2_red,p1_blue,p2_blue;
|
||||
public Image p1_icon, p2_icon;
|
||||
public Sprite redIcon, blueIcon;
|
||||
|
||||
public RectTransform p1_winner, p2_winner;
|
||||
[Header("Rematch")]
|
||||
public Button btnRematch;
|
||||
public Button btnLeave;
|
||||
public GameObject rematchWarningLoser;
|
||||
public TMP_Text txtRewardRC;
|
||||
public TMP_Text txtRewardCC;
|
||||
public TMP_Text countdownTxt;
|
||||
string returningToMenuText;
|
||||
|
||||
public float returnToMenuCountdown = 15f;
|
||||
|
||||
public static GameOverCanvas instance;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
instance = this;
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
Hide();
|
||||
|
||||
CollectOriginalPositionsAndScales();
|
||||
|
||||
returningToMenuText = countdownTxt.text;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(showOnLoad){
|
||||
if(LevelLoadManager.instance == null){ //Load dummy data for testing
|
||||
LevelLoadManager.myPlayer = new MatchmadePlayer(){Name = "test p1", l10_wins = 3, l10_losses = 1};
|
||||
LevelLoadManager.opponentPlayer = new MatchmadePlayer(){Name = "test p2", l10_wins = 1, l10_losses = 3};
|
||||
}
|
||||
Show(Team.Red, Team.Red, 3, 1);
|
||||
}
|
||||
|
||||
btnRematch.onClick.AddListener(OnBtnRematchClicked);
|
||||
btnLeave.onClick.AddListener(OnBtnLeaveGameClicked);
|
||||
}
|
||||
|
||||
void OnBtnRematchClicked(){
|
||||
// LevelLoadManager.LoadLevel("Game");
|
||||
}
|
||||
void OnBtnLeaveGameClicked(){
|
||||
LevelLoadManager.LoadLevel("MainMenu");
|
||||
}
|
||||
|
||||
void CollectOriginalPositionsAndScales(){
|
||||
OriginalPositions = new Dictionary<RectTransform, Vector3>();
|
||||
OriginalScales = new Dictionary<RectTransform, Vector3>();
|
||||
foreach (var item in comingFromMiddle)
|
||||
{
|
||||
OriginalPositions.Add(item, item.position);
|
||||
OriginalScales.Add(item, item.localScale);
|
||||
}
|
||||
foreach (var item in middleScalingItems)
|
||||
{
|
||||
if(!OriginalPositions.ContainsKey(item)){
|
||||
OriginalPositions.Add(item, item.position);
|
||||
}
|
||||
if(!OriginalScales.ContainsKey(item)){
|
||||
OriginalScales.Add(item, item.localScale);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in comingDown)
|
||||
{
|
||||
if(!OriginalPositions.ContainsKey(item)){
|
||||
OriginalPositions.Add(item, item.position);
|
||||
}
|
||||
if(!OriginalScales.ContainsKey(item)){
|
||||
OriginalScales.Add(item, item.localScale);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in prizeFrames)
|
||||
{
|
||||
if(!OriginalPositions.ContainsKey(item)){
|
||||
OriginalPositions.Add(item, item.position);
|
||||
}
|
||||
if(!OriginalScales.ContainsKey(item)){
|
||||
OriginalScales.Add(item, item.localScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
void Hide(){
|
||||
canvasGroup.alpha = 0;
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
canvasGroup.interactable = false;
|
||||
}
|
||||
|
||||
|
||||
public void Setup(Team winningTeam, Team myTeam, int redScore, int blueScore){
|
||||
p1_winner.gameObject.SetActive(false);
|
||||
p2_winner.gameObject.SetActive(false);
|
||||
if(myTeam == Team.Red){
|
||||
p1_red.SetActive(true);
|
||||
p1_blue.SetActive(false);
|
||||
p2_red.SetActive(false);
|
||||
p2_blue.SetActive(true);
|
||||
|
||||
p1_icon.sprite = redIcon;
|
||||
p2_icon.sprite = blueIcon;
|
||||
}else{
|
||||
p1_red.SetActive(false);
|
||||
p1_blue.SetActive(true);
|
||||
p2_red.SetActive(true);
|
||||
p2_blue.SetActive(false);
|
||||
|
||||
p1_icon.sprite = blueIcon;
|
||||
p2_icon.sprite = redIcon;
|
||||
}
|
||||
|
||||
p1_name.text = LevelLoadManager.myPlayer.Name;
|
||||
p2_name.text = LevelLoadManager.opponentPlayer.Name;
|
||||
p1_l10.text = $"L10 {LevelLoadManager.myPlayer.l10_wins}-{LevelLoadManager.myPlayer.l10_losses}";
|
||||
p2_l10.text = $"L10 {LevelLoadManager.opponentPlayer.l10_wins}-{LevelLoadManager.opponentPlayer.l10_losses}";
|
||||
|
||||
if(myTeam == winningTeam){
|
||||
p1_winner.gameObject.SetActive(true);
|
||||
p2_winner.gameObject.SetActive(false);
|
||||
}else{
|
||||
p1_winner.gameObject.SetActive(false);
|
||||
p2_winner.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
float rcPrize = 0;
|
||||
public void Show(Team winningTeam, Team myTeam, int redScore, int blueScore){
|
||||
Setup(winningTeam, myTeam, redScore, blueScore);
|
||||
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
canvasGroup.interactable = true;
|
||||
|
||||
foreach (var item in middleScalingItems)
|
||||
{
|
||||
item.localScale = new Vector3(0, item.localScale.y, item.localScale.z);
|
||||
}
|
||||
foreach (var item in comingFromMiddle)
|
||||
{
|
||||
item.position = new Vector3(Screen.width/2f,OriginalPositions[item].y);
|
||||
item.localScale = new Vector3(0, OriginalScales[item].y, OriginalScales[item].z);
|
||||
}
|
||||
foreach (var item in comingDown)
|
||||
{
|
||||
item.position = new Vector3(OriginalPositions[item].x, 0.3f);
|
||||
item.localScale = new Vector3(OriginalScales[item].x, 0, OriginalScales[item].z);
|
||||
}
|
||||
|
||||
foreach (var item in prizeFrames)
|
||||
{
|
||||
item.localScale = new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
if(winningTeam == myTeam){
|
||||
rcPrize = 8.2f;
|
||||
}
|
||||
|
||||
btnRematch.interactable = winningTeam == myTeam;
|
||||
rematchWarningLoser.SetActive(winningTeam != myTeam);
|
||||
|
||||
StartCoroutine(CoroutineShow());
|
||||
}
|
||||
|
||||
IEnumerator CoroutineShow(){
|
||||
float fadeInTime = 0.5f;
|
||||
float scaleTime = 0.2f;
|
||||
float moveTime = 0.3f;
|
||||
canvasGroup.DOFade(1, fadeInTime).SetEase(Ease.InOutBack);
|
||||
yield return new WaitForSeconds(fadeInTime);
|
||||
|
||||
foreach (var item in middleScalingItems)
|
||||
{
|
||||
item.DOScale(OriginalScales[item], scaleTime).SetEase(Ease.InOutBack);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(scaleTime * 0.5f);
|
||||
foreach (var item in comingFromMiddle)
|
||||
{
|
||||
item.DOMove(OriginalPositions[item], moveTime).SetEase(Ease.InOutBack);
|
||||
item.DOScale(OriginalScales[item], scaleTime).SetEase(Ease.InOutBack);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(scaleTime * 0.5f);
|
||||
|
||||
foreach (var item in prizeFrames)
|
||||
{
|
||||
item.DOScale(Vector3.one, scaleTime).SetEase(Ease.InOutBack);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(scaleTime * 0.5f);
|
||||
|
||||
//Rewards
|
||||
StartCoroutine(CoroutineSetTextNumber(rcPrize, txtRewardRC, 10, "N1", "+", " RC"));
|
||||
StartCoroutine(CoroutineSetTextNumber(100, txtRewardCC, 100, "N0", "+", " CC"));
|
||||
|
||||
yield return new WaitForSeconds(1f);
|
||||
|
||||
foreach (var item in comingDown)
|
||||
{
|
||||
item.DOMove(OriginalPositions[item], 0.3f).SetEase(Ease.InOutBack);
|
||||
item.DOScale(OriginalScales[item], 0.3f).SetEase(Ease.InOutBack);
|
||||
}
|
||||
|
||||
|
||||
|
||||
StartCoroutine(CoroutineCountdown());
|
||||
}
|
||||
|
||||
|
||||
IEnumerator CoroutineSetTextNumber(float number, TMP_Text text, float speed = 100f, string formatting = "N0", string prefix = "", string suffix = ""){
|
||||
float t=0;
|
||||
while(t < number){
|
||||
t+=Time.deltaTime*speed;
|
||||
text.text = prefix + t.ToString(formatting) + suffix;
|
||||
yield return null;
|
||||
}
|
||||
text.text = prefix + number.ToString(formatting) + suffix;
|
||||
}
|
||||
|
||||
|
||||
IEnumerator CoroutineCountdown(){
|
||||
TextColorFlash textColorFlash = countdownTxt.GetComponent<TextColorFlash>();
|
||||
while(returnToMenuCountdown > 0){
|
||||
returnToMenuCountdown--;
|
||||
countdownTxt.text = returningToMenuText.Replace("{t}", returnToMenuCountdown.ToString("N0"));
|
||||
if(returnToMenuCountdown < 5){
|
||||
textColorFlash.duration = 5;
|
||||
}
|
||||
yield return new WaitForSecondsRealtime(1f);
|
||||
}
|
||||
|
||||
LevelLoadManager.LoadLevel("MainMenu");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34fb5f6c8224c94438e92e0f8f5c8471
|
||||
@@ -38,6 +38,10 @@ public class MainMenuManager : MonoBehaviour
|
||||
public TMP_Text txtWithdrawStatus;
|
||||
private bool isCoinBuyInProgress;
|
||||
|
||||
[Header("Audio")]
|
||||
public ToggleButton toggleSfx;
|
||||
public ToggleButton toggleMusic;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if(LoginManager.instance==null){
|
||||
@@ -82,6 +86,28 @@ public class MainMenuManager : MonoBehaviour
|
||||
btnPaste.onClick.AddListener(OnPasteFromClipboard);
|
||||
|
||||
btnPlay.onClick.AddListener(OnPlay);
|
||||
|
||||
toggleSfx.onToggleValueChanged.AddListener(OnToggleSfx);
|
||||
toggleMusic.onToggleValueChanged.AddListener(OnToggleMusic);
|
||||
|
||||
toggleSfx.SetIsOn(AudioManager.instance.IsSFXOn());
|
||||
toggleMusic.SetIsOn(AudioManager.instance.IsMusicOn());
|
||||
}
|
||||
|
||||
void OnDestroy(){
|
||||
LoginManager.OnUserDataUpdated -= OnUserUpdated;
|
||||
toggleSfx.onToggleValueChanged.RemoveListener(OnToggleSfx);
|
||||
toggleMusic.onToggleValueChanged.RemoveListener(OnToggleMusic);
|
||||
}
|
||||
|
||||
void OnToggleSfx(bool isOn)
|
||||
{
|
||||
AudioManager.instance.SetSfxVolume(isOn ? 1f : 0f);
|
||||
}
|
||||
|
||||
void OnToggleMusic(bool isOn)
|
||||
{
|
||||
AudioManager.instance.SetMusicVolume(isOn ? 1f : 0f);
|
||||
}
|
||||
|
||||
void OnPlay()
|
||||
@@ -174,10 +200,7 @@ public class MainMenuManager : MonoBehaviour
|
||||
btnBuyUsd50.interactable = interactable;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
LoginManager.OnUserDataUpdated -= OnUserUpdated;
|
||||
}
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
|
||||
@@ -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