Fix result scene + bug fix

This commit is contained in:
r.nikolin 2023-10-11 17:33:14 +03:00
parent 549d44e0c5
commit b561c6cea6
7 changed files with 1302 additions and 22052 deletions

View File

@ -2,6 +2,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.UI;
public class ResultSceneManager : MonoBehaviour public class ResultSceneManager : MonoBehaviour
{ {
@ -9,9 +10,14 @@ public class ResultSceneManager : MonoBehaviour
public UnityEvent<int> OnDailyTop; public UnityEvent<int> OnDailyTop;
public UnityEvent<int> OnGlobalTop; public UnityEvent<int> OnGlobalTop;
public UnityEvent OnNoTop;
public UnityEvent OnNoAllTop;
public UnityEvent OnNoDailyTop;
public UnityEvent OnNoGlobalTop;
private void Start() public InputField PlayerNameInputField;
private void Awake()
{ {
leaderboardController = FindObjectOfType<LeaderboardController>(); leaderboardController = FindObjectOfType<LeaderboardController>();
@ -21,7 +27,7 @@ public class ResultSceneManager : MonoBehaviour
if (!leaderboardController.CheckCurrentPlayerDailyTop() && !leaderboardController.CheckCurrentPlayerGlobalTop()) if (!leaderboardController.CheckCurrentPlayerDailyTop() && !leaderboardController.CheckCurrentPlayerGlobalTop())
{ {
OnNoTop?.Invoke(); OnNoAllTop?.Invoke();
} }
} }
@ -32,6 +38,8 @@ public class ResultSceneManager : MonoBehaviour
OnDailyTop?.Invoke(leaderboardController.GetCurrentPlayerDailyPos()); OnDailyTop?.Invoke(leaderboardController.GetCurrentPlayerDailyPos());
Debug.Log("Âû ïîïàëè â Òîï 30 èãðîêîâ äíÿ!"); Debug.Log("Âû ïîïàëè â Òîï 30 èãðîêîâ äíÿ!");
} }
else
OnNoDailyTop?.Invoke();
} }
public void CheckGlobalTop() public void CheckGlobalTop()
@ -41,5 +49,13 @@ public class ResultSceneManager : MonoBehaviour
OnGlobalTop?.Invoke(leaderboardController.GetCurrentPlayerGlobalPos()); OnGlobalTop?.Invoke(leaderboardController.GetCurrentPlayerGlobalPos());
Debug.Log("Âû ïîïàëè â Òîï 30 èãðîêîâ çà âñ¸ âðåìÿ!"); Debug.Log("Âû ïîïàëè â Òîï 30 èãðîêîâ çà âñ¸ âðåìÿ!");
} }
else
OnNoGlobalTop?.Invoke();
}
public void SavePlayerName()
{
PlayerSetup.Instance.CurrentPlayer.Name = PlayerNameInputField.text;
leaderboardController.SaveData();
} }
} }

File diff suppressed because one or more lines are too long

View File

