Esempio n. 1
0
 // Start is called before the first frame update
 void Start()
 {
     attrManager  = GetComponent <AttributesManager>();
     networkInput = GetComponent <NetworkInput>();
     backpack     = new Backpack(gameObject, backpackSize);
     PickUpEvent += OnPickUp;
 }
Esempio n. 2
0
        protected NetworkInterface(UDPConnection udpConnection, Logger logger)
        {
            Logger = logger;

            ClientConnections = new NetworkConnectionPool();
            In  = new NetworkInput(ClientConnections);
            Out = new NetworkOutput(ClientConnections);

            ErrorHandling = new NetworkErrorHandling(ClientConnections, this);

            UdpConnection                 = udpConnection;
            UdpConnection.Logger          = logger;
            UdpConnection.OnReceiveError += ErrorHandling.HandleUDPReceiveError;
            UdpConnection.OnSendError    += ErrorHandling.HandleUDPSendError;
            UdpConnection.InitializeReceiving();

            KeepAliveInterval = 1000;
            m_keepAlive       = true;

            HolePunchingInterval = 1000;
            m_holePunching       = false;

            Thread keepAliveThread = new Thread(KeepAliveLoop);

            keepAliveThread.Name = "Keep alive";
            keepAliveThread.Start();
        }
Esempio n. 3
0
 public ActivityBase(GameObject ownerGO, ActivityBaseInfo activityInfo)
 {
     this.ownerGO      = ownerGO;
     activityManager   = ownerGO.GetComponent <ActivityManager>();
     animator          = ownerGO.GetComponent <Animator>();
     networkInput      = ownerGO.GetComponent <NetworkInput>();
     this.activityInfo = activityInfo;
 }
Esempio n. 4
0
        public Enemy(Game game, ContentManager content, NetworkInput service)
            : base(game)
        {
            this.DrawOrder = 2;
            this.service = service;
            this.content = content;

            service.EnemyShot += new Action<Info>(EnemyShot);
        }
        private void MovePlayer(Connection connection)
        {
            Rigidbody rb = _connectionToRigidbody[connection];
            float     horizontalInput = 0;
            float     verticalInput   = 0;

            if (NetworkInput.GetKey(connection, Keys.MoveLeft))
            {
                horizontalInput = -1;
            }
            if (NetworkInput.GetKey(connection, Keys.MoveRight))
            {
                horizontalInput = 1;
            }
            if (NetworkInput.GetKey(connection, Keys.MoveForward))
            {
                verticalInput = 1;
            }
            if (NetworkInput.GetKey(connection, Keys.MoveBackward))
            {
                verticalInput = -1;
            }

            rb.AddForce(new Vector3(horizontalInput * setup.moveInputIntensity, 0, verticalInput * setup.moveInputIntensity));

            if (NetworkInput.GetKey(connection, Keys.Pull))
            {
                Vector3    pos          = new Vector3(rb.transform.position.x, -1, rb.transform.position.z);
                Collider[] hitColliders = Physics.OverlapSphere(pos, 5);
                int        i            = 0;
                while (i < hitColliders.Length)
                {
                    Rigidbody colliderRb = hitColliders[i].GetComponent <Rigidbody>();
                    if (colliderRb != null && colliderRb != rb)
                    {
                        colliderRb.AddExplosionForce(50f, pos, 5f);
                    }
                    i++;
                }
            }
            if (NetworkInput.GetKey(connection, Keys.Push))
            {
                Vector3    pos          = new Vector3(rb.transform.position.x, -1, rb.transform.position.z);
                Collider[] hitColliders = Physics.OverlapSphere(pos, 5);
                int        i            = 0;
                while (i < hitColliders.Length)
                {
                    Rigidbody colliderRb = hitColliders[i].GetComponent <Rigidbody>();
                    if (colliderRb != null && colliderRb != rb)
                    {
                        colliderRb.AddForce((rb.transform.position - hitColliders[i].transform.position) * 10f);
                    }
                    i++;
                }
            }
        }
