Create InteractionType and network it and fix some docs

This commit is contained in:
Sofia 2017-05-12 01:41:57 +03:00
parent 127d7b1565
commit 542a8cc360
6 changed files with 45 additions and 2 deletions

View File

@ -4,6 +4,7 @@ using Cyber.Console;
using Cyber.Networking.Clientside; using Cyber.Networking.Clientside;
using Cyber.Networking; using Cyber.Networking;
using Cyber.Networking.Messages; using Cyber.Networking.Messages;
using Cyber.Entities;
namespace Cyber.Controls { namespace Cyber.Controls {
@ -56,7 +57,7 @@ namespace Cyber.Controls {
if (LookingAt != null && (LookingAt.transform.position - Character.GetPosition()).magnitude < Character.InteractionDistance) { if (LookingAt != null && (LookingAt.transform.position - Character.GetPosition()).magnitude < Character.InteractionDistance) {
LookingAt.Interact(Character); LookingAt.Interact(Character);
if (LookingAt.GetInteractableSyncdata().PublicInteractions) { if (LookingAt.GetInteractableSyncdata().PublicInteractions) {
Client.Send(PktType.Interact, new InteractionPkt(LookingAt.ID)); Client.Send(PktType.Interact, new InteractionPkt(LookingAt.ID, InteractionType.Press));
} }
} }
} }

View File

@ -0,0 +1,12 @@

namespace Cyber.Entities {
/// <summary>
/// Describes the type of interaction being made.
/// </summary>
public enum InteractionType : byte {
Press, Release, Enter, Exit
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d4438a8b75336fd46ab611ac2f2e745f
timeCreated: 1494542205
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -54,6 +54,10 @@ namespace Cyber.Entities {
return Spawned; return Spawned;
} }
/// <summary>
/// Removes the gameobject that was given as an argument from the world.
/// </summary>
/// <param name="gameObject">Gameobject to be removed.</param>
public void Remove(GameObject gameObject) { public void Remove(GameObject gameObject) {
SyncDB.RemoveEntity(gameObject); SyncDB.RemoveEntity(gameObject);
Destroy(gameObject); Destroy(gameObject);

View File

@ -1,4 +1,5 @@
 
using Cyber.Entities;
using UnityEngine.Networking; using UnityEngine.Networking;
namespace Cyber.Networking.Messages { namespace Cyber.Networking.Messages {
@ -18,12 +19,19 @@ namespace Cyber.Networking.Messages {
/// </summary> /// </summary>
public int OwnerSyncBaseID; public int OwnerSyncBaseID;
/// <summary>
/// The interaction type that was made.
/// </summary>
public InteractionType InteractionType;
/// <summary> /// <summary>
/// Creates an InteraktionPkt, which contains the message "someone interacted". /// Creates an InteraktionPkt, which contains the message "someone interacted".
/// </summary> /// </summary>
/// <param name="syncBaseID">The Sync Base ID of the interacted thing.</param> /// <param name="syncBaseID">The Sync Base ID of the interacted thing.</param>
public InteractionPkt(int syncBaseID) { /// <param name="interactionType">The type of interaction that was made.</param>
public InteractionPkt(int syncBaseID, InteractionType interactionType) {
InteractSyncBaseID = syncBaseID; InteractSyncBaseID = syncBaseID;
InteractionType = interactionType;
} }
/// <summary> /// <summary>
@ -38,6 +46,7 @@ namespace Cyber.Networking.Messages {
public override void Deserialize(NetworkReader reader) { public override void Deserialize(NetworkReader reader) {
InteractSyncBaseID = reader.ReadInt32(); InteractSyncBaseID = reader.ReadInt32();
OwnerSyncBaseID = reader.ReadInt32(); OwnerSyncBaseID = reader.ReadInt32();
InteractionType = (InteractionType) reader.ReadByte();
} }
/// <summary> /// <summary>
@ -47,6 +56,7 @@ namespace Cyber.Networking.Messages {
public override void Serialize(NetworkWriter writer) { public override void Serialize(NetworkWriter writer) {
writer.Write(InteractSyncBaseID); writer.Write(InteractSyncBaseID);
writer.Write(OwnerSyncBaseID); writer.Write(OwnerSyncBaseID);
writer.Write((byte) InteractionType);
} }
} }

View File

@ -44,6 +44,10 @@ namespace Cyber.Networking.Serverside {
// Disregard the package, it's too old. // Disregard the package, it's too old.
} }
/// <summary>
/// Clears the 'LastSyncIDReceived' from the given connection id, making sure that any new connections re-using this connectionID will be properly synced.
/// </summary>
/// <param name="connectionID">The connectionID to be cleared.</param>
public void ClearConnectionFromSyncDict(int connectionID) { public void ClearConnectionFromSyncDict(int connectionID) {
LastSyncIDReceived.Remove(connectionID); LastSyncIDReceived.Remove(connectionID);
} }