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

View File

@ -4,7 +4,6 @@ using System.Linq;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Assertions;
using Utilities;
using UnityUtils;
public class RopeSimulator : NetworkBehaviour
@ -315,7 +314,8 @@ public class RopeSimulator : NetworkBehaviour
{
GameState localState = new() {
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;