コード例 #1
0
    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);
    }
コード例 #2
0
    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);
    }
コード例 #3
0
ファイル: KS_SaveLoad.cs プロジェクト: luodongfu/ks-framework
        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);
            }
        }
コード例 #4
0
    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);
    }
コード例 #5
0
        /// <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;
        }
コード例 #6
0
    public static QuaternionSurrogate ConvertFromQuaternion(Quaternion quaternion)
    {
        QuaternionSurrogate surrogate = new QuaternionSurrogate();

        surrogate.x = quaternion.x;
        surrogate.y = quaternion.y;
        surrogate.z = quaternion.z;
        surrogate.w = quaternion.w;

        return(surrogate);
    }
コード例 #7
0
        public static BinaryFormatter GetBinaryFormatter()
        {
            BinaryFormatter               formatter           = new BinaryFormatter();
            SurrogateSelector             selector            = new SurrogateSelector();
            Vector3SerializationSurrogate vector3Surrogate    = new Vector3SerializationSurrogate();
            QuaternionSurrogate           quaternionSurrogate = new QuaternionSurrogate();

            selector.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), vector3Surrogate);
            selector.AddSurrogate(typeof(Quaternion), new StreamingContext(StreamingContextStates.All), quaternionSurrogate);
            formatter.SurrogateSelector = selector;
            return(formatter);
        }
コード例 #8
0
        /// <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;
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
 /// <summary>
 /// Converts a provided <see cref="Quaternion"/> to the network surrogate.
 /// </summary>
 /// <param name="quat"></param>
 /// <returns></returns>
 public static Quaternion ToQuaternion(this QuaternionSurrogate quat)
 {
     //Just map the Quaternion to the surrogate
     return(new Quaternion(quat.X, quat.Y, quat.Z, quat.W));
 }
コード例 #11
0
 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;
 }
コード例 #12
0
 public PlayerEntitySpawnEventPayload(NetworkEntityGuid entityGuid, Vector3Surrogate position, QuaternionSurrogate rotation)
     : base(entityGuid, position, rotation)
 {
     //Nothing at the moment. Can extend for future use.
 }