You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HighGroundRoyaleNetcode/Assets/Scripts/Gameplay/CursorManager.cs

43 lines
1.1 KiB
C#

1 week ago
using UnityEngine;
using System.Collections.Generic;
public class CursorManager : MonoBehaviour
{
[System.Serializable]
public struct CursorData
{
public CursorState state;
public Sprite cursorSprite;
}
public List<CursorData> cursorList = new List<CursorData>();
private Dictionary<CursorState, Sprite> cursorDictionary = new Dictionary<CursorState, Sprite>();
public GameObject cursorObject; // Assign CursorImage from the Prefab
private void Awake()
{
foreach (CursorData cursor in cursorList)
{
cursorDictionary[cursor.state] = cursor.cursorSprite;
}
}
private void Start()
{
GameStateManager.Instance.OnStateChanged += SetCursor;
SetCursor(GameStateManager.Instance.GetCurrentState());
}
private void SetCursor(CursorState state)
{
Debug.Log("SetCursor1: " + state);
if (cursorDictionary.TryGetValue(state, out Sprite cursorSprite))
{
cursorObject.GetComponent<UnityEngine.UI.Image>().sprite = cursorSprite;
Debug.Log("SetCursor2: " + state);
}
}
}