using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.InputSystem; using NaughtyAttributes; using Random = UnityEngine.Random; [CreateAssetMenu(menuName = "Data/PlayerList")] public class PlayerList : ScriptableObject { [ShowNativeProperty] public int PlayerCount => Players.Count; public PlayerData[] AllPlayers => Players.Values.ToArray(); public Dictionary Players = new Dictionary(); private uint m_totalPlayerCount; public event EventHandler OnPlayerJoin; public PlayerData AddPlayer(UnityEngine.InputSystem.PlayerInput input) { uint ID = m_totalPlayerCount++; Color color = Random.ColorHSV(0, 1, 1, 1, 0.75f, 1); PlayerData data = PlayerData.Initialise(ID, color, input); Players.Add(input, data); OnPlayerJoin?.Invoke(this,data); return data; } [ContextMenu("Add Fake Player")] private void AddFakePlayer() { uint ID = m_totalPlayerCount++; Color color = Random.ColorHSV(0, 1, 1, 1, 0.75f, 1); PlayerData data = PlayerData.Initialise(ID, color, null); //Players.Add(null, data); OnPlayerJoin?.Invoke(this, data); } private void OnEnable() { Players = new Dictionary(); } }