コード例 #1
0
        public override void OnDeserialize(byte[] buffer, int index)
        {
            // object id
            uint objectId;

            Serializer.DeserializeData(buffer, ref index, out objectId);
            GameObjectId = objectId;

            // object type
            EObjectType type = (EObjectType)((int)buffer[index]);

            index++;

            bool isLocalPlayer = false;

            Serializer.DeserializeData(buffer, ref index, out isLocalPlayer);
            IsLocalPlayer = isLocalPlayer;

            // player linked id
            uint playerId = 0;

            Serializer.DeserializeData(buffer, ref index, out playerId);
            PlayerLinked = playerId;

            // Deserialize components
            byte componentsNumber = buffer[index];

            index++;

            for (int i = 0; i < componentsNumber; i++)
            {
                ISerializableComponent tmpComponent = GameComponentFactory.DeserializeComponent(buffer, ref index);
                Components.Add(tmpComponent);
            }
        }
コード例 #2
0
        public static ISerializableComponent DeserializeComponent(byte[] buffer, ref int index)
        {
            ISerializableComponent component = null;

            byte tmpType = buffer[index + sizeof(uint)]; // we know that the type is after the id

            switch ((EComponentType)tmpType)
            {
            case EComponentType.HealthComponent:
                component = new DeusSerializableTimelineComponent <int>();
                break;

            case EComponentType.PositionComponent:
                component = new DeusSerializableTimelineComponent <DeusVector2>();
                break;

            case EComponentType.SkillComponent:
                component = new DeusSerializableTimelineComponent <SkillInfos>();
                break;

            default:
                throw new Exception("Impossible to instantiate the serializable component");
            }

            component.Deserialize(buffer, ref index);

            return(component);
        }
コード例 #3
0
ファイル: Message.cs プロジェクト: SpenQ/Prototype
 /// <summary>
 /// Choose the right payload object according to the command
 /// </summary>
 private void DeserializePayloadObject()
 {
     // todo map the commands to the types somehow..
     using (MemoryStream ms = new MemoryStream(_payloadByteArray, false))
         using (BinaryReader br = new BinaryReader(ms, Encoding.UTF8))
         {
             // Deserializing the appropriate payload object
             if (Command == NetworkCommand.Version.ToString())
             {
                 Payload = new VersionPayload();
                 Payload.Deserialize(br);
             }
             else if (Command == NetworkCommand.Addr.ToString())
             {
                 Payload = new AddrPayload();
                 Payload.Deserialize(br);
             }
             else if (Command == NetworkCommand.GetHeaders.ToString())
             {
                 Payload = new GetHeadersPayload();
                 Payload.Deserialize(br);
             }
             else if (Command == NetworkCommand.Headers.ToString())
             {
                 Payload = new HeadersPayload();
                 Payload.Deserialize(br);
             }
             else if (Command == NetworkCommand.GetBlocks.ToString())
             {
                 Payload = new GetBlocksPayload();
                 Payload.Deserialize(br);
             }
             else if (Command == NetworkCommand.Blocks.ToString())
             {
                 Payload = new StateBlocksPayload();
                 Payload.Deserialize(br);
             }
             else if (Command == NetworkCommand.NewBlock.ToString())
             {
                 Payload = new SingleStateBlockPayload();
                 Payload.Deserialize(br);
             }
             else if (Command == NetworkCommand.NewTransaction.ToString())
             {
                 Payload = new SingleStateTransactionPayload();
                 Payload.Deserialize(br);
             }
             else if (Command == NetworkCommand.TxPool.ToString())
             {
                 Payload = new StateTransactionsPayload();
                 Payload.Deserialize(br);
             }
             else if (Command != NetworkCommand.VerAck.ToString() && Command != NetworkCommand.GetAddr.ToString() &&
                      Command != NetworkCommand.CloseConn.ToString() && Command != NetworkCommand.NotFound.ToString() &&
                      Command != NetworkCommand.GetTxPool.ToString()) // No payloads for these ones
             {
                 throw new ArgumentException("Unknown command, cannot deserialize Payload");
             }
         }
 }
コード例 #4
0
        /// <summary>
        /// This method instantiates a game object with the required components and applies this data object to the component.
        /// </summary>
        /// <param name="defaults">References to the prefabs.</param>
        /// <returns></returns>
        internal ISerializableComponent Deserialize(DefaultReferences defaults)
        {
            ISerializableComponent serializableComponent = InstantiateComponent(defaults);

            serializableComponent.ApplyData(this);
            return(serializableComponent);
        }
