fgm24/Assets/Scripts/Rope/GameState.cs

43 lines
1.1 KiB
C#

using Unity.Netcode;
using UnityEngine;
// FIXME: NetworkObject.NetworkObjectId are ulong but we're sending them as int. potential problem
[System.Serializable]
public struct GameState : INetworkSerializable
{
public int tick;
public NetworkRope nrope;
/// <summary>
/// x & y are location coords. z component is the <see cref="NetworkID.ID"/>
/// of the enemy.
/// </summary>
public Vector3[] enemyPositions;
/// <summary>
/// x & y are location coords. z component is the <see cref="NetworkID.ID"/>
/// of the player.
/// </summary>
public Vector3[] playerPositions;
public override int GetHashCode()
{
return tick;
}
public override bool Equals(object obj)
{
GameState other = (GameState) obj;
return this.GetHashCode() == obj.GetHashCode();
}
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
serializer.SerializeValue(ref tick);
serializer.SerializeValue(ref enemyPositions);
serializer.SerializeValue(ref playerPositions);
nrope.NetworkSerialize(serializer);
}
}