예제 #1
0
    private void Update()
    {
        m_pressedButtonL = null;
        m_pressedButtonR = null;

        if (m_joycons == null || m_joycons.Count <= 0)
        {
            return;
        }

        SetControllers();

        foreach (var button in m_buttons)
        {
            if (m_joyconL != null && m_joyconL.GetButton(button))
            {
                m_pressedButtonL = button;
            }
            if (m_joyconR != null && m_joyconR.GetButton(button))
            {
                m_pressedButtonR = button;
            }
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            m_joyconL.SetRumble(320, 160, 0.6f, 200);
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            m_joyconR.SetRumble(160, 320, 0.6f, 200);
        }
    }
예제 #2
0
    void BreakRumbles()
    {
        Joycon j = main.joycons[main.currentJoyconMouth];

        j.SetRumble(0f, 0f, 0f);

        j = main.joycons[main.currentJoyconPlayer];
        j.SetRumble(0f, 0f, 0f);
    }
예제 #3
0
    void BreakRumbles()
    {
        Joycon j = joycons[this.currentJoyconMouth];

        j.SetRumble(0f, 0f, 0f);

        j = joycons[this.currentJoyconPlayer];
        j.SetRumble(0f, 0f, 0f);
    }
예제 #4
0
    IEnumerator Forward()
    {
        for (int i = 0; i < 5; i++)
        {
            m_joyconL.SetRumble(0, -500.0f, 1.0f, 20);
            yield return(new WaitForSeconds(0.02f));

            m_joyconL.SetRumble(0, 1.0f, 0.2f, 50);
            yield return(new WaitForSeconds(0.05f));
        }
    }
예제 #5
0
 public void GameOver(bool winner)
 {
     if (joycons.Count > 0)
     {
         Joycon j = joycons[jc_ind];
         if (winner)
         {
             j.SetRumble(80, 320, 0.6f, 200);
         }
         else
         {
             j.SetRumble(80, 160, 0.6f, 200);
         }
     }
 }
예제 #6
0
파일: Example.cs 프로젝트: yuyuran/project
    private void Update()
    {
        m_pressedButtonL = null;
        m_pressedButtonR = null;

        if (m_joycons == null || m_joycons.Count <= 0) return;

        //foreach (var button in m_buttons)
        //{
        //    if (m_joyconL.GetButton(button))
        //    {
        //        m_pressedButtonL = button;
        //    }
        //    if (m_joyconR.GetButton(button))
        //    {
        //        m_pressedButtonR = button;
        //    }
        //}

        if (Input.GetKeyDown(KeyCode.Z))
        {
            m_joyconL.SetRumble(160, 320, 0.6f, 200);
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            m_joyconR.SetRumble(160, 320, 0.6f, 200);
        }

        if(m_joyconR.GetButton(Joycon.Button.SHOULDER_2))
        {
            gameObject.transform.Translate(0, 0, 0.08f);
        }

        obj.transform.localRotation = new Quaternion(0, -m_joyconL.GetVector().z, 0, m_joyconL.GetVector().w);
    }
예제 #7
0
    private void Update()
    {
        m_pressedButtonL = null;
        //m_pressedButtonR = null;

        if (m_joycons == null || m_joycons.Count <= 0)
        {
            return;
        }

        foreach (var button in m_buttons)
        {
            if (m_joyconL.GetButton(button))
            {
                m_pressedButtonL = button;
            }
            //if (m_joyconR.GetButton(button))
            //{
            //    m_pressedButtonR = button;
            //}
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            m_joyconL.SetRumble(160, 320, 0.6f, 200);
        }
        //if (Input.GetKeyDown(KeyCode.X))
        //{
        //    m_joyconR.SetRumble(160, 320, 0.6f, 200);
        //}
    }
예제 #8
0
    void Update()
    {
        if (j != null)
        {
            j.SetRumble(160, 320, 0.3f, 200);

            if (j.GetButton(Joycon.Button.DPAD_UP))
            {
                transform.position += (Vector3.forward * SPEED * Time.deltaTime);
            }

            if (j.GetButton(Joycon.Button.DPAD_DOWN))
            {
                transform.position += (Vector3.back * SPEED * Time.deltaTime);
            }

            if (j.GetButton(Joycon.Button.DPAD_LEFT))
            {
                transform.position += (Vector3.left * SPEED * Time.deltaTime);
            }

            if (j.GetButton(Joycon.Button.DPAD_RIGHT))
            {
                transform.position += (Vector3.right * SPEED * Time.deltaTime);
            }
        }
    }
