From f7a20035a1ef9914323d4dd2321f699e1df45a64 Mon Sep 17 00:00:00 2001 From: Randall Dolifka Date: Wed, 29 Nov 2017 22:39:12 -0600 Subject: [PATCH] Fixed score bars; fixed line endings. --- .../Assets/Scenes/GameScene.unity | 4 +- .../Assets/Scripts/UI/ScorePanelController.cs | 318 +++++++++--------- 2 files changed, 161 insertions(+), 161 deletions(-) diff --git a/Project Undercover/Assets/Scenes/GameScene.unity b/Project Undercover/Assets/Scenes/GameScene.unity index a85e7d1..9c17ee9 100755 --- a/Project Undercover/Assets/Scenes/GameScene.unity +++ b/Project Undercover/Assets/Scenes/GameScene.unity @@ -4017,7 +4017,7 @@ Prefab: m_IsPrefabParent: 0 --- !u!114 &1184926818 stripped MonoBehaviour: - m_PrefabParentObject: {fileID: 114935328999071964, guid: 2e0806d99e91f374fb64a63401c2eb5d, + m_PrefabParentObject: {fileID: 114359522130762914, guid: 2e0806d99e91f374fb64a63401c2eb5d, type: 2} m_PrefabInternal: {fileID: 1184926817} m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} @@ -4029,7 +4029,7 @@ MonoBehaviour: m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} --- !u!114 &1184926820 stripped MonoBehaviour: - m_PrefabParentObject: {fileID: 114646529127711606, guid: 2e0806d99e91f374fb64a63401c2eb5d, + m_PrefabParentObject: {fileID: 114745961723015550, guid: 2e0806d99e91f374fb64a63401c2eb5d, type: 2} m_PrefabInternal: {fileID: 1184926817} m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} diff --git a/Project Undercover/Assets/Scripts/UI/ScorePanelController.cs b/Project Undercover/Assets/Scripts/UI/ScorePanelController.cs index b4fb38e..2099145 100644 --- a/Project Undercover/Assets/Scripts/UI/ScorePanelController.cs +++ b/Project Undercover/Assets/Scripts/UI/ScorePanelController.cs @@ -1,98 +1,98 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; - -public class ScorePanelController : Photon.PunBehaviour { - - public Text timerText; - public Image guardScore, spyScore; - - private float initalScoreWidth; - private static ScorePanelController mSingleton; - - public static ScorePanelController Singleton { get { return mSingleton; } } - - /** - * Setup the ScorePanelController. - */ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class ScorePanelController : Photon.PunBehaviour { + + public Text timerText; + public Image guardScore, spyScore; + + private float initalScoreWidth; + private static ScorePanelController mSingleton; + + public static ScorePanelController Singleton { get { return mSingleton; } } + + /** + * Setup the ScorePanelController. + */ void Start() - { - // set the singleton - if (mSingleton) - { + { + // set the singleton + if (mSingleton) + { Debug.LogError("Two ScorePanelControllers in the scene"); - } - mSingleton = this; - - // start the timer update coroutine - StartCoroutine(TimerUpdate()); - - // initialize scorebar variables - initalScoreWidth = spyScore.rectTransform.sizeDelta.x; - spyScore.rectTransform.sizeDelta = new Vector2(-1, spyScore.rectTransform.sizeDelta.y); - guardScore.rectTransform.sizeDelta = new Vector2(-1, guardScore.rectTransform.sizeDelta.y); - } - - /** - * Update the score panel to reflect a new guard score - */ - public void UpdateGuardScore(float progress) - { - StartCoroutine(IncreaseScoreBarAnimation(guardScore, progress)); - } - - /** - * Update the score panel to reflect a new spy score - */ - public void UpdateSpyScore(float progress) - { - StartCoroutine(IncreaseScoreBarAnimation(spyScore, progress)); - } - - #region Coroutines - IEnumerator TimerUpdate() - { - while (true) - { - yield return new WaitForEndOfFrame(); - int seconds = (int)Time.timeSinceLevelLoad; - int minutes = seconds / 60; - seconds = seconds % 60; - string timeString = ""; - if (seconds < 10) - timeString = minutes.ToString() + ":0" + seconds.ToString(); - else - timeString = minutes.ToString() + ":" + seconds.ToString(); - timerText.text = timeString; - } - } - - IEnumerator IncreaseScoreBarAnimation(Image scoreBar, float progress) - { - Color originalColor = scoreBar.color; - var flashCoroutine = StartCoroutine(FlashScoreBar(scoreBar)); - float targetWidth = initalScoreWidth * progress; - float overshotWidth = targetWidth * 1.2f; - while (true) - { - Vector2 sizeDelta = scoreBar.rectTransform.sizeDelta; - float newWidth = Mathf.Lerp(sizeDelta.x, overshotWidth, Time.deltaTime * 0.8f); - if (sizeDelta.x < targetWidth) - { - scoreBar.rectTransform.sizeDelta = new Vector2(newWidth, sizeDelta.y); - yield return new WaitForEndOfFrame(); - } - else - { - scoreBar.rectTransform.sizeDelta = new Vector2(targetWidth, sizeDelta.y); - break; - } - } - StopCoroutine(flashCoroutine); - StartCoroutine(ResetScoreBarColor(scoreBar, originalColor)); - + } + mSingleton = this; + + // start the timer update coroutine + StartCoroutine(TimerUpdate()); + + // initialize scorebar variables + initalScoreWidth = spyScore.rectTransform.sizeDelta.x; + spyScore.rectTransform.sizeDelta = new Vector2(-1, spyScore.rectTransform.sizeDelta.y); + guardScore.rectTransform.sizeDelta = new Vector2(-1, guardScore.rectTransform.sizeDelta.y); + } + + /** + * Update the score panel to reflect a new guard score + */ + public void UpdateGuardScore(float progress) + { + StartCoroutine(IncreaseScoreBarAnimation(guardScore, progress)); + } + + /** + * Update the score panel to reflect a new spy score + */ + public void UpdateSpyScore(float progress) + { + StartCoroutine(IncreaseScoreBarAnimation(spyScore, progress)); + } + + #region Coroutines + IEnumerator TimerUpdate() + { + while (true) + { + yield return new WaitForEndOfFrame(); + int seconds = (int)Time.timeSinceLevelLoad; + int minutes = seconds / 60; + seconds = seconds % 60; + string timeString = ""; + if (seconds < 10) + timeString = minutes.ToString() + ":0" + seconds.ToString(); + else + timeString = minutes.ToString() + ":" + seconds.ToString(); + timerText.text = timeString; + } + } + + IEnumerator IncreaseScoreBarAnimation(Image scoreBar, float progress) + { + Color originalColor = scoreBar.color; + var flashCoroutine = StartCoroutine(FlashScoreBar(scoreBar)); + float targetWidth = initalScoreWidth * progress; + float overshotWidth = targetWidth * 1.2f; + while (true) + { + Vector2 sizeDelta = scoreBar.rectTransform.sizeDelta; + float newWidth = Mathf.Lerp(sizeDelta.x, overshotWidth, Time.deltaTime * 0.8f); + if (sizeDelta.x < targetWidth) + { + scoreBar.rectTransform.sizeDelta = new Vector2(newWidth, sizeDelta.y); + yield return new WaitForEndOfFrame(); + } + else + { + scoreBar.rectTransform.sizeDelta = new Vector2(targetWidth, sizeDelta.y); + break; + } + } + StopCoroutine(flashCoroutine); + StartCoroutine(ResetScoreBarColor(scoreBar, originalColor)); + if (progress >= 1.0) { if (scoreBar == guardScore) @@ -103,69 +103,69 @@ public class ScorePanelController : Photon.PunBehaviour { { photonView.RPC("ShowWinScreen", PhotonTargets.All, false); } - } - - yield return null; - } - - IEnumerator FlashScoreBar(Image scoreBar) - { - Color darkerColor = scoreBar.color; - darkerColor.r *= 0.5f; - darkerColor.g *= 0.5f; - darkerColor.b *= 0.5f; - HSBColor darkColor = HSBColor.FromColor(darkerColor); - HSBColor flashColor = HSBColor.FromColor(Color.yellow); - HSBColor currentColor = darkColor; - bool pingPong = true; - float time = 0.0f; - while (true) - { - float elapsedTime = Time.deltaTime * 2.0f; - if (pingPong) - time += elapsedTime; - else - time -= elapsedTime; - time = Mathf.Clamp01(time); - if (time == 0.0f) - pingPong = true; - else if (time == 1.0f) - pingPong = false; - - currentColor = HSBColor.Lerp(darkColor, flashColor, time); - scoreBar.color = currentColor.ToColor(); - yield return new WaitForEndOfFrame(); - } - } - - IEnumerator ResetScoreBarColor(Image scoreBar, Color originalColor) - { - float time = 0.0f; - HSBColor startColor = HSBColor.FromColor(scoreBar.color); - HSBColor endColor = HSBColor.FromColor(originalColor); - HSBColor currentColor = startColor; - while (true) - { - time += Time.deltaTime * 2.0f; - time = Mathf.Clamp01(time); - currentColor = HSBColor.Lerp(startColor, endColor, time); - scoreBar.color = currentColor.ToColor(); - if (time >= 0.90f) - { - scoreBar.color = originalColor; - break; - } - yield return new WaitForEndOfFrame(); - } - yield return null; - } - #endregion - - #region PunRPC - [PunRPC] - void ShowWinScreen(bool guardsOrSpies) - { - WinAnimationController.ActiveController.PlayWinAnimation(guardsOrSpies); - } - #endregion -} + } + + yield return null; + } + + IEnumerator FlashScoreBar(Image scoreBar) + { + Color darkerColor = scoreBar.color; + darkerColor.r *= 0.5f; + darkerColor.g *= 0.5f; + darkerColor.b *= 0.5f; + HSBColor darkColor = HSBColor.FromColor(darkerColor); + HSBColor flashColor = HSBColor.FromColor(Color.yellow); + HSBColor currentColor = darkColor; + bool pingPong = true; + float time = 0.0f; + while (true) + { + float elapsedTime = Time.deltaTime * 2.0f; + if (pingPong) + time += elapsedTime; + else + time -= elapsedTime; + time = Mathf.Clamp01(time); + if (time == 0.0f) + pingPong = true; + else if (time == 1.0f) + pingPong = false; + + currentColor = HSBColor.Lerp(darkColor, flashColor, time); + scoreBar.color = currentColor.ToColor(); + yield return new WaitForEndOfFrame(); + } + } + + IEnumerator ResetScoreBarColor(Image scoreBar, Color originalColor) + { + float time = 0.0f; + HSBColor startColor = HSBColor.FromColor(scoreBar.color); + HSBColor endColor = HSBColor.FromColor(originalColor); + HSBColor currentColor = startColor; + while (true) + { + time += Time.deltaTime * 2.0f; + time = Mathf.Clamp01(time); + currentColor = HSBColor.Lerp(startColor, endColor, time); + scoreBar.color = currentColor.ToColor(); + if (time >= 0.90f) + { + scoreBar.color = originalColor; + break; + } + yield return new WaitForEndOfFrame(); + } + yield return null; + } + #endregion + + #region PunRPC + [PunRPC] + void ShowWinScreen(bool guardsOrSpies) + { + WinAnimationController.ActiveController.PlayWinAnimation(guardsOrSpies); + } + #endregion +}