@ -163,8 +163,8 @@ public class LeaderboardController : MonoBehaviour
return _globalPlayerInfo.Players.Contains(PlayerSetup.Instance.CurrentPlayer); return _globalPlayerInfo.Players.Contains(PlayerSetup.Instance.CurrentPlayer);
} }
public int GetCurrentPlayerDailyPos() => _dailyPlayerInfo.Players.IndexOf(PlayerSetup.Instance.CurrentPlayer); public int GetCurrentPlayerDailyPos() => _dailyPlayerInfo.Players.IndexOf(PlayerSetup.Instance.CurrentPlayer) + 1;
public int GetCurrentPlayerGlobalPos() => _globalPlayerInfo.Players.IndexOf(PlayerSetup.Instance.CurrentPlayer); public int GetCurrentPlayerGlobalPos() => _globalPlayerInfo.Players.IndexOf(PlayerSetup.Instance.CurrentPlayer) + 1;
public void SaveData() public void SaveData()
{ {

View File

@ -13,23 +13,32 @@ public class LeanTimer : MonoBehaviour
public UnityEvent<float> OnUpdate = new UnityEvent<float>(); public UnityEvent<float> OnUpdate = new UnityEvent<float>();
public UnityEvent OnTotalComplete;
private LTDescr LTDescr; private LTDescr LTDescr;
private void Start() private void Start()
{ {
if (StartOnAwake) if (StartOnAwake)
{ {
StartTimer(StartValue, EndValue, Time); ManualStart();
} }
} }
public void ManualStart()
{
StartTimer(StartValue, EndValue, Time);
}
public void StartTimer(float startValue, float endValue, float time, System.Action OnComplete = null) public void StartTimer(float startValue, float endValue, float time, System.Action OnComplete = null)
{ {
LTDescr = LeanTween.value(1, 0, time).setOnUpdate((float x) => LTDescr = LeanTween.value(1, 0, time).setOnUpdate((float x) =>
{ {
OnUpdate?.Invoke(x); OnUpdate?.Invoke(x);
}).setOnComplete(OnComplete); }).setOnComplete(() =>
{
OnComplete?.Invoke();
OnTotalComplete?.Invoke();
});
} }
public void StopTimer(float value = 0) public void StopTimer(float value = 0)

View File

@ -30,6 +30,7 @@ public class SaveLoadController : MonoBehaviour
string fullDirPath = Application.persistentDataPath + DIR_PATH; string fullDirPath = Application.persistentDataPath + DIR_PATH;
string fullFilePath = Application.persistentDataPath + DIR_PATH + $"{filename}.txt"; string fullFilePath = Application.persistentDataPath + DIR_PATH + $"{filename}.txt";
Debug.Log($"SAVE:{fullFilePath}");
if (!Directory.Exists(fullDirPath)) if (!Directory.Exists(fullDirPath))
{ {
Directory.CreateDirectory(fullDirPath); Directory.CreateDirectory(fullDirPath);
@ -40,7 +41,7 @@ public class SaveLoadController : MonoBehaviour
var json = JsonUtility.ToJson(so); var json = JsonUtility.ToJson(so);
bf.Serialize(fs, json); bf.Serialize(fs, json);
fs.Close(); fs.Close();
Debug.Log($"SAVE:SUCCESS");
return true; return true;
} }
@ -48,8 +49,8 @@ public class SaveLoadController : MonoBehaviour
{ {
string fullDirPath = Application.persistentDataPath + DIR_PATH; string fullDirPath = Application.persistentDataPath + DIR_PATH;
string fullFilePath = Application.persistentDataPath + DIR_PATH + $"{filename}.txt"; string fullFilePath = Application.persistentDataPath + DIR_PATH + $"{filename}.txt";
Debug.Log(fullFilePath); Debug.Log($"LOAD:{fullFilePath}");
if (!Directory.Exists(fullDirPath)) if (!Directory.Exists(fullDirPath))
{ {
@ -71,6 +72,7 @@ public class SaveLoadController : MonoBehaviour
so = ScriptableObject.CreateInstance<T>(); so = ScriptableObject.CreateInstance<T>();
} }
Debug.Log($"LOAD:SUCCESS");
return true; return true;
} }
} }

View File

@ -44,7 +44,8 @@ public class UIDisplayMessage : MonoBehaviour
public void Hide() public void Hide()
{ {
IsShow = false; IsShow = false;
gameObject.SetActive(false); if (gameObject != null)
gameObject.SetActive(false);
} }
public void StopMessage() public void StopMessage()

View File

@ -15,6 +15,9 @@ public class UITextShow : MonoBehaviour
public UnityEvent OnTimeTick; public UnityEvent OnTimeTick;
public UnityEvent OnTimeEnd; public UnityEvent OnTimeEnd;
public string Prefix;
public string Postfix;
public string Text => _text.text; public string Text => _text.text;
private void Awake() private void Awake()
@ -24,7 +27,12 @@ public class UITextShow : MonoBehaviour
public void SetText(string text) public void SetText(string text)
{ {
_text.SetText(text); _text.SetText($"{Prefix}{text}{Postfix}");
}
public void SetText(int num)
{
SetText(num.ToString());
} }
public void ShowSubtitle(string text, float delay, float afterDelay, Action onStart, Action onEnd) public void ShowSubtitle(string text, float delay, float afterDelay, Action onStart, Action onEnd)
@ -51,12 +59,12 @@ public class UITextShow : MonoBehaviour
for (int i = time; i > 0; i--) for (int i = time; i > 0; i--)
{ {
_text.SetText(i.ToString()); SetText(i.ToString());
OnTimeTick?.Invoke(); OnTimeTick?.Invoke();
yield return new WaitForSeconds(1); yield return new WaitForSeconds(1);
} }
_text.SetText(afterTimerText); SetText(afterTimerText);
yield return new WaitForSeconds(afterDelay); yield return new WaitForSeconds(afterDelay);
//_text.SetText(string.Empty); //_text.SetText(string.Empty);
OnTimeEnd?.Invoke(); OnTimeEnd?.Invoke();
@ -71,13 +79,13 @@ public class UITextShow : MonoBehaviour
for (int i = 0; i < text.Length; i++) for (int i = 0; i < text.Length; i++)
{ {
sb.Append(text[i]); sb.Append(text[i]);
_text.SetText(sb); SetText(sb.ToString());
OnTimeTick?.Invoke(); OnTimeTick?.Invoke();
yield return new WaitForSeconds(delay); yield return new WaitForSeconds(delay);
} }
yield return new WaitForSeconds(afterDelay); yield return new WaitForSeconds(afterDelay);
_text.SetText(string.Empty); SetText(string.Empty);
OnTimeEnd?.Invoke(); OnTimeEnd?.Invoke();
onEnd?.Invoke(); onEnd?.Invoke();
} }