Ejemplo n.º 1
0
        // this is a little hacky as there aren't actually any entities to process
        // probably a sign that I'm abusing the entity component system. i think the proper
        // way to do this is to create a simple entity that just has a component to hold
        // a reference to the network agent. that's roughly how it would work in unity.
        // might be best to use a TagSystem like for player input?
        protected override void ProcessEntities(IDictionary <int, Entity> entities)
        {
            List <NetIncomingMessage> messages = _networkAgent.ReadMessages();

            foreach (NetIncomingMessage netMessage in messages)
            {
                NetworkMessageType messageType = (NetworkMessageType)Enum.ToObject(typeof(NetworkMessageType), netMessage.ReadByte());

                if (messageType == NetworkMessageType.PlayerConnect)
                {
                    PlayerConnectMessage <UmbraEntityType> playerConnectMessage = new PlayerConnectMessage <UmbraEntityType>();
                    playerConnectMessage.Decode(netMessage);
                    PlayerConnect(playerConnectMessage);
                }
                else if (messageType == NetworkMessageType.EntityAdd)
                {
                    EntityAddMessage <UmbraEntityType> addMessage = new EntityAddMessage <UmbraEntityType>();
                    addMessage.Decode(netMessage);
                    AddEntity(addMessage);
                }
                else if (messageType == NetworkMessageType.EntityMove)
                {
                    EntityMoveMessage moveMessage = new EntityMoveMessage();
                    moveMessage.Decode(netMessage);
                    MoveEntity(moveMessage);
                }
                else if (messageType == NetworkMessageType.EntityRemove)
                {
                    EntityRemoveMessage removeMessage = new EntityRemoveMessage();
                    removeMessage.Decode(netMessage);
                    RemoveEntity(removeMessage);
                }
            }
        }
Ejemplo n.º 2
0
        private void MoveEntity(EntityMoveMessage msg)
        {
            Entity entity = CrawEntityManager.Instance.GetEntity(msg.EntityId);

            if (entity != null && entity.Tag != "PLAYER")
            {
                TransformComponent transform = entity.GetComponent <TransformComponent>();
                transform.Position = msg.Position;
            }
        }
Ejemplo n.º 3
0
        private void MoveEntity(EntityMoveMessage msg)
        {
            Entity          entity     = CrawEntityManager.Instance.GetEntity(msg.EntityId);
            UmbraEntityType entityType = entity.GetComponent <UmbraEntityTypeComponent>().EntityType;

            if (entityType == UmbraEntityType.Player)
            {
                TransformComponent transform = entity.GetComponent <TransformComponent>();
                transform.Position = msg.Position;
            }
        }
Ejemplo n.º 4
0
        // this is a little hacky as there aren't actually any entities to process
        // probably a sign that I'm abusing the entity component system. i think the proper
        // way to do this is to create a simple entity that just has a component to hold
        // a reference to the network agent. that's roughly how it would work in unity.
        // might be best to use a TagSystem like for player input?
        protected override void ProcessEntities(IDictionary <int, Entity> entities)
        {
            List <NetIncomingMessage> messages = _networkAgent.ReadMessages();

            foreach (NetIncomingMessage netMessage in messages)
            {
                NetworkMessageType messageType = (NetworkMessageType)Enum.ToObject(typeof(NetworkMessageType), netMessage.ReadByte());

                Console.WriteLine(messageType);

                if (messageType == NetworkMessageType.EntityMove)
                {
                    EntityMoveMessage moveMessage = new EntityMoveMessage();
                    moveMessage.Decode(netMessage);
                    MoveEntity(moveMessage);
                }
            }
        }