using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; class SkillsPointsManger : MonoBehaviour { public const string PLAYER_SKILS_FREE_POINTS = "Player.Skills.FreePoints"; public const string PLAYER_SKILS_HEALTH_POINTS = "Player.Skills.HealthPoints"; public const string PLAYER_SKILS_STRENGHT_POINTS = "Player.Skills.StenghtPoints"; public const string PLAYER_SKILS_DEFENSE_POINTS = "Player.Skills.DefensePoints"; public const string PLAYER_SKILS_INTELIGENCE_POINTS = "Player.Skills.InteligencePoints"; public static SkillsPointsManger Instance; [Header("Player Skills Points")] public int FreePoints = 0; public int StrenghtPoints = 0; public int DefensePoints = 0; public int HealthPoints = 0; public int InteligencePoints = 0; public void Awake() { if (Instance == null) { // Load saved gold value LoadValue(); Instance = this; } else { Destroy(gameObject); } } /// /// Function to load values after loading scenes but after changing them by player script /// Thats because: /// - this manager fetch values globally on scene /// - Skills Panel gets info from this script /// - but.. Plater script modify vales themself and save them in PlayerPrefs instead of this Singleton class - messy... /// So we must fetch every one change from player.cs /// public void LoadValue() { if (PlayerPrefs.HasKey(PLAYER_SKILS_FREE_POINTS)) { FreePoints = PlayerPrefs.GetInt(PLAYER_SKILS_FREE_POINTS); } if (PlayerPrefs.HasKey(PLAYER_SKILS_HEALTH_POINTS)) { HealthPoints = PlayerPrefs.GetInt(PLAYER_SKILS_HEALTH_POINTS); } if (PlayerPrefs.HasKey(PLAYER_SKILS_STRENGHT_POINTS)) { StrenghtPoints = PlayerPrefs.GetInt(PLAYER_SKILS_STRENGHT_POINTS); } if (PlayerPrefs.HasKey(PLAYER_SKILS_DEFENSE_POINTS)) { DefensePoints = PlayerPrefs.GetInt(PLAYER_SKILS_DEFENSE_POINTS); } if (PlayerPrefs.HasKey(PLAYER_SKILS_INTELIGENCE_POINTS)) { InteligencePoints = PlayerPrefs.GetInt(PLAYER_SKILS_INTELIGENCE_POINTS); } } /// /// Points are added after level up! :D /// see Player::ManageLevels /// public void AddFreePoints(int newPoints) { FreePoints += newPoints; PlayerPrefs.SetInt(PLAYER_SKILS_FREE_POINTS, FreePoints); } /// /// Function to update value displayed on Inventory Panel - only if is opened /// public void UpdatePanelView() { LoadValue(); if (SkillsUIManager.Instance.GetPanelStatus()) { Debug.Log("UpdatePanelView"); //SkillsUIManager SkillsUIManager.Instance.DynamicPanel.GetComponent().RefreshPanelView( FreePoints, StrenghtPoints, DefensePoints, HealthPoints, InteligencePoints ); } } }