예제 #9
0
    // Update is called once per frame
    void Update()
    {
        Joycon j = joycons[jc_ind];

        //Tekst wordt omgezet naar Goed bezig!
        warning.text = "Goed bezig!";
        if (currentForce.joint.currentForce[1] > -600)
        {
            alreadyPlayed = false;
        }
        //Als de force op as Y lager is dan -700 dan moet de tekst "Je knie mag niet voorbij je tenen!" zijn.
        if (currentForce.joint.currentForce[1] < -600)
        {
            Debug.Log("Rumble");
            //Verstuurt rumble naar joy-con wanneer knie te ver naar voren staat.
            j.SetRumble(160, 160, 0.6f, 1000);

            warning.text = "Je knie mag niet voorbij je tenen!";
            if (!alreadyPlayed)
            {
                if (feedbackSound != null)
                {
                    audioSource.PlayOneShot(feedbackSound, 0.7f);
                    alreadyPlayed = true;
                }
            }
        }
    }
예제 #10
0
 void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.tag == "target")
     {
         m_joyconL.SetRumble(160, 320, 0.6f, 200);
     }
 }
예제 #11
0
 public static void RumbleJoycon(float lowFreq, float higFreq, float amp, int time = 0)
 {
     if (CheckJoyconAvail() && BodySourceView.BodyFound)
     //if(CheckJoyconAvail())
     {
         j.SetRumble(lowFreq, higFreq, amp, time);
     }
 }