Esempio n. 6
0
 void Awake()
 {
     if (_instance == null)
     {
         _instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
Esempio n. 7
0
 public void testPostion()
 {
     CDTIPlane plane = new CDTIPlane();
     plane.Position = new Vector(5, 5, 0);
     NetworkInput toTest = new NetworkInput();
     Assert.That(1.25 == toTest.figurePositon(plane).x, "got: " + toTest.figurePositon(plane).x);
     Assert.That(1.25== toTest.figurePositon(plane).y, "got: " + toTest.figurePositon(plane).y);
     toTest.zoomIn();
     Assert.That(1.5625 == toTest.figurePositon(plane).x, "got: " + toTest.figurePositon(plane).x);
     Assert.That(1.5625 == toTest.figurePositon(plane).y, "got: " + toTest.figurePositon(plane).y);
     toTest.zoomOut();
     toTest.zoomOut();
     Assert.That(1.041667 == toTest.figurePositon(plane).x, "got: " + toTest.figurePositon(plane).x);
     Assert.That(1.041667 == toTest.figurePositon(plane).y, "got: " + toTest.figurePositon(plane).y);
 }
Esempio n. 8
0
    public void testPostion()
    {
        CDTIPlane plane = new CDTIPlane();

        plane.Position = new Vector(5, 5, 0);
        NetworkInput toTest = new NetworkInput();

        Assert.That(1.25 == toTest.figurePositon(plane).x, "got: " + toTest.figurePositon(plane).x);
        Assert.That(1.25 == toTest.figurePositon(plane).y, "got: " + toTest.figurePositon(plane).y);
        toTest.zoomIn();
        Assert.That(1.5625 == toTest.figurePositon(plane).x, "got: " + toTest.figurePositon(plane).x);
        Assert.That(1.5625 == toTest.figurePositon(plane).y, "got: " + toTest.figurePositon(plane).y);
        toTest.zoomOut();
        toTest.zoomOut();
        Assert.That(1.041667 == toTest.figurePositon(plane).x, "got: " + toTest.figurePositon(plane).x);
        Assert.That(1.041667 == toTest.figurePositon(plane).y, "got: " + toTest.figurePositon(plane).y);
    }
Esempio n. 9
0
 public void testRotation()
 {
     CDTIPlane plane = new CDTIPlane();
     plane.Velocity = new Vector(1, 0, 0);
     NetworkInput toTest = new NetworkInput();
     Assert.That(Quaternion.AngleAxis(-90, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
     plane.Velocity = new Vector(1, 1, 0);
     Assert.That(Quaternion.AngleAxis(-45, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
     plane.Velocity = new Vector(0, 1, 0);
     Assert.That(Quaternion.AngleAxis(0, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
     plane.Velocity = new Vector(-1, 1, 0);
     Assert.That(Quaternion.AngleAxis(45, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
     plane.Velocity = new Vector(-1, 0, 0);
     Assert.That(Quaternion.AngleAxis(90, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
     plane.Velocity = new Vector(-1, -1, 0);
     Assert.That(Quaternion.AngleAxis(135, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
     plane.Velocity = new Vector(0, -1, 0);
     Assert.That(Quaternion.AngleAxis(180, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
     plane.Velocity = new Vector(1, -1, 0);
     Assert.That(Quaternion.AngleAxis(225, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
 }
Esempio n. 10
0
        public void Learn(ref ActivationNetwork network, double[] crossInput, double[] circleInput, double[] blankInput)
        {
            NetworkInput networkInput = new NetworkInput(crossInput, circleInput, blankInput);

            double[][] input = networkInput.Input;

            NetworkOutput networkOutput = new NetworkOutput(0);

            double[][] output = networkOutput.Output;

            BackPropagationLearning teacher =
                new BackPropagationLearning(network);

            for (int i = 0; i < 100000; i++)
            {
                double error = teacher.RunEpoch(input, output);
            }

            network.Save("Net.bin");
            MessageBox.Show("Learning finished");
        }
Esempio n. 11
0
    public void testRotation()
    {
        CDTIPlane plane = new CDTIPlane();

        plane.Velocity = new Vector(1, 0, 0);
        NetworkInput toTest = new NetworkInput();

        Assert.That(Quaternion.AngleAxis(-90, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
        plane.Velocity = new Vector(1, 1, 0);
        Assert.That(Quaternion.AngleAxis(-45, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
        plane.Velocity = new Vector(0, 1, 0);
        Assert.That(Quaternion.AngleAxis(0, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
        plane.Velocity = new Vector(-1, 1, 0);
        Assert.That(Quaternion.AngleAxis(45, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
        plane.Velocity = new Vector(-1, 0, 0);
        Assert.That(Quaternion.AngleAxis(90, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
        plane.Velocity = new Vector(-1, -1, 0);
        Assert.That(Quaternion.AngleAxis(135, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
        plane.Velocity = new Vector(0, -1, 0);
        Assert.That(Quaternion.AngleAxis(180, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
        plane.Velocity = new Vector(1, -1, 0);
        Assert.That(Quaternion.AngleAxis(225, new Vector3(0, 0, 1)).Equals(toTest.figureRotation(plane)));
    }
Esempio n. 12
0
 public void OnInput(NetworkRunner runner, NetworkInput input)
 {
     //if (SceneManager.GetActiveScene().buildIndex < 1) return;
     //if (!PlayerManager.In.LocalPlayer) return;
 }
Esempio n. 13
0
 /// <summary>
 /// 入力情報
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public async Task InputAsync(GameInputRequest request)
 {
     NetworkInput.SetCurrentCommand(request.Command);
     await Task.Yield();
 }
Esempio n. 14
0
 void Awake()
 {
     anim         = GetComponent <Animator>();
     networkInput = GameObject.Find("Supat Face").GetComponent <NetworkInput>();
 }
Esempio n. 15
0
 public void OnInput(NetworkRunner runner, NetworkInput input)
 {
 }
Esempio n. 16
0
    void Update()
    {
        //setup code to get initial rotation
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            got_first = false;
        }

        //Used to time the robot, how long it took to reach the destination
        if (isTimer)
        {
            timeForTable += Time.deltaTime;
        }


        /*
         * Following code takes in Inputs WASD from user and moves the robot depending on the input.
         * W: Forward movement
         * S: Backward movement
         * A: Left rotation
         * D: Right rotation
         */
        if (Input.GetKey(KeyCode.W))
        {
            controllerValue1 = maxSpeed;
            controllerValue2 = maxSpeed;
            controllerValue3 = maxSpeed;
            controllerValue4 = maxSpeed;

            this.transform.position += transform.forward * moveSpeed * Time.deltaTime;
        }
        else if (Input.GetKey(KeyCode.S))
        {
            controllerValue1 = -maxSpeed;
            controllerValue2 = -maxSpeed;
            controllerValue3 = -maxSpeed;
            controllerValue4 = -maxSpeed;

            this.transform.position -= transform.forward * moveSpeed * Time.deltaTime;
        }
        else if (Input.GetKey(KeyCode.A))
        {
            controllerValue1 = -maxSpeed;
            controllerValue2 = maxSpeed;
            controllerValue3 = -maxSpeed;
            controllerValue4 = maxSpeed;

            if (simulate_rotate)
            {
                this.transform.Rotate(-Vector3.up * rotateSpeed * Time.deltaTime);
            }
        }
        else if (Input.GetKey(KeyCode.D))
        {
            controllerValue1 = maxSpeed;
            controllerValue2 = -maxSpeed;
            controllerValue3 = maxSpeed;
            controllerValue4 = -maxSpeed;

            if (simulate_rotate)
            {
                this.transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime);
            }
        }
        else
        {
            controllerValue1 = 0f;
            controllerValue2 = 0f;
            controllerValue3 = 0f;
            controllerValue4 = 0f;
        }

        /*
         * Following code takes in Inputs WASD from AI &moves the robot depending on the input.
         * W: Forward movement
         * S: Backward movement
         * A: Left rotation
         * D: Right rotation
         * It also takes into account the current distance it is away from the destination and determines if
         * the movement taken is positive or negative toward the goal.
         */
        if (NetworkInput.GetKey(KeyCode.W))
        {
            controllerValue1 = maxSpeed;
            controllerValue2 = maxSpeed;
            controllerValue3 = maxSpeed;
            controllerValue4 = maxSpeed;

            //Distance taken from the moment before the movement is applied
            var distance = Vector3.Distance(this.transform.position, Playground.instance.destinationPos);

            this.transform.position += transform.forward * moveSpeed * Time.deltaTime;

            //toScore used to only allocate scores once at a time
            if (toScore)
            {
                //Check if the distance between the robot and Destination got larger or smaller
                if (Vector3.Distance(this.transform.position, Playground.instance.destinationPos) < distance)
                {
                    //allocate score if distance was reduced
                    score++;
                }
                else
                {
                    //otherwise penalize the AI
                    score -= 2;
                }

                toScore = false;
            }
        }
        else if (NetworkInput.GetKey(KeyCode.S))
        {
            controllerValue1 = -maxSpeed;
            controllerValue2 = -maxSpeed;
            controllerValue3 = -maxSpeed;
            controllerValue4 = -maxSpeed;

            var distance = Vector3.Distance(this.transform.position, Playground.instance.destinationPos);

            this.transform.position -= transform.forward * moveSpeed * Time.deltaTime;

            if (toScore)
            {
                if (Vector3.Distance(this.transform.position, Playground.instance.destinationPos) < distance)
                {
                    score++;
                }
                else
                {
                    score -= 2;
                }

                toScore = false;
            }
        }
        else if (NetworkInput.GetKey(KeyCode.A))
        {
            controllerValue1 = -maxSpeed;
            controllerValue2 = maxSpeed;
            controllerValue3 = -maxSpeed;
            controllerValue4 = maxSpeed;

            if (simulate_rotate)
            {
                this.transform.Rotate(-Vector3.up * rotateSpeed * Time.deltaTime);
            }

            if (toScore)
            {
                score--;

                toScore = false;
            }
        }
        else if (NetworkInput.GetKey(KeyCode.D))
        {
            controllerValue1 = maxSpeed;
            controllerValue2 = -maxSpeed;
            controllerValue3 = maxSpeed;
            controllerValue4 = -maxSpeed;

            if (simulate_rotate)
            {
                this.transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime);
            }

            if (toScore)
            {
                score--;

                toScore = false;
            }
        }
        else
        {
            controllerValue1 = 0f;
            controllerValue2 = 0f;
            controllerValue3 = 0f;
            controllerValue4 = 0f;

            toScore = true;
        }

        SendRobotCommand((int)controllerValue1, (int)controllerValue2, (int)controllerValue3, (int)controllerValue4);
    }
Esempio n. 17
0
 public void OnInputMissing(NetworkRunner runner, PlayerRef player, NetworkInput input)
 {
 }