using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
[RequireComponent(typeof(PlayerInputManager))]
|
|
public class PlayerManager : MonoBehaviour
|
|
{
|
|
|
|
private static PlayerManager Instance;
|
|
|
|
|
|
[SerializeField]
|
|
private PlayerList m_connectedPlayers;
|
|
|
|
private PlayerInputManager m_playerManager;
|
|
|
|
|
|
private void OnEnable()
|
|
{
|
|
DoSingleton();
|
|
m_playerManager = GetComponent<PlayerInputManager>();
|
|
}
|
|
|
|
public void OnPlayerJoined(UnityEngine.InputSystem.PlayerInput player)
|
|
{
|
|
GameObject newPlayer = player.gameObject;
|
|
Debug.Log($"New Player Joined");
|
|
|
|
PlayerData data = m_connectedPlayers.AddPlayer(player);
|
|
newPlayer.GetComponent<PlayerDataHolder>().Initialise(data);
|
|
|
|
newPlayer.transform.SetParent(transform, false);
|
|
}
|
|
|
|
|
|
public void AllowJoin(bool value)
|
|
{
|
|
if (value)
|
|
m_playerManager.EnableJoining();
|
|
else
|
|
m_playerManager.DisableJoining();
|
|
}
|
|
|
|
private void DoSingleton()
|
|
{
|
|
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
|
|
}
|
|
}
|