예제 #12
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (joycons.Count > 0)
        {
            j = joycons[jc_ind];
            // GetButtonDown checks if a button has been pressed (not held)
            if (j.GetButtonDown(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 pressed");
                // GetStick returns a 2-element vector with x/y joystick components
                Debug.Log(string.Format("Stick x: {0:N} Stick y: {1:N}", j.GetStick()[0], j.GetStick()[1]));

                // Joycon has no magnetometer, so it cannot accurately determine its yaw value. Joycon.Recenter allows the user to reset the yaw value.
                j.Recenter();
            }
            // GetButtonDown checks if a button has been released
            if (j.GetButtonUp(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 released");
            }
            // GetButtonDown checks if a button is currently down (pressed or held)
            if (j.GetButton(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 held");
            }

            if (j.GetButtonDown(Joycon.Button.DPAD_DOWN))
            {
                Debug.Log("Rumble");

                // Rumble for 200 milliseconds, with low frequency rumble at 160 Hz and high frequency rumble at 320 Hz. For more information check:
                // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md

                j.SetRumble(30, 130, 2f, 100);

                // The last argument (time) in SetRumble is optional. Call it with three arguments to turn it on without telling it when to turn off.
                // (Useful for dynamically changing rumble values.)
                // Then call SetRumble(0,0,0) when you want to turn it off.
            }

            stick = j.GetStick();

            // Gyro values: x, y, z axis values (in radians per second)
            gyro = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = j.GetAccel();

            orientation    = j.GetVector();
            orientation    = Quaternion.Inverse(new Quaternion(orientation.x, orientation.z, orientation.y, orientation.w));
            orientationXYZ = orientation.eulerAngles;
            orientationXYZ = new Vector3(orientationXYZ.x, orientationXYZ.y, orientationXYZ.z);
            gameObject.transform.localRotation = Quaternion.Euler(orientationXYZ);
        }
    }
예제 #13
0
 public void Vibrate(bool lFlag, bool rFlag)
 {
     if (lFlag)
     {
         m_joyconL.SetRumble(160, 320, 0.6f, 200);
     }
     if (rFlag)
     {
         m_joyconR.SetRumble(160, 320, 0.6f, 200);
     }
 }
예제 #14
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Joycon j = joycons[jc_ind];

        stick = new Vector2(j.GetStick()[0], j.GetStick()[1]);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/joystick/x", stick.x);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/joystick/y", stick.y);

        // Gyro values: x, y, z axis values (in radians per second)
        gyro = j.GetGyro();
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/gyro/x", gyro.x);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/gyro/y", gyro.y);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/gyro/z", gyro.z);
        // Accel values:  x, y, z axis values (in Gs)
        accel = j.GetAccel();
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/accel/x", accel.x);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/accel/y", accel.y);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/accel/z", accel.z);

        orientation = j.GetVector();
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/orientation/0", orientation[0]);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/orientation/1", orientation[1]);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/orientation/2", orientation[2]);
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/orientation/3", orientation[3]);

        //Buttons
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/down", (j.GetButton(Joycon.Button.DPAD_DOWN) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/up", (j.GetButton(Joycon.Button.DPAD_UP) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/right", (j.GetButton(Joycon.Button.DPAD_RIGHT) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/left", (j.GetButton(Joycon.Button.DPAD_LEFT) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/minus", (j.GetButton(Joycon.Button.MINUS) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/bumper", (j.GetButton(Joycon.Button.SHOULDER_1) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/trigger", (j.GetButton(Joycon.Button.SHOULDER_2) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/home", (j.GetButton(Joycon.Button.CAPTURE) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/joystick", (j.GetButton(Joycon.Button.STICK) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/side-top", (j.GetButton(Joycon.Button.SL) ? 1 : 0));
        OSCHandler.Instance.SendMessageToClient("myClient", "/left/buttons/side-bottom", (j.GetButton(Joycon.Button.SR) ? 1 : 0));

        if (rumble == 1)
        {
            j.SetRumble(rumbleFreqLow, rumbleFreqHigh, 0.6f, rumbleLen);
            rumble = 0;
        }


        for (var i = 0; i < OSCHandler.Instance.packets.Count; i++)
        {
            // Process OSC
            receivedOSC(OSCHandler.Instance.packets[i]);
            // Remove them once they have been read.
            OSCHandler.Instance.packets.Remove(OSCHandler.Instance.packets[i]);
            i--;
        }
    }
예제 #15
0
    IEnumerator slowVibrations()
    {
        for (int i = 0; i < playerName + 1; i++)
        {
            this.transform.Find("Spot Light").gameObject.SetActive(true);
            current.SetRumble(160, 160, 0.6f, 100);
            yield return(new WaitForSeconds(0.20f));

            this.transform.Find("Spot Light").gameObject.SetActive(false);
            yield return(new WaitForSeconds(0.15f));
        }
    }
예제 #16
0
    void playFeedbacks()
    {
        plane.GetComponentInChildren <ParticleSystem>().Play();
        CameraShake.Shake(0.1f, 0.75f);
        player.Freeze();

        if (joycons.Count > 0)
        {
            Joycon j = joycons[this.currentJoyconMouth];
            j.SetRumble(0.2f, 0.3f, 1f);


            if (player.deathSoundIsPlayed)
            {
                j = joycons[this.currentJoyconPlayer];
                j.SetRumble(0.2f, 0.3f, 1f);
            }

            Invoke("BreakRumbles", 0.1f);
        }
    }
예제 #17
0
    IEnumerator waitASec()
    {
        if (bossAnim != null)
        {
            bossAnim.SetBool("isDead", true);
        }
        yield return(new WaitForSeconds(2.5f));

        if (SceneManager.GetActiveScene().buildIndex % 2 == 0)
        {
            music.source.clip   = music.clips[2];
            music.source.volume = 0.4f;
            music.source.Play();
        }
        else
        {
            music.source.clip   = music.clips[1];
            music.source.volume = 0.05f;
            music.source.Play();
        }
        j.SetRumble(0, 0, 0, 0);
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }
 ///<summary>
 ///Checks if a shoulder button was pressed and on which controller
 ///</summary>
 private void PushedButton()
 {
     if (joyconLeft != null && joyconRight != null)
     {
         if (!wasPushed && joyconRight.GetButton(Joycon.Button.SHOULDER_2))
         {
             PickUp();
             wasPushed = true;
             joyconLeft.SetRumble(160.0f, 320.0f, 0.6f, 1000);
             joyconRight.SetRumble(160.0f, 320.0f, 0.6f, 1000);
         }
         if (wasPushed && isHolding && joyconRight.GetButton(Joycon.Button.SHOULDER_1))
         {
             item.GetComponent <Rigidbody>().AddForce(tempParent.transform.forward * throwForce);
             joyconLeft.SetRumble(lowerLimit, upperLimit, amplitude, 1000);
             joyconRight.SetRumble(lowerLimit, upperLimit, amplitude, 1000);
             isHolding = false;
             wasPushed = false;
         }
     }
     else if (joyconLeft != null)
     {
         if (!wasPushed && joyconLeft.GetButton(Joycon.Button.SHOULDER_2))
         {
             PickUp();
             wasPushed = true;
             joyconLeft.SetRumble(160.0f, 320.0f, 0.6f, 1000);
         }
         if (wasPushed && isHolding && joyconLeft.GetButton(Joycon.Button.SHOULDER_1))
         {
             item.GetComponent <Rigidbody>().AddForce(tempParent.transform.forward * throwForce);
             joyconLeft.SetRumble(lowerLimit, upperLimit, amplitude, 1000);
             isHolding = false;
             wasPushed = false;
         }
     }
 }
예제 #19
0
 // Simulate a throw of a ball by decreasing rumble intensity, then increasing it again
 IEnumerator performRumble(Joycon throw_j, Joycon catch_j, float speed)
 {
     for (float val = 1f; val >= 0f; val -= (0.1f * Mathf.Max((2 - speed), 1f)))
     {
         throw_j.SetRumble(160, 320, val, 100);
         yield return(new WaitForSeconds(0.1f));
     }
     for (float val = 0f; val <= 1f; val += (0.2f * Mathf.Max((2 - speed), 1f)))
     {
         catch_j.SetRumble(160, 320, val, 100);
         yield return(new WaitForSeconds(0.1f));
     }
     isCon1 = !isCon1;
     inAir  = !inAir;
 }
        public void locBtnClick(object sender, EventArgs e)
        {
            Button bb = sender as Button;

            if (bb.Tag.GetType() == typeof(Button))
            {
                Button button = bb.Tag as Button;

                if (button.Tag.GetType() == typeof(Joycon))
                {
                    Joycon v = (Joycon)button.Tag;
                    v.SetRumble(20.0f, 400.0f, 1.0f, 300);
                }
            }
        }
예제 #21
0
 IEnumerator performRumbleSide(Joycon throw_j, Joycon catch_j, float speed)
 {
     for (float val = 1f; val >= 0f; val -= (0.1f * Mathf.Max((4 - speed), 1)))
     {
         if (val > .3f)
         {
             throw_j.SetRumble(160, 320, val, 100);
         }
         if (val < .5f)
         {
             catch_j.SetRumble(160, 320, 1 - (2 * val), 100);
         }
         yield return(new WaitForSeconds(0.1f));
     }
     isCon1 = !isCon1;
     inAir  = !inAir;
 }
예제 #22
0
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.name == "BounceCollider")
        {
            float   xTarget = Random.Range(-2f, 2f);
            float   yTarget = Random.Range(-2f, 2f);
            Vector3 target  = new Vector3(xTarget, yTarget, 0);
            collision.transform.parent.GetComponent <Player>().isBouncing    = true;
            collision.transform.parent.GetComponent <Rigidbody2D>().velocity = (target - collision.transform.position).normalized * bang;
            AkSoundEngine.PostEvent("Play_bounce", Camera.main.gameObject);

            if (main.joycons.Count > 0)
            {
                Joycon j = main.joycons[main.currentJoyconPlayer];
                j.SetRumble(0.05f, 0.1f, 0.5f);
                Invoke("BreakRumbles", 0.05f);
            }
        }
    }
