public override GameData Save(GameData gameData, int id) { PlayerData playerData = new PlayerData(); playerData.health = health; playerData.armor = armor; playerData.grenades = grenadeCount; playerData.weaponIndex = switchController.currentWeaponIndex; playerData.crouched = crouched; playerData.clips = new int[ammoClips.Length]; playerData.ammo = new int[weapons.Length]; playerData.weaponLocks = new bool[weapons.Length]; for (int i = 0; i < weapons.Length; i++) { playerData.clips[i] = ammoClips[i]; playerData.ammo[i] = weapons[i].ammoPool; playerData.weaponLocks[i] = weapons[i].locked; } // Positioning playerData.position = Vector3Surrogate.ConvertFromVector3(transform.position); playerData.rotation = Vector3Surrogate.ConvertFromVector3(_rotation); playerData.camRotation = Vector3Surrogate.ConvertFromVector3(cam.transform.localEulerAngles); playerData.velocity = Vector3Surrogate.ConvertFromVector3(velocity); gameData.SetPlayerData(playerData); return(gameData); }
private static void AddSurrogates(ref SurrogateSelector ss) { Vector2Surrogate Vector2_SS = new Vector2Surrogate(); ss.AddSurrogate(typeof(Vector2), new StreamingContext(StreamingContextStates.All), Vector2_SS); Vector3Surrogate Vector3_SS = new Vector3Surrogate(); ss.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), Vector3_SS); Vector4Surrogate Vector4_SS = new Vector4Surrogate(); ss.AddSurrogate(typeof(Vector4), new StreamingContext(StreamingContextStates.All), Vector4_SS); ColorSurrogate Color_SS = new ColorSurrogate(); ss.AddSurrogate(typeof(Color), new StreamingContext(StreamingContextStates.All), Color_SS); QuaternionSurrogate Quaternion_SS = new QuaternionSurrogate(); ss.AddSurrogate(typeof(Quaternion), new StreamingContext(StreamingContextStates.All), Quaternion_SS); }
private static void AddSurrogates(ref SurrogateSelector ss) { Vector3Surrogate Vector3_SS = new Vector3Surrogate(); ss.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), Vector3_SS); Texture2DSurrogate Texture2D_SS = new Texture2DSurrogate(); ss.AddSurrogate(typeof(Texture2D), new StreamingContext(StreamingContextStates.All), Texture2D_SS); ColorSurrogate Color_SS = new ColorSurrogate(); ss.AddSurrogate(typeof(Color), new StreamingContext(StreamingContextStates.All), Color_SS); GameObjectSurrogate GameObject_SS = new GameObjectSurrogate(); ss.AddSurrogate(typeof(GameObject), new StreamingContext(StreamingContextStates.All), GameObject_SS); TransformSurrogate Transform_SS = new TransformSurrogate(); ss.AddSurrogate(typeof(Transform), new StreamingContext(StreamingContextStates.All), Transform_SS); QuaternionSurrogate Quaternion_SS = new QuaternionSurrogate(); ss.AddSurrogate(typeof(Quaternion), new StreamingContext(StreamingContextStates.All), Quaternion_SS); }
/// <summary> /// Creates a new <see cref="BoomaPayloadMessageType.PlayerMoveRequestPayload"/> payload. /// </summary> public PlayerMoveRequestPayload(Vector3Surrogate position, float timeStamp) { //TODO: Check refs Position = position; TimeSinceStart = timeStamp; }
private static void AddSurrogates(ref SurrogateSelector ss) { Vector3Surrogate vector = new Vector3Surrogate(); ss.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), vector); QuaternionSurrogate quaternion = new QuaternionSurrogate(); ss.AddSurrogate(typeof(Quaternion), new StreamingContext(StreamingContextStates.All), quaternion); TransformSurrogate transform = new TransformSurrogate(); ss.AddSurrogate(typeof(Transform), new StreamingContext(StreamingContextStates.All), transform); ColourSurrogate colour = new ColourSurrogate(); ss.AddSurrogate(typeof(Color), new StreamingContext(StreamingContextStates.All), colour); CameraSurrogate camera = new CameraSurrogate(); ss.AddSurrogate(typeof(Camera), new StreamingContext(StreamingContextStates.All), camera); foreach (KeyValuePair <ISerializationSurrogate, Type> kv in surrogateList) { ss.AddSurrogate(kv.Value, new StreamingContext(StreamingContextStates.All), kv.Key); } }
public static bool GetSurrogate(ref object surrogate) { Type objType = surrogate.GetType(); switch (objType.ToString()) { case "UnityEngine.Vector3": surrogate = Vector3Surrogate.GetSurrogateObject((Vector3)surrogate); break; case "UnityEngine.Vector4": surrogate = Vector4Surrogate.GetSurrogateObject((Vector4)surrogate); break; case "UnityEngine.Vector2": surrogate = Vector2Surrogate.GetSurrogateObject((Vector2)surrogate); break; case "UnityEngine.Quaternion": surrogate = QuaternionSurrogate.GetSurrogateObject((Quaternion)surrogate); break; default: return(false); } return(true); }
public EntityPositionUpdateEvent(Vector3Surrogate position, NetworkEntityGuid entityGuid, float timeStamp) { //TODO: Check refs //TODO: Verify args EntityGuid = entityGuid; Position = position; CurrentTimeStamp = timeStamp; }
/// <summary> /// Creates a new <see cref="BoomaPayloadMessageType.PlayerSpawnResponse"/> payload. /// </summary> public PlayerSpawnResponsePayload(PlayerSpawnResponseCode code, Vector3Surrogate position, QuaternionSurrogate rotation, NetworkEntityGuid entityGuid) { //TODO: Check refs ResponseCode = code; EntityGuid = entityGuid; Position = position; Rotation = rotation; }
public GameObjectEntitySpawnEventPayload(NetworkEntityGuid entityGuid, Vector3Surrogate position, QuaternionSurrogate rotation, Vector3Surrogate scale, GameObjectPrefab prefabId, byte state) : base(entityGuid, position, rotation) { //TODO: Check values/refs Scale = scale; PrefabId = prefabId; CurrentState = state; }
public static Vector3Surrogate ConvertFromVector3(Vector3 vector3) { Vector3Surrogate surrogate = new Vector3Surrogate(); surrogate.x = vector3.x; surrogate.y = vector3.y; surrogate.z = vector3.z; return(surrogate); }
public override GameData Save(GameData gameData, int id) { ProjectileData projectileData = new ProjectileData(); projectileData.id = id; projectileData.position = Vector3Surrogate.ConvertFromVector3(transform.position); projectileData.rotation = Vector3Surrogate.ConvertFromVector3(transform.rotation.eulerAngles); gameData.projectileData.Add(projectileData); return(gameData); }
public override GameData Save(GameData gameData, int id) { AICharacterData aICharacterData = new AICharacterData(); aICharacterData.id = id; aICharacterData.position = Vector3Surrogate.ConvertFromVector3(transform.position); aICharacterData.rotation = Vector3Surrogate.ConvertFromVector3(transform.rotation.eulerAngles); aICharacterData.health = health; gameData.aICharacterData.Add(aICharacterData); return(gameData); }
/// <summary> /// Creates a new payload for the <see cref="BoomaPayloadMessageType.EntitySpawnEvent"/> packet. /// </summary> /// <param name="entityGuid">The entity's GUID.</param> /// <param name="position">Position of the entity.</param> /// <param name="rotation">Rotation of the entity.</param> public EntitySpawnEventPayload(NetworkEntityGuid entityGuid, Vector3Surrogate position, QuaternionSurrogate rotation) { if (position == null) { throw new ArgumentNullException(nameof(position), $"Provided {nameof(Vector3Surrogate)} must not be null."); } if (rotation == null) { throw new ArgumentNullException(nameof(rotation), $"Provided {nameof(QuaternionSurrogate)} must not be null."); } EntityGuid = entityGuid; Position = position; Rotation = rotation; }
protected override void OnIncomingHandlableMessage(IRequestMessage message, PlayerSpawnRequestPayload payload, IMessageParameters parameters, InstanceClientSession peer) { //TODO: Right now we don't have a full handshake for entering an instance. So we need to make up a GUID for the entering player //Important to check if we've actually already created an entity for this connection //We don't have that implemenented though for the demo //rely on the factory implementation to handle placement details such as position and rotation NetworkEntityGuid guid = entityGuidFactory.Create(EntityType.Player); IEntitySpawnResults details = playerEntityFactory.SpawnPlayerEntity(new NetworkPlayerSpawnContext(guid, peer)); if (details.Result != SpawnResult.Success) { throw new InvalidOperationException($"Failed to create Entity for {peer.ToString()}. Failure: {details.Result.ToString()}"); } //TODO: This is temporary stuff for demo entityCollection.Add(guid, new EntityContainer(guid, details.EntityGameObject)); peerCollection.Add(peer); connectionRegistry.Register(peer.PeerDetails.ConnectionID, guid); //TODO: Clean this up Vector3Surrogate pos = details.EntityGameObject.transform.position.ToSurrogate(); QuaternionSurrogate rot = details.EntityGameObject.transform.rotation.ToSurrogate(); //Send the response to the player who requested to spawn peer.SendResponse(new PlayerSpawnResponsePayload(PlayerSpawnResponseCode.Success, pos, rot, guid), DeliveryMethod.ReliableUnordered, true, 0); //TODO: Remove this. This is demo code. foreach (var entity in entityCollection.Values.Where(e => e.NetworkGuid.EntityType == EntityType.GameObject)) { ITagProvider <GameObjectPrefab> prefabTag = entity.WorldObject.GetComponent <ITagProvider <GameObjectPrefab> >(); IEntityStateContainer state = entity.WorldObject.GetComponentInChildren <IEntityStateContainer>(); peer.SendEvent(new GameObjectEntitySpawnEventPayload(entity.NetworkGuid, entity.WorldObject.transform.position.ToSurrogate(), entity.WorldObject.transform.rotation.ToSurrogate(), entity.WorldObject.transform.localScale.ToSurrogate(), prefabTag.Tag, state.State), DeliveryMethod.ReliableOrdered, false, 0); } }
/// <summary> /// Converts a provided <see cref="Vector3"/> to the network surrogate. /// </summary> /// <param name="vector"></param> /// <returns></returns> public static Vector3 ToVector3(this Vector3Surrogate vector) { //Just map the vector3 to the surrogate return(new Vector3(vector.X, vector.Y, vector.Z)); }
public PlayerEntitySpawnEventPayload(NetworkEntityGuid entityGuid, Vector3Surrogate position, QuaternionSurrogate rotation) : base(entityGuid, position, rotation) { //Nothing at the moment. Can extend for future use. }