示例#1
0
        /// <summary>Needs to be called by the entity in order to be registered</summary>
        /// <param name="e">The entity to register</param>
        public void RegisterEntity(Entity e)
        {
            List <uint> keys = new List <uint>(Server.entities.Keys);
            //Get first free ID
            uint i;

            for (i = 0; i < keys.Count + 1; i++)
            {
                if (!keys.Contains(i))
                {
                    break;
                }
            }
            //Send an EntitySpawn packet to all
            e.id = i;
            ServerSend.SpawnEntity(e);

            //Add it to the server registry
            Server.entities.Add(i, e);
        }
示例#2
0
        public static void Stop()
        {
            foreach (Client c in clients.Values)
            {
                ServerSend.PlayerDisconnected(c.id);
            }
            clients.Clear();
            foreach (Entity e in entities.Values)
            {
                GameObject.Destroy(e.gameObject);
            }
            entities.Clear();

            if (tcpListener != null)
            {
                tcpListener.Stop();
            }
            if (udpListener != null)
            {
                udpListener.Close();
            }
        }
示例#3
0
        /// <summary>Calculates the player's desired movement direction and moves him.</summary>
        /// <param name="inputDirection"></param>
        private void Move(Vector2 inputDirection)
        {
            Vector3 moveDirection = transform.right * inputDirection.x + transform.forward * inputDirection.y;

            moveDirection *= moveSpeed;

            if (controller.isGrounded)
            {
                yVelocity = 0f;
                if (inputs[4])
                {
                    yVelocity = jumpSpeed;
                }
            }
            yVelocity += gravity;

            moveDirection.y = yVelocity;
            controller.Move(moveDirection);

            ServerSend.PlayerPosition(this);
            ServerSend.PlayerRotation(this);
        }
示例#4
0
 /// <summary>Messages the client entity (basically calls a function by name)</summary>
 /// <param name="msg">The name of the function to call</param>
 /// <param name="args">Arguments to pass on to the function</param>
 public virtual void Message(string msg, object args = null)
 {
     ServerSend.MessageEntity(this, msg, args);
 }
示例#5
0
 /// <summary>Sends all the entity data to the client</summary>
 public virtual void Send()
 {
     ServerSend.UpdateEntity(this);
 }