Global Game Jam 2021
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.5 KiB

3 years ago
3 years ago
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. using UnityEngine.InputSystem;
  7. using NaughtyAttributes;
  8. using Random = UnityEngine.Random;
  9. [CreateAssetMenu(menuName = "Data/PlayerList")]
  10. public class PlayerList : ScriptableObject
  11. {
  12. [ShowNativeProperty]
  13. public int PlayerCount => Players.Count;
  14. public PlayerData[] AllPlayers => Players.Values.ToArray();
  15. public Dictionary<PlayerInput, PlayerData> Players = new Dictionary<PlayerInput, PlayerData>();
  16. private uint m_totalPlayerCount;
  17. public event EventHandler<PlayerData> OnPlayerJoin;
  18. public PlayerData AddPlayer(UnityEngine.InputSystem.PlayerInput input)
  19. {
  20. uint ID = m_totalPlayerCount++;
  21. Color color = Random.ColorHSV(0, 1, 1, 1, 0.75f, 1);
  22. PlayerData data = PlayerData.Initialise(ID, color, input);
  23. data.Score = Random.Range(2, 10);
  24. Players.Add(input, data);
  25. OnPlayerJoin?.Invoke(this,data);
  26. return data;
  27. }
  28. [ContextMenu("Add Fake Player")]
  29. private void AddFakePlayer()
  30. {
  31. uint ID = m_totalPlayerCount++;
  32. Color color = Random.ColorHSV(0, 1, 1, 1, 0.75f, 1);
  33. PlayerData data = PlayerData.Initialise(ID, color, null);
  34. //Players.Add(null, data);
  35. OnPlayerJoin?.Invoke(this, data);
  36. }
  37. private void OnEnable()
  38. {
  39. Players = new Dictionary<UnityEngine.InputSystem.PlayerInput, PlayerData>();
  40. }
  41. }