예제 #23
0
    private void Update()
    {
        //m_joyconL.SetRumble( 160, 320, 0.6f, 200 ); // 振動
        m_pressedButtonL = null;
        m_pressedButtonR = null;

        if (m_joyconL.GetButtonDown(Joycon.Button.DPAD_RIGHT))
        {
            //	number = Random.Range(0, Train.Length);

            Instantiate(Train[0], transform.position, transform.rotation);
            // 右ボタンが押された
            //	number = Random.Range(0, Train.Length);

            //Instantiate(Train[number], transform.position, transform.rotation);
        }

        if (m_joycons == null || m_joycons.Count <= 0)
        {
            return;
        }

        foreach (var button in m_buttons)
        {
            if (m_joyconL.GetButton(button))
            {
                m_pressedButtonL = button;
            }
            if (m_joyconR.GetButton(button))
            {
                m_pressedButtonR = button;
            }
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            m_joyconL.SetRumble(160, 320, 0.6f, 200);
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            m_joyconR.SetRumble(160, 320, 0.6f, 200);
        }
    }
예제 #24
0
    // Update is called once per frame
    void Update()
    {
        stick = j.GetStick();
        gyro  = j.GetGyro();
        accel = j.GetAccel();
        if (FixableItemController.locked)
        {
            if ((Input.GetKeyDown(KeyCode.Return) || accel.magnitude > 3) && locked && dragonImage.fillAmount >= 0.75f)
            {
                locked = !locked;
                dragCon.flameFill.fillAmount -= 0.01f;
            }
            else if (dragonImage.fillAmount <= 0f && !locked)
            {
                t = 0;
                powerBar.value = 0;
                locked         = !locked;
            }
            else if ((Input.GetKeyDown(KeyCode.Return) || accel.magnitude > 3) && dragonImage.fillAmount > 0f)
            {
                dragCon.flameFill.fillAmount -= 0.01f;

                j.SetRumble(50, 50, 5.0f, 1000);
                if (powerBar.value >= sweetSpotMin && powerBar.value <= sweetSpotMax)
                {
                    Debug.Log("BING - GOOD");
                    GameController.overallGameScore += 1;
                    Debug.Log("Score: " + GameController.overallGameScore);
                }
                else
                {
                    Debug.Log("BONG - BAD");
                }
            }

            if (!locked)
            {
                t += Time.deltaTime;
                powerBar.value = Mathf.Abs(Mathf.Sin(t));
            }
        }
    }
