Cyber/Assets/Scripts/Networking/Messages/MoveCreaturePkt.cs

59 lines
1.8 KiB
C#
Raw Normal View History

2017-05-09 06:15:34 +02:00
using UnityEngine;
using UnityEngine.Networking;
namespace Cyber.Networking.Messages {
/// <summary>
/// Packet informing the client to move a creature, or the server to request change in movement.
/// More information at <see cref="PktType.MoveCreature"/>
/// </summary>
public class MoveCreaturePkt : MessageBase {
/// <summary>
/// Direction of the new movement (or (0, 0, 0) for stopping)
/// </summary>
public Vector3 Direction;
/// <summary>
/// SyncBase ID of the Creature to be moved.
/// </summary>
public int SyncBaseID;
/// <summary>
/// Creates a MoveCreaturePkt which contains the direction of desired movement (or (0, 0, 0) for stopping)
/// </summary>
/// <param name="direction">Direction of movement</param>
/// <param name="syncBaseId">SyncBase ID of the Creature.</param>
public MoveCreaturePkt(Vector3 direction, int syncBaseId) {
Direction = direction;
SyncBaseID = syncBaseId;
}
/// <summary>
/// Parameter-less constructor using when deserializing the message.
/// </summary>
public MoveCreaturePkt() {
}
/// <summary>
/// Used to deserialize a message received via networking.
/// </summary>
/// <param name="reader"></param>
public override void Deserialize(NetworkReader reader) {
Direction = reader.ReadVector3();
SyncBaseID = reader.ReadInt32();
}
/// <summary>
/// Used to serialize the message before it is sent.
/// </summary>
/// <param name="writer"></param>
public override void Serialize(NetworkWriter writer) {
writer.Write(Direction);
writer.Write(SyncBaseID);
}
}
}