From 4bf280465070a6dc681c3eedd49436fecd76b7e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20P=C4=9Bnkava?= Date: Sat, 2 Aug 2025 15:35:39 +0200 Subject: [PATCH] PotionGui --- .../Assets/Prefabs/PlayerContainer.prefab | 8 ++--- .../Assets/Prefabs/Scripts/RoomHandler.cs | 1 + .../Assets/Scripts/Player/PlayerSkillTree.cs | 32 ++++++++++++++++--- .../Scripts/PotionsSkills/PotionHandler.cs | 18 +++++++---- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/3D blobici/Assets/Prefabs/PlayerContainer.prefab b/3D blobici/Assets/Prefabs/PlayerContainer.prefab index 4ffcaf2..547562d 100644 --- a/3D blobici/Assets/Prefabs/PlayerContainer.prefab +++ b/3D blobici/Assets/Prefabs/PlayerContainer.prefab @@ -13,7 +13,7 @@ GameObject: - component: {fileID: 535055519960375857} - component: {fileID: 2492104367656422644} m_Layer: 0 - m_Name: Text (TMP) + m_Name: HealthBig m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -35,7 +35,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 100, y: 0} + m_AnchoredPosition: {x: 150, y: 0} m_SizeDelta: {x: 200, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &3729392411308814688 @@ -297,7 +297,7 @@ GameObject: - component: {fileID: 4795552151069639100} - component: {fileID: 4576974581871443905} m_Layer: 0 - m_Name: Text (TMP) + m_Name: HealthBig m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -319,7 +319,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 100, y: 0} + m_AnchoredPosition: {x: 150, y: 0} m_SizeDelta: {x: 200, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &5692096231889078255 diff --git a/3D blobici/Assets/Prefabs/Scripts/RoomHandler.cs b/3D blobici/Assets/Prefabs/Scripts/RoomHandler.cs index 24a7c7b..df83815 100644 --- a/3D blobici/Assets/Prefabs/Scripts/RoomHandler.cs +++ b/3D blobici/Assets/Prefabs/Scripts/RoomHandler.cs @@ -73,6 +73,7 @@ public class RoomHandler : MonoBehaviour enemyPrefabsLocal.RemoveAt(0); // Select a spawn point with round-robin + Debug.Log("Ammount of spawn points: " + spawnPoints.Count); GameObject spawnPoint = spawnPoints[i % spawnPoints.Count]; Instantiate(enemyPrefab, spawnPoint.transform.position + new Vector3(0, 1, 0), Quaternion.identity); diff --git a/3D blobici/Assets/Scripts/Player/PlayerSkillTree.cs b/3D blobici/Assets/Scripts/Player/PlayerSkillTree.cs index 8bd1a32..036fd96 100644 --- a/3D blobici/Assets/Scripts/Player/PlayerSkillTree.cs +++ b/3D blobici/Assets/Scripts/Player/PlayerSkillTree.cs @@ -1,12 +1,15 @@ using System.Collections.Generic; using UnityEngine; using System.Collections; +using System.ComponentModel; +using UnityEditor.SceneManagement; +using static PotionHandler; public class PlayerSkillTree { private static PlayerSkillTree _instance; - private PotionHandler potionHandler; + private Dictionary potionHandlers = new Dictionary(); public static PlayerSkillTree Instance { @@ -38,14 +41,29 @@ public class PlayerSkillTree public PlayerSkillTree() { playerSkills = new List(); - potionHandler = new PotionHandler(); + + } + + public void RegisterPotionHandler(PotionType type, PotionHandler handler) + { + if (!potionHandlers.ContainsKey(type)) + { + potionHandlers.Add(type, handler); + } + else + { + potionHandlers[type] = handler; + } } public void UnlockSkill(Skills skill, PotionHandler.PotionType potionType) { if(skill == Skills.Potion){ - potionHandler.AddPotion(potionType); + if (potionHandlers.TryGetValue(potionType, out PotionHandler handler)) + { + handler.AddPotion(potionType); + } return; } @@ -56,8 +74,12 @@ public class PlayerSkillTree public bool TryUsePotion(PotionHandler.PotionType potionType) { - if(potionHandler.IsEmpty(potionType)) return false; - return potionHandler.UsePotion(potionType); + if (potionHandlers.TryGetValue(potionType, out PotionHandler handler)) + { + if (handler.IsEmpty(potionType)) return false; + return handler.UsePotion(potionType); + } + return false; } diff --git a/3D blobici/Assets/Scripts/PotionsSkills/PotionHandler.cs b/3D blobici/Assets/Scripts/PotionsSkills/PotionHandler.cs index 23b866f..d49548d 100644 --- a/3D blobici/Assets/Scripts/PotionsSkills/PotionHandler.cs +++ b/3D blobici/Assets/Scripts/PotionsSkills/PotionHandler.cs @@ -7,7 +7,7 @@ public class PotionHandler:MonoBehaviour // Start is called once before the first execution of Update after the MonoBehaviour is created private Dictionary potions = new Dictionary(); - [SerializeField] private TextMeshProUGUI textMeshProUGUI; + [SerializeField] private TMP_Text textMeshProUGUI; [SerializeField] private PotionType potionType; public enum PotionType @@ -18,34 +18,40 @@ public class PotionHandler:MonoBehaviour None } - public PotionHandler() + private void Awake() { foreach (PotionType type in System.Enum.GetValues(typeof(PotionType))) { potions.Add(type, 0); } - //textMeshProUGUI.text = potions[potionType].ToString(); + textMeshProUGUI.text = potions[potionType].ToString(); + // Register this handler with the PlayerSkillTree + PlayerSkillTree.Instance.RegisterPotionHandler(potionType, this); } - public void AddPotion(PotionType type, int amount = 1) { potions[type] += amount; - Debug.Log(potions[type]); if(type == potionType) { textMeshProUGUI.text= potions[type].ToString(); } - //Debug.Log("Text is: " + textMeshProUGUI.text); + Debug.Log("Potion text is: " + textMeshProUGUI.text); } public bool UsePotion(PotionType type, int amount = 1) { potions[type] -= amount; + + if (type == potionType) + { + textMeshProUGUI.text = potions[type].ToString(); + } + return true; }