예제 #25
0
    private void Update()
    {
        m_pressedButtonL = null;
        m_pressedButtonR = null;

        if (m_joycons == null || m_joycons.Count <= 0)
        {
            return;
        }

        SetControllers();

        foreach (var button in m_buttons)
        {
            if (m_joyconL.GetButton(button))
            {
                m_pressedButtonL = button;
            }
            if (m_joyconR.GetButton(button))
            {
                m_pressedButtonR = button;
            }
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            m_joyconL.SetRumble(160, 320, 0.6f, 200);
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            m_joyconR.SetRumble(160, 320, 0.6f, 200);
        }

        for (int i = 0; i < isShake.Length; i++)
        {
            if (isShake[i])
            {
                SendDisturb(i);
            }
        }
    }
예제 #26
0
 // Update is called once per frame
 void Update()
 {
     if (joycons.Count > 0)
     {
         gyro = j.GetGyro();
         if ((!initpump) && gyro.y >= yinit + 5)
         {
             Debug.Log("Action de pompage initialisé.");
             initpump = true;
         }
         if (initpump && gyro.y <= yinit - 5)
         {
             Debug.Log("De l'air est envoyé !");
             //initpump = false;
             gameObject.transform.localScale += new Vector3(0.1f, 0.1f, 0.1f);
             SphereRadius = gameObject.transform.localScale.y;
             radius       = SphereRadius;
         }
         else if (SphereRadius > BaseRadius)
         {
             gameObject.transform.localScale -= new Vector3(0.01f, 0.01f, 0.01f);
             SphereRadius = gameObject.transform.localScale.y;
             radius       = SphereRadius;
         }
         if (SphereRadius != -1)
         {
             if (SphereRadius >= 5)
             {
                 Debug.Log("La sphère éclate !");
                 j.SetRumble(160f, 320f, 0.6f, 550);
                 Destroy(gameObject);
                 Application.Quit();
             }
         }
     }
 }
    void OnTriggerStay2D(Collider2D theCol)
    {
        Joycon j = joycons [jc_ind];

        if (theCol.gameObject.CompareTag("SonObj"))
        {
            //Debug.Log("THIS IS THE BODY");
            //Debug.Log(Vector3.Dot(theCol.transform.up, transform.up));
            if (Vector3.Dot(theCol.transform.up, transform.up) <= -Threshold)
            {
                if (j.GetButtonDown(Joycon.Button.SHOULDER_2) && !isCuttingAnim)
                {
                    Debug.Log("Shoulder button 2 pressed");
                    j.SetRumble(160, 320, 0.6f, 200);
                    Destroy(theCol.gameObject);
                    isCuttingAnim = true;
                }
                else
                {
                    isCuttingAnim = false;
                }
            }
        }
    }
