Fixed score bars; fixed line endings.

This commit is contained in:
Randall Dolifka 2017-11-29 22:39:12 -06:00
parent 6b91eb1069
commit f7a20035a1
2 changed files with 161 additions and 161 deletions

View file

@ -4017,7 +4017,7 @@ Prefab:
m_IsPrefabParent: 0 m_IsPrefabParent: 0
--- !u!114 &1184926818 stripped --- !u!114 &1184926818 stripped
MonoBehaviour: MonoBehaviour:
m_PrefabParentObject: {fileID: 114935328999071964, guid: 2e0806d99e91f374fb64a63401c2eb5d, m_PrefabParentObject: {fileID: 114359522130762914, guid: 2e0806d99e91f374fb64a63401c2eb5d,
type: 2} type: 2}
m_PrefabInternal: {fileID: 1184926817} m_PrefabInternal: {fileID: 1184926817}
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
@ -4029,7 +4029,7 @@ MonoBehaviour:
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
--- !u!114 &1184926820 stripped --- !u!114 &1184926820 stripped
MonoBehaviour: MonoBehaviour:
m_PrefabParentObject: {fileID: 114646529127711606, guid: 2e0806d99e91f374fb64a63401c2eb5d, m_PrefabParentObject: {fileID: 114745961723015550, guid: 2e0806d99e91f374fb64a63401c2eb5d,
type: 2} type: 2}
m_PrefabInternal: {fileID: 1184926817} m_PrefabInternal: {fileID: 1184926817}
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}

View file

