Include enemy posisions in gamestate

This commit is contained in:
Sveske_Juice 2024-03-17 19:59:34 +01:00
parent dc4309fba9
commit 9887ee0266
2 changed files with 5 additions and 2 deletions

View File

@ -1,10 +1,12 @@
using Unity.Netcode; using Unity.Netcode;
using UnityEngine;
[System.Serializable] [System.Serializable]
public struct GameState : INetworkSerializable public struct GameState : INetworkSerializable
{ {
public int tick; public int tick;
public NetworkRope nrope; public NetworkRope nrope;
public Vector2[] enemyPositions;
public override int GetHashCode() public override int GetHashCode()
{ {
@ -20,6 +22,7 @@ public struct GameState : INetworkSerializable
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{ {
serializer.SerializeValue(ref tick); serializer.SerializeValue(ref tick);
serializer.SerializeValue(ref enemyPositions);
nrope.NetworkSerialize(serializer); nrope.NetworkSerialize(serializer);
} }
} }

View File

@ -4,7 +4,6 @@ using System.Linq;
using Unity.Netcode; using Unity.Netcode;
using UnityEngine; using UnityEngine;
using UnityEngine.Assertions; using UnityEngine.Assertions;
using Utilities;
using UnityUtils; using UnityUtils;
public class RopeSimulator : NetworkBehaviour public class RopeSimulator : NetworkBehaviour
@ -315,7 +314,8 @@ public class RopeSimulator : NetworkBehaviour
{ {
GameState localState = new() { GameState localState = new() {
tick = currentTick, tick = currentTick,
nrope = Rope.ToNetworkRope(this.rope) nrope = Rope.ToNetworkRope(this.rope),
enemyPositions = GameObject.FindObjectsByType<EnemyPathFinding>(FindObjectsSortMode.None).Select(e => new Vector2(e.transform.position.x, e.transform.position.y)).ToArray()
}; };
return localState; return localState;