Ejemplo n.º 1
0
        private void MenuTabs_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                int tempIndex = GetTabIndexFromPoint(e.Location, out onCloseButton, out onMenuArrow, out onSignOut);

                if (onCloseButton)
                {
                    ControlEvent.Invoke(this, ControlAction.CloseTour);
                    return;
                }

                if (onSignOut)
                {
                    if (Earth3d.IsLoggedIn)
                    {
                        ControlEvent.Invoke(this, ControlAction.SignOut);
                    }
                    else
                    {
                        ControlEvent.Invoke(this, ControlAction.SignIn);
                    }
                    return;
                }
                SetSelectedIndex(tempIndex, onMenuArrow);
            }
            else if (e.Button == MouseButtons.Right)
            {
                if (e.X < startX)
                {
                    ControlEvent.Invoke(this, ControlAction.AppMenu);
                }
            }
        }
Ejemplo n.º 2
0
//    public void OnPostRender()
    IEnumerator SendAndReceive()
    {
        yield return(new WaitForEndOfFrame());

        while (true)
        {
            // Python sends a command, which is then invoked
            var read = ReadMessage();
            Debug.Log("read" + read);
            var msg = JsonUtility.FromJson <ControlMessage>(read);

            // If the game is being reset, reset it then exit early
            if (msg.resetGame)
            {
                Game.ResetGame();
                yield return(new WaitForSeconds(.5f));

                Game.ResetGame();
            }
            else
            {
                // Trigger action events here
                OnInputReceived.Invoke(msg.action);
            }

            // Wait for the new state
            yield return(new WaitForEndOfFrame());

            //The new state is encoded, along with the game score and game state information
            var encodedImage = GetFrameEncoded();

            // Create the state message and send it
            var message = new StateMessage
            {
                encodedImage = encodedImage,
                gameScore    = Game.Score,
                gameOver     = Game.IsOver
            };
            var json = JsonUtility.ToJson(message);

            WriteMessage(json);
//            if (msg.resetGame)
//            {
//                _theStream.Close();
//                _mySocket.Close();
//                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
//                yield return null;
//            }
        }
    }
Ejemplo n.º 3
0
    public void OnDrag(PointerEventData eventData)
    {
        Ray ray = Camera.allCameras[1].ScreenPointToRay(eventData.position);

        float rayDistance;

        if (_plane.Raycast(ray, out rayDistance))
        {
            var newPos = ray.GetPoint(rayDistance);
            _controlCube.transform.position = new Vector3(_controlCube.transform.position.x, newPos.y, _controlCube.transform.position.z);

            _output = _controlCube.transform.localPosition.y / transform.worldToLocalMatrix.MultiplyPoint3x4(_originalPosition).y;

            controlChangedEvent.Invoke(_output);

            //_target.transform.localScale = new Vector3( _originalScale.x, _originalScale.y * _output, _originalScale.z);
        }
    }
Ejemplo n.º 4
0
        private void MenuTabs_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int index = ((int)e.X - startX) / 100;

            if (ControlEvent == null)
            {
                return;
            }
            if (e.X < startX)
            {
                if (Maximized)
                {
                    ControlEvent.Invoke(this, ControlAction.Restore);
                }
                else
                {
                    ControlEvent.Invoke(this, ControlAction.Maximize);
                }
            }
        }
    //Update is called once per frame
    void Update()
    {
        //if (!Input.GetKey(KeyCode.LeftShift))
        {
            if (input == null)
            {
                print("input is null");
            }


            //if (input.gamepads.Count == 0)
            //{
            //    print("no gamepads connected");
            //}

            int playerNum = 1;


            foreach (GamepadDevice gamepad in input.gamepads)
            {
                //create a structure for holding controls
                ControlStruct playerControls = new ControlStruct();


                int[] buttonValues = (int[])System.Enum.GetValues(typeof(GamepadButton));


                for (int i = 0; i < buttonValues.Length; i++)
                {
                    //print("Not left shift " + (GamepadButton)buttonValues[i] + ": " + gamepad.GetButton((GamepadButton)buttonValues[i]) + "\n");
                    //print("Not left shift " + i + ": " + gamepad.GetButton((GamepadButton)buttonValues[i]) + "\n");
                    updateControl(i, playerControls, gamepad.GetButton((GamepadButton)buttonValues[i]));
                }

                int[] axisValues = (int[])System.Enum.GetValues(typeof(GamepadAxis));
                for (int i = 0; i < axisValues.Length; i++)
                {
                    if (gamepad.GetAxis((GamepadAxis)axisValues[i]) != 0)
                    {
                        //print("Not left shift " + (GamepadAxis)axisValues[i] + ": " + gamepad.GetAxis((GamepadAxis)axisValues[i]) + "\n");
                        updateControl(i, playerControls, gamepad.GetAxis((GamepadAxis)axisValues[i]));
                    }
                }


                //pass the controls on to the player through an event
                //keep track of gamepads by ID, rather than player number
                //so that if a controller becomes unplugged, it doesn't shift
                //all controllers down an index.
                if (gamepad.deviceId == 0)
                {
                    controller1.Invoke(playerControls);
                }
                if (gamepad.deviceId == 1)
                {
                    controller2.Invoke(playerControls);
                }
                if (gamepad.deviceId == 2)
                {
                    controller3.Invoke(playerControls);
                }
                if (gamepad.deviceId == 3)
                {
                    controller4.Invoke(playerControls);
                }
                playerNum++;
            }
            if (printOnce)
            {
                print("controllers found: " + (playerNum - 1));
                printOnce = false;
            }
        }
    }