Skill Logic

Implemented basic UI for skills to player
This commit is contained in:
2025-07-27 23:48:47 +02:00
parent 4fa9e01768
commit 6179c5bc0e
33 changed files with 1047 additions and 181 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 96b8a58e3e105b8449af86511eb40528
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,97 @@
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using System;
public class CardManager : MonoBehaviour
{
public static CardManager Instance;
[SerializeField] private List<GameObject> cardPrefabs;
[SerializeField] private Transform cardsParent;
private PlayerSkillTree playerSkillTree;
private GameObject cards;
private void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Destroy(gameObject);
}
}
private void Start()
{
playerSkillTree = PlayerSkillTree.Instance;
cards = GameObject.Find("Cards");
cards.SetActive(false);
}
public void Update()
{
if (Input.GetKeyDown(KeyCode.V))
{
cards.SetActive(true);
ShowRandomCards(3);
}
}
public void ShowRandomCards(int count)
{
var unlockedSkills = playerSkillTree.GetPlayerSkills();
// Projdeme všechny prefaby a zkontrolujeme jejich skill
var availableCards = cardPrefabs
.Select(x => x.GetComponent<CardUI>())
.Where(x => x != null && !unlockedSkills.Contains(x.Skill))
.ToList();
// Vyčistíme staré karty
foreach (Transform child in cardsParent)
{
Destroy(child.gameObject);
}
// Vybereme náhodné karty
var shuffled = availableCards.OrderBy(x => UnityEngine.Random.value).Take(count).ToList();
Debug.Log($"Showing cards: {string.Join(", ", shuffled.Select(x => x.Skill))}");
Debug.Log($"Available cards: {string.Join(", ", availableCards.Select(x => x.Skill))}");
Debug.Log($"Unlocked skills: {string.Join(", ", unlockedSkills)}");
int xOffset = -800;
if (availableCards.Count < 3)
{
xOffset = -400;
}
foreach (var cardUI in shuffled)
{
var newCard = Instantiate(cardUI.gameObject, cardsParent.position + new Vector3(xOffset, 0, 0), Quaternion.identity, cardsParent);
xOffset += 800;
}
}
public void SelectCard(PlayerSkillTree.Skills skill)
{
playerSkillTree.UnlockSkill(skill);
foreach (Transform child in cardsParent)
{
var cardUI = child.GetComponent<CardUI>();
if (cardUI.Skill == skill)
{
Destroy(child.gameObject);
}
}
cards.SetActive(false);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ac4402de23efee441a6fe1c443a1f3ed

View File

@@ -0,0 +1,23 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class CardUI : MonoBehaviour
{
[SerializeField] private string cardname;
[SerializeField] private PlayerSkillTree.Skills skill;
public PlayerSkillTree.Skills Skill { get => skill; private set => skill = value; }
public string Name { get => cardname; private set => cardname = value; }
private void Start()
{
Skill = skill;
GetComponent<Button>().onClick.AddListener(OnCardClicked);
}
private void OnCardClicked()
{
CardManager.Instance.SelectCard(Skill);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0da9907611db3a04382aa4902957927c

View File

@@ -1,3 +1,4 @@
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
@@ -9,12 +10,26 @@ public class PlayerMovement : MonoBehaviour
private CharacterController controller;
private Vector3 velocity;
private PlayerSkillTree PlayerSkills;
private void Awake()
{
PlayerSkills = PlayerSkillTree.Instance;
}
void Start()
{
controller = GetComponent<CharacterController>();
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
HandleDash();
}
}
void FixedUpdate()
{
HandleMovement();
@@ -38,6 +53,19 @@ public class PlayerMovement : MonoBehaviour
}
}
void HandleDash()
{
if (PlayerSkills.IsSkillUnlocked(PlayerSkillTree.Skills.Dash))
{
// Implement dash logic
Debug.Log("Dashing!");
}
else
{
Debug.Log("Dash skill is not unlocked.");
}
}
void ApplyGravity()
{
if (IsGrounded() && velocity.y < 0) velocity.y = -2f;
@@ -50,4 +78,9 @@ public class PlayerMovement : MonoBehaviour
float groundDistance = 0.2f;
return Physics.Raycast(transform.position, Vector3.down, groundDistance);
}
public List<PlayerSkillTree.Skills> GetPlayerSkills()
{
return PlayerSkills.GetPlayerSkills();
}
}

View File

@@ -0,0 +1,51 @@
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
public class PlayerSkillTree
{
private static PlayerSkillTree _instance;
public static PlayerSkillTree Instance
{
get
{
if (_instance == null)
{
_instance = new PlayerSkillTree();
}
return _instance;
}
}
public enum Skills
{
Dash,
Rush,
Kek,
LMAO
}
private List<Skills> playerSkills;
public PlayerSkillTree()
{
playerSkills = new List<Skills>();
}
public void UnlockSkill(Skills skill)
{
playerSkills.Add(skill);
}
public bool IsSkillUnlocked(Skills skill)
{
return playerSkills.Contains(skill);
}
public List<Skills> GetPlayerSkills() { return playerSkills; }
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8ee023dad7da1b5498077a6744499037