Пример #1
0
 /// <summary>
 /// 入力ボタン確認用
 /// </summary>
 /// <param name="x"></param>
 public void GetLogButton(XBoxInput x)
 {
     if (x != XBoxInput.None)
     {
         Debug.Log(x.ToString());
     }
 }
Пример #2
0
        /// <summary>
        /// Initialize Classes for Input handling
        /// Add event listeners for everyone who wants to process incomming drone-commands (UI and Drone itself)
        /// </summary>
        private void InitInput()
        {
            this.Activated  += MainForm_Activated;
            this.Deactivate += MainForm_Deactivate;

            inputManager = new InputManager();
            // Add UI Listeners
            inputManager.Hover    += inputManager_Hover;
            inputManager.Progress += inputManager_Progress;

            // Add droneClient listeners
            inputManager.Emergency += droneClient.Emergency;
            inputManager.FlatTrim  += droneClient.FlatTrim;
            inputManager.Hover     += droneClient.Hover;
            inputManager.Land      += droneClient.Land;
            inputManager.Progress  += droneClient.Progress;
            inputManager.Takeoff   += droneClient.Takeoff;

            // Load keyboard module
            KeyboardInput keyboardInput = new KeyboardInput();

            // Prevents input through keyboard when the app is not focused
            this.Activated  += (sender, e) => keyboardInput.Active = true;
            this.Deactivate += (sender, e) => keyboardInput.Active = false;
            inputManager.addControl(keyboardInput);

            // Load Xbox module
            try
            {
                XBoxInput xBoxInput = new XBoxInput();
                inputManager.addControl(xBoxInput);
            }
            catch (Exception e)
            {
                MessageBox.Show("Xbox module not loaded:\n" + e.Message, "Xbox error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            // Load Myo module
            try
            {
                MyoInput myoInput = new MyoInput();
                this.Activated  += (sender, e) => myoInput.Active = true;
                this.Deactivate += (sender, e) => myoInput.Active = false;
                inputManager.addControl(myoInput);
            }
            catch (Exception e)
            {
                MessageBox.Show("Myo module not loaded:\n" + e.Message, "Myo error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
 public XBoxInputPair(XBoxInput key, string axis)
 {
     this.key = key;
     this.value = axis;
     this.isAxis = true;
 }
 public XBoxInputPair(XBoxInput key, KeyCode keyCode)
 {
     this.key = key;
     this.value = keyCode.ToString();
 }
Пример #5
0
        // Update is called once per frame
        void Update()
        {
            // ボタンとスティックの入力を取得して通知
#if WINDOWS_UWP
            if (gamepad != null)
            {
                var reader = gamepad.GetCurrentReading();
                var lx     = (float)reader.LeftThumbstickX;
                var ly     = (float)reader.LeftThumbstickY;
                if (Mathf.Abs(lx) > 0.1f || Mathf.Abs(ly) > 0.1f)
                {
                    getAxis.Invoke(XBoxStick.LeftThumbstick, new Vector2(lx, ly));
                }
                var rx = (float)reader.RightThumbstickX;
                var ry = (float)reader.RightThumbstickY;
                if (Mathf.Abs(rx) > 0.1f || Mathf.Abs(ry) > 0.1f)
                {
                    getAxis.Invoke(XBoxStick.RightThumbstick, new Vector2(rx, ry));
                }
                var lt = (float)reader.LeftTrigger;
                var rt = (float)reader.RightTrigger;
                if (Mathf.Abs(lt) > 0.1f || Mathf.Abs(rt) > 0.1f)
                {
                    getAxis.Invoke(XBoxStick.Trigger, new Vector2(lt, rt));
                }
                getButton.Invoke((XBoxInput)reader.Buttons);
            }
#else
            // No support (DPad, RightThumbstick, Trigger)
            // UWP以外ではXBoxコントローラーの十字キー,右側スティック,左右のトリガーは非サポート
            var gamepad = UnityEngine.Input.GetJoystickNames();
            if (((gamepad.Length > 0) ? true : false) == true && gamepad[0] != "")
            {
                var axisX = UnityEngine.Input.GetAxis("Horizontal");
                var axisY = UnityEngine.Input.GetAxis("Vertical");
                if (Mathf.Abs(axisX) > 0.1f || Mathf.Abs(axisY) > 0.1f)
                {
                    getAxis.Invoke(XBoxStick.LeftThumbstick, new Vector2(axisX, axisY));
                }

                XBoxInput xBoxInput = 0;
                if (UnityEngine.Input.GetKey("joystick button 0"))
                {
                    xBoxInput = xBoxInput | XBoxInput.A;
                }
                if (UnityEngine.Input.GetKey("joystick button 1"))
                {
                    xBoxInput = xBoxInput | XBoxInput.B;
                }
                if (UnityEngine.Input.GetKey("joystick button 2"))
                {
                    xBoxInput = xBoxInput | XBoxInput.X;
                }
                if (UnityEngine.Input.GetKey("joystick button 3"))
                {
                    xBoxInput = xBoxInput | XBoxInput.Y;
                }
                if (UnityEngine.Input.GetKey("joystick button 4"))
                {
                    xBoxInput = xBoxInput | XBoxInput.LeftShoulder;
                }
                if (UnityEngine.Input.GetKey("joystick button 5"))
                {
                    xBoxInput = xBoxInput | XBoxInput.RightShoulder;
                }
                if (UnityEngine.Input.GetKey("joystick button 6"))
                {
                    xBoxInput = xBoxInput | XBoxInput.View;
                }
                if (UnityEngine.Input.GetKey("joystick button 7"))
                {
                    xBoxInput = xBoxInput | XBoxInput.Menu;
                }
                if (UnityEngine.Input.GetKey("joystick button 8"))
                {
                    xBoxInput = xBoxInput | XBoxInput.LeftThumbstick;
                }
                if (UnityEngine.Input.GetKey("joystick button 9"))
                {
                    xBoxInput = xBoxInput | XBoxInput.RightThumbstick;
                }
                getButton.Invoke(xBoxInput);
            }
#endif
        }
    // Update is called once per frame
    void Update()
    {
        if (!isLocalPlayer)
        {
            for (int i = 0; i < totalCamera.Count; i++)
            {
                totalCamera[i].GetComponentInChildren <Camera>().enabled = false;
            }
            camChoice = false;
            theCanvasManager.SetCanvasActive(false);

            return;
        }

        if (!initRM)
        {
            controller  = GameObject.FindGameObjectWithTag("Ardunity").GetComponent <ArdunityApp>();
            controllerX = GameObject.FindGameObjectWithTag("CamX").GetComponent <AnalogInput>();
            controllerY = GameObject.FindGameObjectWithTag("CamY").GetComponent <AnalogInput>();
            controllerZ = GameObject.FindGameObjectWithTag("Zoom").GetComponent <AnalogInput>();
            trapButton  = GameObject.FindGameObjectWithTag("TrapButton").GetComponent <DigitalInput>();
            leftButton  = GameObject.FindGameObjectWithTag("LeftArrow").GetComponent <DigitalInput>();
            rightButton = GameObject.FindGameObjectWithTag("RightArrow").GetComponent <DigitalInput>();
            //camRoomName = "Room1";
            //trapSelect = 1;
            LoadProperties();
        }

        GameObject.FindGameObjectsWithTag("RunnerOne")[1].GetComponentInChildren <SkinnedMeshRenderer>().material = run2mat;

        //theCanvasManager.PrintCode(theRoomManager.ObjectiveLength());
        //theCanvasManager.PrintCode(theRoomManager.ObjectiveLength());

        //for deactivating traps :)
        switch (GameObject.Find(networkTrapStr).GetComponent <TrapForNetwork>().trapToGoAway)
        {
        case 1:
            R1currentObjective = GameObject.Find(O1).GetComponentInChildren <Objective>();

            break;

        case 2:
            R1currentObjective = GameObject.Find(O2).GetComponentInChildren <Objective>();

            break;

        case 3:
            R1currentObjective = GameObject.Find(O3).GetComponentInChildren <Objective>();

            break;

        case 4:
            R1currentObjective = GameObject.Find(O4).GetComponentInChildren <Objective>();

            break;

        case 5:
            R1currentObjective = GameObject.Find(O5).GetComponentInChildren <Objective>();

            break;

        case 6:
            R1currentObjective = GameObject.Find(O6).GetComponentInChildren <Objective>();

            break;

        case 7:
            R1currentObjective = GameObject.Find(O7).GetComponentInChildren <Objective>();

            break;

        default:
            //swing and a miss
            break;
        }

        switch (GameObject.Find(networkTrapStr).GetComponent <TrapForNetwork>().otherTrapToGoAway)
        {
        case 1:
            R2currentObjective = GameObject.Find(O1).GetComponentInChildren <Objective>();

            break;

        case 2:
            R2currentObjective = GameObject.Find(O2).GetComponentInChildren <Objective>();

            break;

        case 3:
            R2currentObjective = GameObject.Find(O3).GetComponentInChildren <Objective>();

            break;

        case 4:
            R2currentObjective = GameObject.Find(O4).GetComponentInChildren <Objective>();

            break;

        case 5:
            R2currentObjective = GameObject.Find(O5).GetComponentInChildren <Objective>();

            break;

        case 6:
            R2currentObjective = GameObject.Find(O6).GetComponentInChildren <Objective>();

            break;

        case 7:
            R2currentObjective = GameObject.Find(O7).GetComponentInChildren <Objective>();

            break;

        default:
            //swing and a miss
            break;
        }



        if (controller.connected)
        {
            if (controllerX.Value < .49f || controllerX.Value > .51f)
            {
                cameraLook.x = (controllerX.Value - .5f) * 2f;
            }
            else
            {
                cameraLook.x = 0;
            }

            if (controllerY.Value < .48f || controllerY.Value > .52f)
            {
                cameraLook.y = (controllerY.Value - .5f) * 2f;
            }
            else
            {
                cameraLook.y = 0;
            }

            if (controllerZ.Value < .48f || controllerZ.Value > .52f)
            {
                zAxis = (controllerZ.Value - .5f) * 2f;
            }
            else
            {
                zAxis = 0;
            }

            if (trapButton.Value == true)
            {
                trapPress = true;
            }
            if (leftButton.Value == true)
            {
                leftPress = true;
            }
            if (rightButton.Value == true)
            {
                rightPress = true;
            }
        }
        else
        {
            if (XBoxInput.getConnected())
            {
                cameraLook.x = XBoxInput.getLeftStickXAxis();
                cameraLook.y = XBoxInput.getLeftStickYAxis() * -1;

                zAxis = XBoxInput.getRightStickYAxis() * -1f;

                if (XBoxInput.getButtonA())
                {
                    trapPress = true;
                }
                if (XBoxInput.getButtonLB())
                {
                    leftPress = true;
                }
                if (XBoxInput.getButtonRB())
                {
                    rightPress = true;
                }
            }
            else
            {
                cameraLook.x += Input.GetAxis(mouseX);
                cameraLook.y += Input.GetAxis(mouseY);
            }
        }

        //clamp the camera's y rotation to prevent weird camera angles
        cameraLook.y = Mathf.Clamp(cameraLook.y, CAM_Y_MIN, CAM_Y_MAX);
        //cameraLook.x = Mathf.Clamp(cameraLook.x, CAM_X_MIN, CAM_X_MAX);

        //Debug.Log(totalCamera.Count);
        //array will be way more useful for this stuff later on

        //https://answers.unity.com/questions/615771/how-to-check-if-click-mouse-on-object.html
        //to activate trap
        if (Input.GetMouseButtonDown(0) || (trapPress && !trapButton.Value))
        {
            trapPress = false;
            clickRay  = totalCamera[currentCamera].GetComponentInChildren <Camera>().ViewportPointToRay(viewportCenter);
            //print(clickRay + " other ver " + totalCamera[currentCamera].GetComponentInChildren<Camera>().ViewportPointToRay(viewportCenter));

            if (Physics.Raycast(clickRay, out clickHit))
            {
                if (clickHit.transform.CompareTag(treasureStr))
                {
                    //atm, the overseer can only have 5 active traps at a time
                    //CmdObjectiveTrap(clickHit.collider.gameObject.name);
                    clickHit.collider.gameObject.GetComponent <Treasure>().TreasureOnClick(theRoomManager.theImages, gameObject.GetComponent <OverSeerControl>(), theRoomManager);//, this.gameObject.GetComponent<OverSeerControl>());
                }
                else if (clickHit.transform.CompareTag(securityStr))
                {
                    //Debug.Log(camRoomName);
                    //Debug.Log(trapSelect);
                    clickHit.collider.gameObject.GetComponent <TrapDoor>().OnSecurityClick(gameObject);
                }
            }
        }

        for (int i = 0; i < totalCamera.Count; i++)
        {
            findFOV(i);

            if (Input.GetKeyUp(KeyCode.LeftArrow) || (leftPress && leftButton.Value == false))
            {
                if (totalCamera[i].GetComponentInChildren <Camera>().enabled)
                {
                    leftPress    = false;
                    cameraLook.x = 0;
                    cameraLook.y = 0;
                    //totalCamera[i].GetComponentInChildren<Camera>().enabled = false;
                    totalCamera[i].GetComponentInChildren <Camera>().transform.eulerAngles = new Vector3(cameraLook.y, ogRotation[i].y + cameraLook.x, 0);

                    if (totalCamera[i] == totalCamera[0])
                    {
                        trapSelect = 15;
                        totalCamera[totalCamera.Count - 1].GetComponentInChildren <Camera>().enabled = true;
                        totalCamera[i].GetComponentInChildren <Camera>().enabled = false;
                        currentCamera = 14;
                        theCanvasManager.SwitchCameras(currentCamera, totalCamera[currentCamera].GetComponentInChildren <Camera>());
                        break;
                    }
                    else
                    {
                        trapSelect--;
                        totalCamera[i - 1].GetComponentInChildren <Camera>().enabled = true;
                        currentCamera = i - 1;
                        totalCamera[i].GetComponentInChildren <Camera>().enabled = false;
                        theCanvasManager.SwitchCameras(currentCamera, totalCamera[currentCamera].GetComponentInChildren <Camera>());
                        break;
                    }

                    //totalCamera[i].GetComponentInChildren<Camera>().enabled = false;
                }
                theCanvasManager.UpdateCanvasCamera(totalCamera[i].GetComponentInChildren <Camera>());
            }

            if (Input.GetKeyUp(KeyCode.RightArrow) || (rightPress && rightButton.Value == false))
            {
                if (totalCamera[i].GetComponentInChildren <Camera>().enabled)
                {
                    rightPress   = false;
                    cameraLook.x = 0;
                    cameraLook.y = 0;
                    totalCamera[i].GetComponentInChildren <Camera>().transform.eulerAngles = new Vector3(cameraLook.y, ogRotation[i].y + cameraLook.x, 0);
                    if (totalCamera[i] == totalCamera[totalCamera.Count - 1])
                    {
                        trapSelect = 1;
                        totalCamera[0].GetComponentInChildren <Camera>().enabled = true;
                        totalCamera[i].GetComponentInChildren <Camera>().enabled = false;
                        currentCamera = 0;
                        theCanvasManager.SwitchCameras(currentCamera, totalCamera[currentCamera].GetComponentInChildren <Camera>());
                        break;
                    }
                    else
                    {
                        trapSelect++;
                        totalCamera[i + 1].GetComponentInChildren <Camera>().enabled = true;
                        totalCamera[i].GetComponentInChildren <Camera>().enabled     = false;
                        currentCamera = i + 1;
                        theCanvasManager.SwitchCameras(currentCamera, totalCamera[currentCamera].GetComponentInChildren <Camera>());
                        break;
                    }
                }
                theCanvasManager.UpdateCanvasCamera(totalCamera[i].GetComponentInChildren <Camera>());
            }

            if (controller.connected || XBoxInput.getConnected())
            {
                if (totalCamera[i].GetComponentInChildren <Camera>().enabled)
                {
                    float temp = totalCamera[i].GetComponentInChildren <Camera>().fieldOfView;

                    if (temp >= 30 && temp <= 70)
                    {
                        temp -= zAxis * zoomSpeed * Time.deltaTime;
                    }
                    if (temp > 70)
                    {
                        temp = 70;
                    }
                    if (temp < 30)
                    {
                        temp = 30;
                    }

                    totalCamera[i].GetComponentInChildren <Camera>().fieldOfView = temp;
                }
            }
            else
            {
                if (Input.GetKey(KeyCode.UpArrow))
                {
                    if (totalCamera[i].GetComponentInChildren <Camera>().enabled)
                    {
                        float temp = totalCamera[i].GetComponentInChildren <Camera>().fieldOfView;

                        if (temp > 30)
                        {
                            temp -= zoomSpeed * Time.deltaTime;
                        }

                        totalCamera[i].GetComponentInChildren <Camera>().fieldOfView = temp;
                    }
                }


                if (Input.GetKey(KeyCode.DownArrow))
                {
                    if (totalCamera[i].GetComponentInChildren <Camera>().enabled)
                    {
                        float temp = totalCamera[i].GetComponentInChildren <Camera>().fieldOfView;

                        if (temp < 70)
                        {
                            temp += zoomSpeed * Time.deltaTime;
                        }

                        totalCamera[i].GetComponentInChildren <Camera>().fieldOfView = temp;
                    }
                }
            }

            if (totalCamera[i].GetComponentInChildren <Camera>().enabled)
            {
                if (controller.connected || XBoxInput.getConnected())
                {
                    totalCamera[i].GetComponentInChildren <Camera>().transform.eulerAngles = new Vector3(Mathf.Clamp(totalCamera[i].GetComponentInChildren <Camera>().transform.eulerAngles.x, 1, 85) + cameraLook.y, Mathf.Clamp(totalCamera[i].GetComponentInChildren <Camera>().transform.eulerAngles.y, 0, 359) + cameraLook.x, 0);
                }
                else
                {
                    totalCamera[i].GetComponentInChildren <Camera>().transform.eulerAngles = new Vector3(-cameraLook.y, ogRotation[i].y + cameraLook.x, 0);
                }
                Vector3 psoition = totalCamera[i].transform.position;
                SoundManager.setListenerPos(psoition.x, psoition.y, psoition.z);
                SoundManager.setListenerVel(0f, 0f, 0f);
                Vector3 cast = totalCamera[i].GetComponentInChildren <Camera>().ViewportPointToRay(viewportCenter).direction;
                SoundManager.setListenerForward(cast.x, cast.y, cast.z);
            }
        }


        //EVENT CONSOLE BULLSHIT
        //	to send stuff on the canvas queue

        //theCanvasManager.T1.text ="r1="+GameObject.FindGameObjectsWithTag("RunnerOne").Length.ToString();
        //theCanvasManager.T2.text ="r2=" + GameObject.FindGameObjectsWithTag("RunnerTwo").Length.ToString();


        //print(eventConsole.repetitiveshit());

        //theCanvasManager.T3.text = eventConsole.repetitiveshit();

        if (run1 == null || run2 == null)
        {
            theCanvasManager.T3.text = "SOMETHINGS NULL BITCHHHHH";
            theCanvasManager.T4.text = "r1=" + GameObject.FindGameObjectsWithTag("RunnerOne").Length.ToString();
            theCanvasManager.T5.text = "r2=" + GameObject.FindGameObjectsWithTag("RunnerTwo").Length.ToString();
        }
        else
        {
            //theCanvasManager.T4.text = "gets to this point";
            //if (OverID == 1)
            //{
            //	theCanvasManager.T4.text = "run2 cur " + run2.currstate.ToString();
            //	theCanvasManager.T5.text = "run1 cur " + run1.currstate.ToString();

            //}
            //else if (OverID == 2)
            //{
            //	theCanvasManager.T4.text = "run2 cur " + run2.currstate.ToString();
            //	theCanvasManager.T5.text = "run1 cur " + run1.currstate.ToString();

            //}

            if (run1.currstate != 0 || run2.currstate != 0)
            {
                theCanvasManager.newConsoleMessage(eventConsole.repetitiveshit());
                print("it gets to this point FUUUCk");
                print(run1.currstate.ToString());
                theCanvasManager.T5.text = "d " + eventConsole.repetitiveshit();
                run1.currstate           = 0;
                run2.currstate           = 0;
            }
        }

        theCanvasManager.consoleMessages();

        //theCanvasManager.T5.text = "gets to this point";



        //Debug.Log(OverID);

        camRoomName = roomStr + trapSelect.ToString();
    }