예제 #28
0
    void JoyconMethod()
    {
        // make sure the Joycon only gets checked if attached
        if (joycons.Count > 0)
        {
            Joycon j = joycons [jc_ind];


            // GetButtonDown checks if a button has been pressed (not held)
            if (canSpawnSpriteMask)
            {
                if (j.GetButtonDown(Joycon.Button.SHOULDER_2) && !isCuttingAnim)
                {
                    //Debug.Log ("Shoulder button 2 pressed");
                    j.SetRumble(160, 320, 0.6f, 200);
                    Shrink spriteMask = Instantiate(spriteMaskPrefab, transform.position, transform.rotation);
                    spriteMask.playerRedController = this;
                    numOfMasksSpawnable--;
                    isCuttingAnim = true;
                    audio.Play();
                }
            }


            // GetButtonDown checks if a button has been released
            if (j.GetButtonUp(Joycon.Button.SHOULDER_2))
            {
                //Debug.Log ("Shoulder button 2 released");
                isCuttingAnim = false;
            }
            // GetButtonDown checks if a button is currently down (pressed or held)
            if (j.GetButton(Joycon.Button.SHOULDER_2))
            {
                //Debug.Log ("Shoulder button 2 held");
            }

            if (j.GetButtonDown(Joycon.Button.DPAD_DOWN))
            {
                //Debug.Log ("Rumble");

                // Rumble for 200 milliseconds, with low frequency rumble at 160 Hz and high frequency rumble at 320 Hz. For more information check:
                // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md

                //j.SetRumble (160, 320, 0.6f, 200);

                // The last argument (time) in SetRumble is optional. Call it with three arguments to turn it on without telling it when to turn off.
                // (Useful for dynamically changing rumble values.)
                // Then call SetRumble(0,0,0) when you want to turn it off.
            }

            stick = j.GetStick();

            // Gyro values: x, y, z axis values (in radians per second)
            gyro = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = j.GetAccel();

            orientation = j.GetVector();

            if (j.GetButton(Joycon.Button.DPAD_UP))
            {
                transform.Translate(0f, moveSpeedY, 0f, Space.World);
            }
            else
            {
            }

            if (j.GetButton(Joycon.Button.DPAD_DOWN))
            {
                transform.Translate(0f, -moveSpeedY, 0f, Space.World);
            }
            else
            {
            }

            if (j.GetButton(Joycon.Button.DPAD_LEFT))
            {
                transform.Translate(-moveSpeedX, 0f, 0f, Space.World);
            }
            else
            {
            }

            if (j.GetButton(Joycon.Button.DPAD_RIGHT))
            {
                transform.Translate(moveSpeedX, 0f, 0f, Space.World);
            }
            else
            {
            }

            float   zOnly  = orientation.eulerAngles.z;
            Vector3 newRot = new Vector3(gameObject.transform.localRotation.x, gameObject.transform.localRotation.y, zOnly);
            //gameObject.transform.eulerAngles = newRot;


            Quaternion targetRotation = Quaternion.Euler(newRot);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, degreesPerSec * Time.deltaTime);

            //gameObject.transform.rotation = orientation;
        }
    }