@ -1,98 +1,98 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
public class ScorePanelController : Photon.PunBehaviour { public class ScorePanelController : Photon.PunBehaviour {
public Text timerText; public Text timerText;
public Image guardScore, spyScore; public Image guardScore, spyScore;
private float initalScoreWidth; private float initalScoreWidth;
private static ScorePanelController mSingleton; private static ScorePanelController mSingleton;
public static ScorePanelController Singleton { get { return mSingleton; } } public static ScorePanelController Singleton { get { return mSingleton; } }
/** /**
* Setup the ScorePanelController. * Setup the ScorePanelController.
*/ */
void Start() void Start()
{ {
// set the singleton // set the singleton
if (mSingleton) if (mSingleton)
{ {
Debug.LogError("Two ScorePanelControllers in the scene"); Debug.LogError("Two ScorePanelControllers in the scene");
} }
mSingleton = this; mSingleton = this;
// start the timer update coroutine // start the timer update coroutine
StartCoroutine(TimerUpdate()); StartCoroutine(TimerUpdate());
// initialize scorebar variables // initialize scorebar variables
initalScoreWidth = spyScore.rectTransform.sizeDelta.x; initalScoreWidth = spyScore.rectTransform.sizeDelta.x;
spyScore.rectTransform.sizeDelta = new Vector2(-1, spyScore.rectTransform.sizeDelta.y); spyScore.rectTransform.sizeDelta = new Vector2(-1, spyScore.rectTransform.sizeDelta.y);
guardScore.rectTransform.sizeDelta = new Vector2(-1, guardScore.rectTransform.sizeDelta.y); guardScore.rectTransform.sizeDelta = new Vector2(-1, guardScore.rectTransform.sizeDelta.y);
} }
/** /**
* Update the score panel to reflect a new guard score * Update the score panel to reflect a new guard score
*/ */
public void UpdateGuardScore(float progress) public void UpdateGuardScore(float progress)
{ {
StartCoroutine(IncreaseScoreBarAnimation(guardScore, progress)); StartCoroutine(IncreaseScoreBarAnimation(guardScore, progress));
} }
/** /**
* Update the score panel to reflect a new spy score * Update the score panel to reflect a new spy score
*/ */
public void UpdateSpyScore(float progress) public void UpdateSpyScore(float progress)
{ {
StartCoroutine(IncreaseScoreBarAnimation(spyScore, progress)); StartCoroutine(IncreaseScoreBarAnimation(spyScore, progress));
} }
#region Coroutines #region Coroutines
IEnumerator TimerUpdate() IEnumerator TimerUpdate()
{ {
while (true) while (true)
{ {
yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame();
int seconds = (int)Time.timeSinceLevelLoad; int seconds = (int)Time.timeSinceLevelLoad;
int minutes = seconds / 60; int minutes = seconds / 60;
seconds = seconds % 60; seconds = seconds % 60;
string timeString = ""; string timeString = "";
if (seconds < 10) if (seconds < 10)
timeString = minutes.ToString() + ":0" + seconds.ToString(); timeString = minutes.ToString() + ":0" + seconds.ToString();
else else
timeString = minutes.ToString() + ":" + seconds.ToString(); timeString = minutes.ToString() + ":" + seconds.ToString();
timerText.text = timeString; timerText.text = timeString;
} }
} }
IEnumerator IncreaseScoreBarAnimation(Image scoreBar, float progress) IEnumerator IncreaseScoreBarAnimation(Image scoreBar, float progress)
{ {
Color originalColor = scoreBar.color; Color originalColor = scoreBar.color;
var flashCoroutine = StartCoroutine(FlashScoreBar(scoreBar)); var flashCoroutine = StartCoroutine(FlashScoreBar(scoreBar));
float targetWidth = initalScoreWidth * progress; float targetWidth = initalScoreWidth * progress;
float overshotWidth = targetWidth * 1.2f; float overshotWidth = targetWidth * 1.2f;
while (true) while (true)
{ {
Vector2 sizeDelta = scoreBar.rectTransform.sizeDelta; Vector2 sizeDelta = scoreBar.rectTransform.sizeDelta;
float newWidth = Mathf.Lerp(sizeDelta.x, overshotWidth, Time.deltaTime * 0.8f); float newWidth = Mathf.Lerp(sizeDelta.x, overshotWidth, Time.deltaTime * 0.8f);
if (sizeDelta.x < targetWidth) if (sizeDelta.x < targetWidth)
{ {
scoreBar.rectTransform.sizeDelta = new Vector2(newWidth, sizeDelta.y); scoreBar.rectTransform.sizeDelta = new Vector2(newWidth, sizeDelta.y);
yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame();
} }
else else
{ {
scoreBar.rectTransform.sizeDelta = new Vector2(targetWidth, sizeDelta.y); scoreBar.rectTransform.sizeDelta = new Vector2(targetWidth, sizeDelta.y);
break; break;
} }
} }
StopCoroutine(flashCoroutine); StopCoroutine(flashCoroutine);
StartCoroutine(ResetScoreBarColor(scoreBar, originalColor)); StartCoroutine(ResetScoreBarColor(scoreBar, originalColor));
if (progress >= 1.0) if (progress >= 1.0)
{ {
if (scoreBar == guardScore) if (scoreBar == guardScore)
@ -103,69 +103,69 @@ public class ScorePanelController : Photon.PunBehaviour {
{ {
photonView.RPC("ShowWinScreen", PhotonTargets.All, false); photonView.RPC("ShowWinScreen", PhotonTargets.All, false);
} }
} }
yield return null; yield return null;
} }
IEnumerator FlashScoreBar(Image scoreBar) IEnumerator FlashScoreBar(Image scoreBar)
{ {
Color darkerColor = scoreBar.color; Color darkerColor = scoreBar.color;
darkerColor.r *= 0.5f; darkerColor.r *= 0.5f;
darkerColor.g *= 0.5f; darkerColor.g *= 0.5f;
darkerColor.b *= 0.5f; darkerColor.b *= 0.5f;
HSBColor darkColor = HSBColor.FromColor(darkerColor); HSBColor darkColor = HSBColor.FromColor(darkerColor);
HSBColor flashColor = HSBColor.FromColor(Color.yellow); HSBColor flashColor = HSBColor.FromColor(Color.yellow);
HSBColor currentColor = darkColor; HSBColor currentColor = darkColor;
bool pingPong = true; bool pingPong = true;
float time = 0.0f; float time = 0.0f;
while (true) while (true)
{ {
float elapsedTime = Time.deltaTime * 2.0f; float elapsedTime = Time.deltaTime * 2.0f;
if (pingPong) if (pingPong)
time += elapsedTime; time += elapsedTime;
else else
time -= elapsedTime; time -= elapsedTime;
time = Mathf.Clamp01(time); time = Mathf.Clamp01(time);
if (time == 0.0f) if (time == 0.0f)
pingPong = true; pingPong = true;
else if (time == 1.0f) else if (time == 1.0f)
pingPong = false; pingPong = false;
currentColor = HSBColor.Lerp(darkColor, flashColor, time); currentColor = HSBColor.Lerp(darkColor, flashColor, time);
scoreBar.color = currentColor.ToColor(); scoreBar.color = currentColor.ToColor();
yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame();
} }
} }
IEnumerator ResetScoreBarColor(Image scoreBar, Color originalColor) IEnumerator ResetScoreBarColor(Image scoreBar, Color originalColor)
{ {
float time = 0.0f; float time = 0.0f;
HSBColor startColor = HSBColor.FromColor(scoreBar.color); HSBColor startColor = HSBColor.FromColor(scoreBar.color);
HSBColor endColor = HSBColor.FromColor(originalColor); HSBColor endColor = HSBColor.FromColor(originalColor);
HSBColor currentColor = startColor; HSBColor currentColor = startColor;
while (true) while (true)
{ {
time += Time.deltaTime * 2.0f; time += Time.deltaTime * 2.0f;
time = Mathf.Clamp01(time); time = Mathf.Clamp01(time);
currentColor = HSBColor.Lerp(startColor, endColor, time); currentColor = HSBColor.Lerp(startColor, endColor, time);
scoreBar.color = currentColor.ToColor(); scoreBar.color = currentColor.ToColor();
if (time >= 0.90f) if (time >= 0.90f)
{ {
scoreBar.color = originalColor; scoreBar.color = originalColor;
break; break;
} }
yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame();
} }
yield return null; yield return null;
} }
#endregion #endregion
#region PunRPC #region PunRPC
[PunRPC] [PunRPC]
void ShowWinScreen(bool guardsOrSpies) void ShowWinScreen(bool guardsOrSpies)
{ {
WinAnimationController.ActiveController.PlayWinAnimation(guardsOrSpies); WinAnimationController.ActiveController.PlayWinAnimation(guardsOrSpies);
} }
#endregion #endregion
} }