chunk 1: core gameplay scripts scenes runtime assets
This commit is contained in:
353
Assets/Scripts/GameInit/GameInitialize.cs
Normal file
353
Assets/Scripts/GameInit/GameInitialize.cs
Normal file
@@ -0,0 +1,353 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
***** LOAD ALL PLAYERPREFS FOR DIFFERENT ASPECTS OF THE GAME
|
||||
5 PlayerPrefs:
|
||||
1. Announcements
|
||||
2. Animate Completed Missions
|
||||
3. Mission
|
||||
4. Rewards
|
||||
5. Settings
|
||||
*/
|
||||
|
||||
|
||||
//PLAYERPREFS for Animate Completed Missions, Missions, Rewards, and Settings
|
||||
#region
|
||||
//PlayerPrefs to handle Animation of Completed Missions
|
||||
[System.Serializable]
|
||||
public class Completed_Missions_toAnimate{
|
||||
public int current_week; //records the week the player is at
|
||||
public List<int> completed_missions_toAnimate_data; //records ID's of completed missions
|
||||
public int animation_status;
|
||||
}
|
||||
|
||||
|
||||
//MISSIONS PlayerPrefs
|
||||
#region
|
||||
//Progress of missions
|
||||
[System.Serializable]
|
||||
public class MissionProgress{
|
||||
public string start_date; //The first date when the game was first opened by user
|
||||
public int current_week; //records the week the player is at
|
||||
public int current_month; //records the week the player is at
|
||||
public List<int> completed_missions; //records ID's of completed missions
|
||||
public List<string> completed_missions_inprogress; //For missions that span for more than 1 match, e.g Win 2 matches in a row
|
||||
}
|
||||
|
||||
//Information about Individual missions, Weekly missions
|
||||
[System.Serializable]
|
||||
public class MissionInfo{
|
||||
public int missionID;
|
||||
public string missionTitle;
|
||||
public string missionDescription;
|
||||
public int missionXP;
|
||||
public int missionProgressCount; //Keeps track of missions that requires count, such as Ads
|
||||
public int month;
|
||||
public int week;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
//REWARDS PlayerPrefs
|
||||
#region
|
||||
//Player Details for the Game
|
||||
[System.Serializable]
|
||||
public class PlayerData{
|
||||
public int xp; //Player's XP
|
||||
public string rank; //Player's rank
|
||||
public string prevRank; //Records Player's rank to compare if it changes/Player ranks up
|
||||
public int overall_matches; //Match played
|
||||
public int win_streak; //Number of win streaks, streaks cause rank to level up
|
||||
public int loss_streak; //Number of loss streaks, streaks cause rank to level down
|
||||
public int overall_wins; //Number of overall wins
|
||||
public int overall_losses; //Number of overall losses
|
||||
public int rank_level; //Player's rank level, such as Level 1 Bronze, Level 2 Bronze etc.
|
||||
public int prevrank_level; //Records Player's rank level to compare if it changes/Player ranks up
|
||||
public int rank_game; //Keeps count of rank level, if reaches certain limit, then increments rank_level
|
||||
public int eliminations;
|
||||
public int deaths;
|
||||
public int revives;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
//SETTINGS PlayerPrefs Data Details
|
||||
#region
|
||||
// Details on GameObject position in the UI
|
||||
[System.Serializable]
|
||||
public class ControlSettings{
|
||||
public float positionX;
|
||||
public float positionY;
|
||||
public float scaleWidth;
|
||||
public float scaleHeight;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class GameSettings{
|
||||
public ControlSettings leftControl;
|
||||
public ControlSettings blockControl;
|
||||
public ControlSettings dodgeControl;
|
||||
|
||||
public ControlSettings rightControl;
|
||||
public ControlSettings punchControl;
|
||||
public ControlSettings kickControl;
|
||||
|
||||
// New controls/buttons
|
||||
public ControlSettings weaponPickupButton;
|
||||
public ControlSettings specialMoveButton;
|
||||
public ControlSettings shieldButton;
|
||||
public ControlSettings splintButton;
|
||||
|
||||
public float leftControlScaleValue;
|
||||
public float rightControlScaleValue;
|
||||
public float kickControlScaleValue;
|
||||
public float punchControlScaleValue;
|
||||
|
||||
public float GameplayVolume_value;
|
||||
public float UIVolume_value;
|
||||
public float MusicVolume_value;
|
||||
public float SFXVolume_value;
|
||||
|
||||
public string[] audioVolumes; //0. GameplayVolume, 1. UIVolume, 2. MusicVolume, 3. SFXVolume
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
public class GameInitialize : MonoBehaviour{
|
||||
private static bool isInitialized = false;
|
||||
public static GameInitialize Instance { get; private set; }
|
||||
[SerializeField] private string authSceneName = "AuthenticationScene";
|
||||
[SerializeField] private string menuSceneName = "MenuScene";
|
||||
[Tooltip("Force skip auth and go straight to menu after splash")] [SerializeField]
|
||||
private bool forceMenuDuringDevelopment = true;
|
||||
|
||||
private Coroutine authRoutine;
|
||||
private bool subscribedToSplash;
|
||||
private bool waitingForGameManager;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isInitialized)
|
||||
{
|
||||
isInitialized = true;
|
||||
Instance = this;
|
||||
// Move to root before DontDestroyOnLoad (required for it to work)
|
||||
transform.SetParent(null);
|
||||
DontDestroyOnLoad(gameObject);
|
||||
TryStartAuthFlow();
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (GameManager.Instance == null && !waitingForGameManager)
|
||||
{
|
||||
waitingForGameManager = true;
|
||||
StartCoroutine(WaitForGameManagerAndStart());
|
||||
}
|
||||
}
|
||||
|
||||
private void TryStartAuthFlow()
|
||||
{
|
||||
var gm = GameManager.Instance;
|
||||
if (gm == null)
|
||||
{
|
||||
if (!waitingForGameManager)
|
||||
{
|
||||
waitingForGameManager = true;
|
||||
StartCoroutine(WaitForGameManagerAndStart());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
waitingForGameManager = false;
|
||||
|
||||
// Development override: skip subscribing & auth checks entirely.
|
||||
if (forceMenuDuringDevelopment)
|
||||
{
|
||||
Debug.Log("[GameInitialize] forceMenuDuringDevelopment active: skipping auth flow & loading menu when splash ends (or immediately if already finished).");
|
||||
if (gm.HasSplashFinished)
|
||||
{
|
||||
TriggerSceneLoad(menuSceneName);
|
||||
}
|
||||
else if (!subscribedToSplash)
|
||||
{
|
||||
gm.SplashSequenceCompleted += () => TriggerSceneLoad(menuSceneName);
|
||||
subscribedToSplash = true; // still mark to avoid duplicate subscription
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (gm.HasSplashFinished)
|
||||
{
|
||||
BeginAuthCheck();
|
||||
}
|
||||
else if (!subscribedToSplash)
|
||||
{
|
||||
gm.SplashSequenceCompleted += HandleSplashSequenceCompleted;
|
||||
subscribedToSplash = true;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator WaitForGameManagerAndStart()
|
||||
{
|
||||
while (GameManager.Instance == null)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
waitingForGameManager = false;
|
||||
TryStartAuthFlow();
|
||||
}
|
||||
|
||||
private void HandleSplashSequenceCompleted()
|
||||
{
|
||||
if (GameManager.Instance != null && subscribedToSplash)
|
||||
{
|
||||
GameManager.Instance.SplashSequenceCompleted -= HandleSplashSequenceCompleted;
|
||||
}
|
||||
|
||||
subscribedToSplash = false;
|
||||
BeginAuthCheck();
|
||||
}
|
||||
|
||||
public void BeginAuthCheck()
|
||||
{
|
||||
if (authRoutine != null)
|
||||
{
|
||||
StopCoroutine(authRoutine);
|
||||
}
|
||||
|
||||
authRoutine = StartCoroutine(CheckAuthAndRedirectRoutine());
|
||||
}
|
||||
|
||||
private IEnumerator CheckAuthAndRedirectRoutine()
|
||||
{
|
||||
string targetScene = forceMenuDuringDevelopment ? menuSceneName : authSceneName; // still computed (kept for future toggle at runtime)
|
||||
string token = PlayerPrefs.GetString("AuthToken", null);
|
||||
|
||||
if (!forceMenuDuringDevelopment && !string.IsNullOrEmpty(token))
|
||||
{
|
||||
var walletSystem = CoinWalletSystem.Instance;
|
||||
if (walletSystem != null)
|
||||
{
|
||||
var initTask = walletSystem.InitializeWallet();
|
||||
while (!initTask.IsCompleted)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (initTask.Status == System.Threading.Tasks.TaskStatus.RanToCompletion && initTask.Result)
|
||||
{
|
||||
Debug.Log("Authentication successful. Loading menu.");
|
||||
targetScene = menuSceneName;
|
||||
}
|
||||
else
|
||||
{
|
||||
string reason = initTask.IsFaulted ? initTask.Exception?.GetBaseException()?.Message ?? "Wallet initialization faulted." : "Failed to initialize wallet.";
|
||||
RedirectToAuth(reason);
|
||||
authRoutine = null;
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("CoinWalletSystem instance not found. Proceeding to menu.");
|
||||
targetScene = menuSceneName;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("No auth token found. Redirecting to authentication.");
|
||||
RedirectToAuth("No auth token found.");
|
||||
authRoutine = null;
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (forceMenuDuringDevelopment)
|
||||
{
|
||||
// Should have been short-circuited earlier, but safeguard here.
|
||||
Debug.Log("[GameInitialize] (Late) development override still active; forcing menu.");
|
||||
targetScene = menuSceneName;
|
||||
}
|
||||
TriggerSceneLoad(targetScene);
|
||||
authRoutine = null;
|
||||
}
|
||||
|
||||
private void RedirectToAuth(string reason)
|
||||
{
|
||||
Debug.Log($"Redirecting to auth: {reason}");
|
||||
ClearStoredToken();
|
||||
TriggerSceneLoad(authSceneName);
|
||||
}
|
||||
|
||||
private void TriggerSceneLoad(string sceneName)
|
||||
{
|
||||
if (GameManager.Instance != null)
|
||||
{
|
||||
GameManager.Instance.LoadSceneWithLoading(sceneName);
|
||||
}
|
||||
else
|
||||
{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearStoredToken()
|
||||
{
|
||||
PlayerPrefs.DeleteKey("AuthToken");
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
public void OnSuccessfulAuthentication(string token)
|
||||
{
|
||||
PlayerPrefs.SetString("AuthToken", token);
|
||||
PlayerPrefs.Save();
|
||||
BeginAuthCheck();
|
||||
}
|
||||
|
||||
public void SetUserAuthenticated(bool authenticated)
|
||||
{
|
||||
if (forceMenuDuringDevelopment)
|
||||
{
|
||||
Debug.Log("[GameInitialize] Ignoring SetUserAuthenticated call because forceMenuDuringDevelopment is TRUE.");
|
||||
return;
|
||||
}
|
||||
if (!authenticated) RedirectToAuth("User logged out.");
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (GameManager.Instance != null && subscribedToSplash)
|
||||
{
|
||||
GameManager.Instance.SplashSequenceCompleted -= HandleSplashSequenceCompleted;
|
||||
}
|
||||
|
||||
if (Instance == this)
|
||||
{
|
||||
Instance = null;
|
||||
isInitialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameInit/GameInitialize.cs.meta
Normal file
11
Assets/Scripts/GameInit/GameInitialize.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 597bfaab5daad934abff4e69dab03af6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
402
Assets/Scripts/GameInit/GameStatsManager.cs
Normal file
402
Assets/Scripts/GameInit/GameStatsManager.cs
Normal file
@@ -0,0 +1,402 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using TMPro;
|
||||
using System;
|
||||
|
||||
|
||||
/*
|
||||
STEPS TO FOLLOW:
|
||||
1. There must be initialization of all PlayerPrefs for the game each time the game is started
|
||||
2. Add Missions from Menu Scene (MissionsManager.cs) to Game Scene (Missions.cs), with their respective Scripts considered
|
||||
3. When a mission is completed, trigger a function such as updateMission() or update_MonthlyMission() which will pass that mission's ID
|
||||
4. Within the specific triggered function, check if the mission ID is already stored, if not, then add the mission ID
|
||||
5. The mission ID is used to get the mission details such as XP, and then add the XP to the current player's recorded XP
|
||||
|
||||
*/
|
||||
|
||||
|
||||
public class GameStatsManager : MonoBehaviour{
|
||||
Missions mission_component;
|
||||
PlayerData players_profile_details, playerData;
|
||||
private MissionProgress missionProgress;
|
||||
private Completed_Missions_toAnimate completed_missions_toAnimate;
|
||||
|
||||
private const string Player_RewardsData = "Player_RewardsData";
|
||||
private const string player_missionData = "Player_MissionData";
|
||||
private const string player_completed_Missions_toAnimate = "Player_Completed_Missions_toAnimate";
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
//NOTE: The code below should be within a function which will then be called whenever the game starts
|
||||
if (PlayerPrefs.HasKey(player_missionData)){
|
||||
missionProgress = LoadPlayer_MissionData();
|
||||
}
|
||||
|
||||
|
||||
if (PlayerPrefs.HasKey(player_completed_Missions_toAnimate)){
|
||||
completed_missions_toAnimate = LoadPlayerData_CompletedMission_toAnimate();
|
||||
}
|
||||
|
||||
if (PlayerPrefs.HasKey(Player_RewardsData)){
|
||||
playerData = LoadPlayerData();
|
||||
}
|
||||
|
||||
mission_component = GetComponent<Missions>();
|
||||
}
|
||||
|
||||
|
||||
string ListToString<T>(List<T> list){
|
||||
// Use string.Join to concatenate the elements of the list into a string
|
||||
return string.Join(", ", list);
|
||||
}
|
||||
|
||||
|
||||
// Function called when the Player start a match
|
||||
public void addMatch(){
|
||||
SaveManager.Instance.AddMatch();
|
||||
}
|
||||
|
||||
|
||||
// Function called at the start of every match
|
||||
public void winsCountedEachMatch(){
|
||||
ResetMissions = false;
|
||||
wins_added = 0;
|
||||
loss_added = 0;
|
||||
}
|
||||
|
||||
|
||||
// Function called when the Player wins a round
|
||||
private int wins_added;
|
||||
public void addWin(){
|
||||
SaveManager.Instance.AddWin();
|
||||
}
|
||||
|
||||
|
||||
// Function called when the Player loses a round
|
||||
private int loss_added;
|
||||
public void addLoss(){
|
||||
SaveManager.Instance.AddLoss();
|
||||
}
|
||||
|
||||
|
||||
// Function called when the Player finishes a match
|
||||
public void match_end(){
|
||||
Debug.Log("Match Over, Start the Animation for the Completed Missions");
|
||||
go_to_menu("Missions"); //Go to Missions UI in MenuScene
|
||||
}
|
||||
|
||||
|
||||
// Function called when the Player quits a match
|
||||
public void match_quit(){
|
||||
// Debug.Log("Match Over, Start the Animation for the Completed Missions");
|
||||
addMatch();
|
||||
|
||||
go_to_menu("Home"); //Go to Missions UI in MenuScene
|
||||
}
|
||||
|
||||
|
||||
public void match_retry(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Updates the Player's RANK
|
||||
public string UpdateRank(int rank_num){
|
||||
string current_rank = "";
|
||||
|
||||
switch (rank_num){
|
||||
//x represents Game wins
|
||||
case int x when ((x >= 0 && x < 80) || (x < 0)):
|
||||
current_rank = "Bronze";
|
||||
break;
|
||||
|
||||
case int x when (x >= 80 && x < 140):
|
||||
current_rank = "Silver";
|
||||
break;
|
||||
|
||||
case int x when (x >= 140 && x < 200):
|
||||
current_rank = "Gold";
|
||||
break;
|
||||
|
||||
case int x when (x >= 200 && x < 260):
|
||||
current_rank = "Platinum";
|
||||
break;
|
||||
|
||||
case int x when (x >= 260 && x < 320):
|
||||
current_rank = "Diamond";
|
||||
break;
|
||||
|
||||
case int x when (x >= 320 && x < 400):
|
||||
current_rank = "Master";
|
||||
break;
|
||||
|
||||
case int x when (x == 400):
|
||||
current_rank = "Apex Predator";
|
||||
break;
|
||||
}
|
||||
return current_rank;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//UPDATE MISSIONS BASED ON INPUT
|
||||
//Alter this, so that the function can be called with the missionID, mission_type as the parameters to it
|
||||
public void updateMission(int missionID_completed){
|
||||
SaveManager.Instance.AddCompletedMission(missionID_completed);
|
||||
}
|
||||
|
||||
|
||||
// Function called when Player chooses to Retry
|
||||
public void ResetMissions_onRetry(){
|
||||
MissionProgress missionProgressReset = LoadPlayer_MissionData();
|
||||
Completed_Missions_toAnimate missionAnimateReset = LoadPlayerData_CompletedMission_toAnimate();
|
||||
playerData = LoadPlayerData();
|
||||
|
||||
//Overall Player Loss (OPL), Overall Player Wins (OPW), Wins In Match (WIM), Losses In Match (LIM)
|
||||
Debug.LogError($"R1 OPW = {playerData.overall_wins}, OPL = {playerData.overall_losses}, WIM = {wins_added}, LIM = {loss_added}");
|
||||
|
||||
if (playerData.overall_wins != 0){
|
||||
playerData = LoadPlayerData();
|
||||
playerData.overall_wins = playerData.overall_wins - wins_added;
|
||||
|
||||
if (playerData.overall_wins < 0){
|
||||
playerData.overall_wins = 0;
|
||||
}
|
||||
|
||||
SavePlayerData(playerData);
|
||||
}
|
||||
|
||||
if (playerData.overall_losses != 0){
|
||||
playerData = LoadPlayerData();
|
||||
playerData.overall_losses = playerData.overall_losses - loss_added;
|
||||
|
||||
if (playerData.overall_losses < 0){
|
||||
playerData.overall_losses = 0;
|
||||
}
|
||||
|
||||
SavePlayerData(playerData);
|
||||
}
|
||||
|
||||
//Reset Player XP for the Completed Missions, Reverse the match
|
||||
foreach (int missionID in missionAnimateReset.completed_missions_toAnimate_data){
|
||||
playerData = LoadPlayerData(); //Load
|
||||
missionProgressReset = LoadPlayer_MissionData();
|
||||
|
||||
missionProgressReset.completed_missions.Remove(missionID); //Remove the mission from recorded completed missions
|
||||
if (playerData.xp != 0){
|
||||
playerData.xp = playerData.xp - mission_component.getmission_XP(missionID, 0); //Reduce XP
|
||||
}
|
||||
|
||||
if (playerData.xp < 0){
|
||||
playerData.xp = 0;
|
||||
}
|
||||
|
||||
SavePlayerData(playerData); //Save
|
||||
SavePlayer_MissionData(missionProgressReset);
|
||||
}
|
||||
|
||||
//Reset Missions to Animate
|
||||
missionAnimateReset.completed_missions_toAnimate_data = new List<int> { };
|
||||
missionAnimateReset.animation_status = 0;
|
||||
SavePlayer_Completed_Missions_toAnimate(missionAnimateReset);
|
||||
|
||||
//Reset Completed Missions
|
||||
// missionProgressReset = LoadPlayer_MissionData();
|
||||
// missionProgressReset.completed_missions = new List<int>();
|
||||
// SavePlayer_MissionData(missionProgressReset);
|
||||
|
||||
playerData = LoadPlayerData();
|
||||
playerData.prevRank = playerData.rank;
|
||||
string player_rank = UpdateRank(playerData.rank_game);
|
||||
playerData.rank = player_rank;
|
||||
SavePlayerData(playerData);
|
||||
|
||||
//Overall Player Loss (OPL), Overall Player Wins (OPW), Wins In Match (WIM), Losses In Match (LIM)
|
||||
Debug.LogError($"R2 OPW = {playerData.overall_wins}, OPL = {playerData.overall_losses}, WIM = {wins_added}, LIM = {loss_added}, CM = {ListToString(missionProgressReset.completed_missions)}");
|
||||
|
||||
ResetMissions = true; //Quit functions have been done
|
||||
}
|
||||
|
||||
|
||||
// Function called when the Player Quits, Reset the Missions completed and XP gained from the match
|
||||
private bool ResetMissions;
|
||||
public void ResetCompletedMissions(){
|
||||
Debug.Log("ResetCompletedMissions");
|
||||
MissionProgress missionProgressReset = LoadPlayer_MissionData();
|
||||
Completed_Missions_toAnimate missionAnimateReset = LoadPlayerData_CompletedMission_toAnimate();
|
||||
playerData = LoadPlayerData();
|
||||
|
||||
//Overall Player Loss (OPL), Overall Player Wins (OPW), Wins In Match (WIM), Losses In Match (LIM)
|
||||
Debug.LogError($"R1 OPW = {playerData.overall_wins}, OPL = {playerData.overall_losses}, WIM = {wins_added}, LIM = {loss_added}");
|
||||
|
||||
if (playerData.overall_wins != 0){
|
||||
playerData = LoadPlayerData();
|
||||
playerData.overall_wins = playerData.overall_wins - wins_added;
|
||||
|
||||
if (playerData.overall_wins < 0){
|
||||
playerData.overall_wins = 0;
|
||||
}
|
||||
|
||||
SavePlayerData(playerData);
|
||||
}
|
||||
|
||||
if (playerData.overall_losses != 0){
|
||||
playerData = LoadPlayerData();
|
||||
playerData.overall_losses = playerData.overall_losses - loss_added;
|
||||
|
||||
if (playerData.overall_losses < 0){
|
||||
playerData.overall_losses = 0;
|
||||
}
|
||||
|
||||
SavePlayerData(playerData);
|
||||
}
|
||||
|
||||
//Reset Player XP for the Completed Missions, Reverse the match
|
||||
foreach (int missionID in missionAnimateReset.completed_missions_toAnimate_data){
|
||||
playerData = LoadPlayerData(); //Load
|
||||
missionProgressReset = LoadPlayer_MissionData();
|
||||
|
||||
missionProgressReset.completed_missions.Remove(missionID); //Remove the mission from recorded completed missions
|
||||
if (playerData.xp != 0){
|
||||
playerData.xp = playerData.xp - mission_component.getmission_XP(missionID, 0); //Reduce XP
|
||||
}
|
||||
|
||||
if (playerData.xp < 0){
|
||||
playerData.xp = 0;
|
||||
}
|
||||
|
||||
SavePlayerData(playerData); //Save
|
||||
SavePlayer_MissionData(missionProgressReset);
|
||||
}
|
||||
|
||||
//Reset Missions to Animate
|
||||
missionAnimateReset.completed_missions_toAnimate_data = new List<int> { };
|
||||
missionAnimateReset.animation_status = 1;
|
||||
SavePlayer_Completed_Missions_toAnimate(missionAnimateReset);
|
||||
|
||||
//Reset Completed Missions
|
||||
// missionProgressReset = LoadPlayer_MissionData();
|
||||
// missionProgressReset.completed_missions = new List<int>();
|
||||
// SavePlayer_MissionData(missionProgressReset);
|
||||
|
||||
for (int i=0; i<=2; i++){
|
||||
addLoss();
|
||||
// playerData = LoadPlayerData();
|
||||
// playerData.overall_losses = playerData.overall_losses + 1;
|
||||
// SavePlayerData(playerData);
|
||||
}
|
||||
|
||||
playerData = LoadPlayerData();
|
||||
playerData.prevRank = playerData.rank;
|
||||
string player_rank = UpdateRank(playerData.rank_game);
|
||||
playerData.rank = player_rank;
|
||||
SavePlayerData(playerData);
|
||||
|
||||
//Overall Player Loss (OPL), Overall Player Wins (OPW), Wins In Match (WIM), Losses In Match (LIM)
|
||||
Debug.LogError($"R2 OPW = {playerData.overall_wins}, OPL = {playerData.overall_losses}, WIM = {wins_added}, LIM = {loss_added}, CM = {ListToString(missionProgressReset.completed_missions)}");
|
||||
|
||||
ResetMissions = true; //Quit functions have been done
|
||||
}
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Change Scenes
|
||||
public string sceneToActivate = "MenuScene";
|
||||
public void go_to_menu(string uiSubcomponentToActivate){
|
||||
//Show Loading UI
|
||||
GameManager.Instance.ShowLoadingUI();
|
||||
GameManager.Instance.gameObject.GetComponent<LoadingScreen>().UI_to_show_AfterLoading(1, "MenuScene");
|
||||
SceneManager.sceneLoaded += (scene, mode) => OnSceneLoaded(scene, mode, uiSubcomponentToActivate);
|
||||
GameManager.Instance.gameObject.GetComponent<LoadingScreen>().InitializeLoading();
|
||||
|
||||
}
|
||||
|
||||
// Function called when the new scene is loaded
|
||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode, string uiSubcomponentToActivate){
|
||||
if (scene.name == sceneToActivate){
|
||||
GameObject uiObject = GameObject.Find("UI");
|
||||
if (uiObject != null){
|
||||
ShowCompletedMissionsAnimation(uiObject, uiSubcomponentToActivate);
|
||||
}
|
||||
else{
|
||||
Debug.LogError("UI GameObject not found in MenuScene!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ShowCompletedMissionsAnimation(GameObject parent, string uiSubcomponentToActivate){
|
||||
foreach (Transform child in parent.transform){
|
||||
if ((child.name != "ModeSelection")){
|
||||
child.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (uiSubcomponentToActivate == "Home"){
|
||||
GameObject UI_to_be_shown = parent.transform.Find(uiSubcomponentToActivate).gameObject;
|
||||
UI_to_be_shown.SetActive(true); //When the Menu scene is activated, show this UI
|
||||
|
||||
if (ResetMissions == false){
|
||||
ResetCompletedMissions();
|
||||
}
|
||||
|
||||
}else{
|
||||
//Sets Missions UI to true
|
||||
Completed_Missions_toAnimate missionAnimateReset = LoadPlayerData_CompletedMission_toAnimate();
|
||||
missionAnimateReset.animation_status = 0;
|
||||
SavePlayer_Completed_Missions_toAnimate(missionAnimateReset);
|
||||
|
||||
GameObject UI_to_be_shown = parent.transform.Find(uiSubcomponentToActivate).gameObject;
|
||||
UI_to_be_shown.SetActive(true); //When the Menu scene is activated, show this UI
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ***** PLAYERPREFS
|
||||
//Serializes and Saves mission progress to PlayerPrefs.
|
||||
private void SavePlayer_MissionData(MissionProgress data){
|
||||
string jsonData = JsonUtility.ToJson(data);
|
||||
PlayerPrefs.SetString(player_missionData, jsonData); // Details stored as "PlayerData"
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
//Loads mission progress from PlayerPrefs.
|
||||
MissionProgress LoadPlayer_MissionData(){
|
||||
string jsonData = PlayerPrefs.GetString(player_missionData, "{}"); // Details were stored as "PlayerData"
|
||||
return JsonUtility.FromJson<MissionProgress>(jsonData);
|
||||
}
|
||||
|
||||
//Saves PlayerData to PlayerPrefs.
|
||||
private void SavePlayerData(PlayerData data){
|
||||
string jsonData = JsonUtility.ToJson(data);
|
||||
PlayerPrefs.SetString(Player_RewardsData, jsonData); // Details stored as "PlayerData"
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
//Load player data from PlayerPrefs
|
||||
PlayerData LoadPlayerData(){
|
||||
string jsonData = PlayerPrefs.GetString(Player_RewardsData, "{}"); // Details were stored as "PlayerData"
|
||||
return JsonUtility.FromJson<PlayerData>(jsonData);
|
||||
}
|
||||
|
||||
//Saves PlayerData to PlayerPrefs.
|
||||
private void SavePlayer_Completed_Missions_toAnimate(Completed_Missions_toAnimate data){
|
||||
string jsonData = JsonUtility.ToJson(data);
|
||||
PlayerPrefs.SetString(player_completed_Missions_toAnimate, jsonData); // Details stored as "PlayerData"
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
Completed_Missions_toAnimate LoadPlayerData_CompletedMission_toAnimate(){
|
||||
string jsonData = PlayerPrefs.GetString(player_completed_Missions_toAnimate, "{}"); // Details were stored as "PlayerData"
|
||||
return JsonUtility.FromJson<Completed_Missions_toAnimate>(jsonData);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameInit/GameStatsManager.cs.meta
Normal file
11
Assets/Scripts/GameInit/GameStatsManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27e9f37d9a1c17f46a3d2497be68edab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user