예제 #29
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (joycons.Count > 0)
        {
            Joycon j = joycons [jc_ind];
            // GetButtonDown checks if a button has been pressed (not held)
            if (j.GetButtonDown(Joycon.Button.SHOULDER_2))
            {
                tilting = true;
                Debug.Log("Shoulder button 2 pressed");
                // GetStick returns a 2-element vector with x/y joystick components
                Debug.Log(string.Format("Stick x: {0:N} Stick y: {1:N}", j.GetStick()[0], j.GetStick()[1]));

                // Joycon has no magnetometer, so it cannot accurately determine its yaw value. Joycon.Recenter allows the user to reset the yaw value.
                j.Recenter();
            }
            // GetButtonDown checks if a button has been released
            if (j.GetButtonUp(Joycon.Button.SHOULDER_2))
            {
                tilting = false;
                Debug.Log("Shoulder button 2 released");
            }
            // GetButtonDown checks if a button is currently down (pressed or held)
            if (j.GetButton(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 held");
            }

            if (j.GetButtonDown(Joycon.Button.DPAD_DOWN))
            {
                Debug.Log("Rumble");

                // Rumble for 200 milliseconds, with low frequency rumble at 160 Hz and high frequency rumble at 320 Hz. For more information check:
                // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md

                j.SetRumble(160, 320, 0.6f, 200);
                transform.position = Vector3.Lerp(transform.position, new Vector3(0, 0, transform.position.z), 1f);

                // The last argument (time) in SetRumble is optional. Call it with three arguments to turn it on without telling it when to turn off.
                // (Useful for dynamically changing rumble values.)
                // Then call SetRumble(0,0,0) when you want to turn it off.
            }

            stick = j.GetStick();

            // Gyro values: x, y, z axis values (in radians per second)
            gyro = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = j.GetAccel();

            orientation = j.GetVector();

            if (tilting)
            {
                transform.rotation = new Quaternion(0f, 0f, orientation.z, orientation.w);
            }

            else
            {
                transform.rotation = new Quaternion(0, 0, 0, 0);
                transform.Translate(new Vector3(gyro.z, gyro.y, 0) * Time.deltaTime * speed, Space.World);
            }
        }
    }
예제 #30
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (joycons.Count > 0)
        {
            Joycon j = joycons[jc_ind];
            // GetButtonDown checks if a button has been pressed (not held)
            if (j.GetButtonDown(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 pressed");
                // GetStick returns a 2-element vector with x/y joystick components
                Debug.Log(string.Format("Stick x: {0:N} Stick y: {1:N}", j.GetStick()[0], j.GetStick()[1]));

                // Joycon has no magnetometer, so it cannot accurately determine its yaw value. Joycon.Recenter allows the user to reset the yaw value.
                j.Recenter();
            }
            // GetButtonDown checks if a button has been released
            if (j.GetButtonUp(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 released");
            }
            // GetButtonDown checks if a button is currently down (pressed or held)
            //Sets win condition
            if (joycons[0].GetButton(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 held");
                for (int x = 0; x < joycons.Count; x++)
                {
                    if (j.GetButton(Joycon.Button.SHOULDER_2))
                    {
                        winner = jc_ind;
                        Debug.Log(winner);
                    }
                }
            }

            if (j.GetButtonDown(Joycon.Button.DPAD_DOWN))
            {
                Debug.Log("Rumble");

                // Rumble for 200 milliseconds, with low frequency rumble at 160 Hz and high frequency rumble at 320 Hz. For more information check:
                // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md

                j.SetRumble(160, 320, 0.6f, 200);

                // The last argument (time) in SetRumble is optional. Call it with three arguments to turn it on without telling it when to turn off.
                // (Useful for dynamically changing rumble values.)
                // Then call SetRumble(0,0,0) when you want to turn it off.
            }

            stick = j.GetStick();

            // Gyro values: x, y, z axis values (in radians per second)
            gyro = j.GetGyro();

            // Accel values:  x, y, z axis values (in Gs)
            accel = j.GetAccel();


            //sends out rumble signal if movement is sensed
            //determines whether someone needs to go back or not
            if (gyro.x >= 1 || gyro.y >= 1 || gyro.z >= 1 || accel.x >= 1 || accel.y >= 1 || accel.z >= 1 && isRed == true)
            //Debug.Log(jc_ind + "go back");
            {
                whoGoesBack = jc_ind;
                j.SetRumble(160, 320, 0.6f, 200);
                someoneGoesBack = true;
            }
            else
            {
                someoneGoesBack = false;
            }


            orientation = j.GetVector();
            if (j.GetButton(Joycon.Button.DPAD_UP) && jc_ind == 0)
            {
                gameObject.GetComponent <Renderer>().material.color = Color.green;
                isRed = true;
                Debug.Log("dragon is asleep");
            }
            else
            {
                gameObject.GetComponent <Renderer>().material.color = Color.red;
                isRed = true;
                Debug.Log("dragon is awake");
            }
            //gameObject.transform.rotation = orientation;
        }
    }