コード例 #5
0
        public IEnumerator SetUpScene()
        {
            yield return(SceneManager.LoadSceneAsync("CommandTestScene", LoadSceneMode.Single));

            this.StrokeSketchObject       = GameObject.FindObjectOfType <StrokeSketchObject>();
            this.SerializableSketchObject = this.StrokeSketchObject;
            yield return(null);
        }
コード例 #6
0
        public virtual void SendSerializedComponent(ISerializableComponent comp, DeliveryMethod deliveryMethod)
        {
            NetDataWriter.Reset();
            NetDataWriter.Put((byte)PacketType.SerializedComponent);
            comp.Serialize(NetDataWriter);

            SendRaw(NetDataWriter.Data, deliveryMethod);
        }
コード例 #7
0
        public virtual void SendSerializedComponent(ISerializableComponent comp, DeliveryMethod deliveryMethod)
        {
            NetDataWriter.Reset();
            NetDataWriter.Put((byte)PacketType.SerializedComponent);
            comp.Serialize(NetDataWriter);

            foreach (var key in ServerNetworkEntities.Keys)
            {
                SendRaw(ServerNetworkEntities[key].Peer, NetDataWriter.Data, deliveryMethod);
            }
        }
コード例 #8
0
        internal override ISerializableComponent InstantiateComponent(DefaultReferences defaults)
        {
            ISerializableComponent serializableComponent = null;

            if (Interpolation == InterpolationType.Cubic)
            {
                serializableComponent = GameObject.Instantiate(defaults.StrokeSketchObjectPrefab).GetComponent <ISerializableComponent>();
            }
            else if (Interpolation == InterpolationType.Linear)
            {
                serializableComponent = GameObject.Instantiate(defaults.LinearInterpolationStrokeSketchObjectPrefab).GetComponent <ISerializableComponent>();
            }
            return(serializableComponent);
        }
コード例 #9
0
ファイル: Message.cs プロジェクト: SpenQ/Prototype
 internal Message(string command, ISerializableComponent payload)
 {
     if (payload == null)
     {
         Payload           = null;
         _payloadByteArray = new byte[0];
     }
     else
     {
         Payload           = payload;
         _payloadByteArray = payload.ToByteArray();
     }
     Command  = command;
     Checksum = GetChecksum(_payloadByteArray);
 }
コード例 #10
0
        //private static DeusSerializableComponent CreatePositionSerializableComponent()
        //{
        //    return null;
        //}

        public static DeusComponent CreateComponent(ISerializableComponent args, uint gameObjectId)
        {
            switch (args.ComponentType)
            {
            case EComponentType.HealthComponent:
                return(new HealthTimeLineComponent(args.ComponentId, gameObjectId, (args as DeusSerializableTimelineComponent <int>).Origin, (args as DeusSerializableTimelineComponent <int>).Destination));

            case EComponentType.PositionComponent:
                return(new PositionTimeLineComponent(args.ComponentId, gameObjectId, (args as DeusSerializableTimelineComponent <DeusVector2>).Origin, (args as DeusSerializableTimelineComponent <DeusVector2>).Destination));

            case EComponentType.SkillComponent:
                return(new SkillTimeLineComponent(args.ComponentId, gameObjectId, (args as DeusSerializableTimelineComponent <SkillInfos>).Origin, (args as DeusSerializableTimelineComponent <SkillInfos>).Destination));

            default:
                return(null);
            }
        }
コード例 #11
0
        /// <summary>
        /// Helper method to reduce duplicate LOC
        /// </summary>
        /// <param name="node">The node to send the message to</param>
        /// <param name="command">The command</param>
        /// <param name="payload">The payload that corresponds with the command</param>
        public async Task SendMessageToNode(NetworkNode node, NetworkCommand command, ISerializableComponent payload)
        {
            IPEndPoint endpoint = node.DirectEndpoint ?? node.ListenEndpoint;
            var        msg      = new Message(command.ToString(), payload);
            await node.SendMessageAsync(msg);

            _logger.LogDebug("Sent {0} message to node {1} on port {2}", command.ToString(), endpoint.Address.ToString(), endpoint.Port);
        }
コード例 #12
0
ファイル: BaseRequest.cs プロジェクト: adearriba/Zeleris.NET
 public BaseRequest(IComponentSerializer serializaer, string rootName = "BODY")
 {
     _serializer = serializaer;
     _root       = new CompositeComponent(rootName);
 }