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.

57 lines
1.4 KiB

  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 Dictionary<UnityEngine.InputSystem.PlayerInput, PlayerData> Players = new Dictionary<UnityEngine.InputSystem.PlayerInput, PlayerData>();
  15. private uint m_totalPlayerCount;
  16. public event EventHandler<PlayerData> OnPlayerJoin;
  17. public PlayerData AddPlayer(UnityEngine.InputSystem.PlayerInput input)
  18. {
  19. uint ID = m_totalPlayerCount++;
  20. Color color = Random.ColorHSV(0, 1, 1, 1, 0.75f, 1);
  21. PlayerData data = PlayerData.Initialise(ID, color, input);
  22. Players.Add(input, data);
  23. OnPlayerJoin?.Invoke(this,data);
  24. return data;
  25. }
  26. [ContextMenu("Add Fake Player")]
  27. private void AddFakePlayer()
  28. {
  29. uint ID = m_totalPlayerCount++;
  30. Color color = Random.ColorHSV(0, 1, 1, 1, 0.75f, 1);
  31. PlayerData data = PlayerData.Initialise(ID, color, null);
  32. //Players.Add(null, data);
  33. OnPlayerJoin?.Invoke(this, data);
  34. }
  35. private void OnEnable()
  36. {
  37. Players = new Dictionary<UnityEngine.InputSystem.PlayerInput, PlayerData>();
  38. }
  39. }