2024-02-09 02:38:39 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Unity.Netcode;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
2024-02-09 04:09:08 +01:00
|
|
|
public class NetworkedGameSetup : NetworkBehaviour
|
2024-02-09 02:38:39 +01:00
|
|
|
{
|
|
|
|
[SerializeField] private GameObject PlayerPrefab;
|
|
|
|
|
2024-02-14 04:30:38 +01:00
|
|
|
private RopeSimulator RopeSim;
|
|
|
|
|
2024-02-09 02:38:39 +01:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
DontDestroyOnLoad(this);
|
|
|
|
NetworkManager.Singleton.SceneManager.OnLoadEventCompleted += SceneLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SceneLoaded(string sceneName, LoadSceneMode loadSceneMode, List<ulong> clientsCompleted, List<ulong> clientsTimedOut)
|
|
|
|
{
|
2024-02-14 04:30:38 +01:00
|
|
|
StartSetupProcedure(clientsCompleted);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void StartSetupProcedure(List<ulong> playerIds)
|
|
|
|
{
|
|
|
|
SpawnPlayers(playerIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SpawnPlayers(List<ulong> playerIds)
|
|
|
|
{
|
|
|
|
NetworkManager.Singleton.SceneManager.OnLoadEventCompleted -= SceneLoaded;
|
|
|
|
|
|
|
|
// Assuming only 2 palyers
|
|
|
|
if (IsHost)
|
2024-02-09 02:38:39 +01:00
|
|
|
{
|
2024-02-14 04:30:38 +01:00
|
|
|
for (int i = 0; i < playerIds.Count; i++)
|
2024-02-09 02:38:39 +01:00
|
|
|
{
|
|
|
|
GameObject player = Instantiate(PlayerPrefab, Vector2.up * 3, Quaternion.identity);
|
2024-02-14 04:30:38 +01:00
|
|
|
player.GetComponent<NetworkObject>().SpawnAsPlayerObject(playerIds[i], true);
|
2024-02-09 02:38:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|