Multiplayer now joinable!!! NO ERRORS ON JOIN!!!

This commit is contained in:
BOTAlex 2024-02-20 03:19:28 +01:00
parent 32f5f27201
commit c590bc893f
16 changed files with 126 additions and 13 deletions

View File

@ -3958,6 +3958,10 @@ PrefabInstance:
propertyPath: m_Targets.Array.data[1].target
value:
objectReference: {fileID: 0}
- target: {fileID: 3603265075407754381, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
propertyPath: players.Array.size
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3603265075407754381, guid: c53e6971c95afb1429cd82616a7b6737, type: 3}
propertyPath: players.Array.data[0]
value:

View File

@ -22,7 +22,7 @@ public class EnemySpawner : MonoBehaviour
[SerializeField] private List<float> enemyDifficulties;
[SerializeField] private float SpawnRadius = 10;
[SerializeField] private int NumEnemies = 6;
[SerializeField] private GameObject[] players;
[SerializeField] public GameObject[] players;
[SerializeField] private float initialSpawnDelay = 5;
// local
@ -34,6 +34,20 @@ public class EnemySpawner : MonoBehaviour
private bool SpawnerStarted = false;
public static EnemySpawner instance;
private void Awake()
{
if (instance == null)
{
instance = this;
}
else
{
Destroy(instance);
}
}
private void Start()
{
mainCam = Camera.main;

View File

@ -0,0 +1,20 @@
{
"name": "Project.Scritps.Enemy",
"rootNamespace": "",
"references": [
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:2ea4a18a75f268848b43865100892489",
"GUID:055e16077a1232f4780a04598b3bfe00",
"GUID:1031dfc67c8f1a645b71d679ac3bf7db",
"GUID:0ba5c175a7b2c8345a4e996560a9d0ab"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 62165c64e8180c441b8cfaa6b82208af
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -6,7 +6,8 @@
"GUID:2ea4a18a75f268848b43865100892489",
"GUID:f4c364e1215051e4dbc6c0bc8fb49793",
"GUID:42d1898a72cfe6848ae89835fb20acd2",
"GUID:0ba5c175a7b2c8345a4e996560a9d0ab"
"GUID:0ba5c175a7b2c8345a4e996560a9d0ab",
"GUID:4307f53044263cf4b835bd812fc161a4"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@ -1,3 +1,4 @@
using Assets.Scripts.Multiplayer;
using System;
using System.Collections;
using System.Collections.Generic;
@ -7,7 +8,7 @@ using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LocalManager : MonoBehaviour
public class LocalManager : ZNetworkData
{
[SerializeField] private Button HostBtn;
[SerializeField] private Button JoinBtn;
@ -30,6 +31,8 @@ public class LocalManager : MonoBehaviour
private void HostLobby()
{
IsServer = true;
NetworkManager.Singleton.StartHost();
UpdateUI();

View File

@ -1,8 +1,11 @@
using Assets.Scripts.Multiplayer;
using Steamworks.ServerList;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.Netcode;
using Unity.Netcode.Transports.UTP;
using UnityEngine;
using UnityEngine.SceneManagement;
using static UnityEditor.Experimental.GraphView.GraphView;
@ -29,8 +32,10 @@ public class NetworkedGameSetup : NetworkBehaviour
private void StartSetupProcedure(List<ulong> playerIds)
{
bool isServer = SteamManager.IsServer || LocalManager.IsServer;
GameObject[] players;
if (IsHost || IsServer)
if (isServer)
players = SpawnPlayers(playerIds);
else
players = GetPlayers(playerIds);
@ -47,11 +52,13 @@ public class NetworkedGameSetup : NetworkBehaviour
InitUpgrader(players);
InitBlood(players);
InitSpawner(players);
}
private GameObject[] GetPlayers(List<ulong> playerIds)
{
GameObject[] players = NetworkManager.SpawnManager.SpawnedObjects.Select(x=>x.Value.gameObject).ToArray();
GameObject[] players = NetworkManager.SpawnManager.SpawnedObjects.Where(x => playerIds.Contains(x.Value.NetworkObjectId)).Select(x => x.Value.gameObject).ToArray();
return players;
}
@ -72,23 +79,55 @@ public class NetworkedGameSetup : NetworkBehaviour
private void InitRope(GameObject[] players)
{
// Assuming 2 players
if (players.Length == 1)
{
RopeSimulator.instance.BuildRope(players[0].GetComponent<RopeJoint>(), players[0].GetComponent<RopeJoint>());
}
else // 2 players
{
RopeSimulator.instance.BuildRope(players[0].GetComponent<RopeJoint>(), players[1].GetComponent<RopeJoint>());
}
}
private void InitUpgrader(GameObject[] players)
{
return; // fuck this upgrade system
Upgrader upgradeSystem = Upgrader.instance;
if (players.Length == 1)
{
upgradeSystem.player1 = players[0];
upgradeSystem.player2 = players[0];
}
else // 2 players
{
upgradeSystem.player1 = players[0];
upgradeSystem.player2 = players[1];
}
}
private void InitBlood(GameObject[] players)
{
BloodComputeShader bloodScript = BloodComputeShader.Instance;
if (players.Length == 1)
{
bloodScript.mop1 = players[0].GetComponent<Mop>();
bloodScript.mop2 = players[0].GetComponent<Mop>();
}
else // 2 players
{
bloodScript.mop1 = players[0].GetComponent<Mop>();
bloodScript.mop2 = players[1].GetComponent<Mop>();
}
}
private void InitSpawner(GameObject[] players)
{
EnemySpawner spawner = EnemySpawner.instance;
spawner.players = players;
}
}

View File

@ -11,7 +11,8 @@
"GUID:dfa0fc7c5444edd619a15e6f8c8f242a",
"GUID:42d1898a72cfe6848ae89835fb20acd2",
"GUID:ff1c299121c93f34ca827a253fc30a61",
"GUID:1eb4e3e6c04cdc848bab71651b1e2ecd"
"GUID:1eb4e3e6c04cdc848bab71651b1e2ecd",
"GUID:62165c64e8180c441b8cfaa6b82208af"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@ -1,3 +1,4 @@
using Assets.Scripts.Multiplayer;
using Netcode.Transports.Facepunch;
using Steamworks;
using Steamworks.Data;
@ -10,7 +11,7 @@ using Unity.Netcode.Transports.UTP;
using UnityEngine;
using UnityEngine.UI;
public class SteamManager : MonoBehaviour
public class SteamManager : ZNetworkData
{
[SerializeField] private Button HostBtn;
[SerializeField] private Button JoinBtn;
@ -72,6 +73,8 @@ public class SteamManager : MonoBehaviour
public async void HostLobby()
{
IsServer = true;
await SteamMatchmaking.CreateLobbyAsync(4);
}

View File

@ -0,0 +1,10 @@
using System.Collections;
using UnityEngine;
namespace Assets.Scripts.Multiplayer
{
public abstract class ZNetworkData : MonoBehaviour
{
public static bool IsServer = false; // Only used during game setup. Do not use after
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c78c95d904ecac24dba98ce72f5020af
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: