예제 #1
0
    /* On passe d'un mode à l'autre par simple pression d'un bouton. */
    void ChangementMode()
    {
        if (selection != null && (Input.GetButtonUp("Mode") || (j != null && j.GetButtonUp(Joycon.Button.SR))))
        {
            if (mode == (int)Modes.DEPLACEMENT)
            {
                mode = (int)Modes.OBSERVATION;
                selection.GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
                selection.AddComponent <Observation>();                           // On ajoute ce script à l'objet sélectionné.

                cam.GetComponent <CameraScript>().offset = new Vector3(0, 0, -3); // On rapproche la caméra de l'objet.
            }
            else if (mode == (int)Modes.OBSERVATION && selection.tag == "Modifiable")
            {
                mode = (int)Modes.MODIFICATION;
                Destroy(selection.GetComponent <Observation>());                          // On retire ce script de l'objet sélectionné.
                selection.GetComponent <ChangeMesh>().setSelected(true);
                sommet        = selection.GetComponent <ChangeMesh>().getCurrentVertex(); // On récupère le premier sommet de la liste.
                couleurSommet = sommet.GetComponent <MeshRenderer>().material.color;      // On récupère sa couleur de base.
                sommet.GetComponent <MeshRenderer>().material.color = Color.yellow;       // On attribue une couleur de sélection.
            }
            else
            {
                mode = (int)Modes.DEPLACEMENT;
                cam.GetComponent <CameraScript>().offset = new Vector3(0, 2, -5); // On remet la caméra à sa place.
                Destroy(selection.GetComponent <Observation>());                  // On retire ce script à l'objet sélectionné.
                if (selection.GetComponent <ChangeMesh>() != null)
                {
                    selection.GetComponent <ChangeMesh>().setSelected(false);            // On déselectionne le gameObject.
                    sommet.GetComponent <MeshRenderer>().material.color = couleurSommet; // On remet la couleur de base au sommet.
                    sommet.GetComponent <Vertex>().setSelected(false);                   // On déselectionne le sommet si sélectionné.
                }
            }
        }
    }
예제 #2
0
 /* On passe d'un mode à l'autre par simple pression d'un bouton. */
 void ChangementMode()
 {
     if (selection != null && j.GetButtonUp(Joycon.Button.SR))
     {
         if (mode == (int)Modes.DEPLACEMENT)
         {
             mode = (int)Modes.OBSERVATION;
             selection.AddComponent <Observation>(); // On ajoute ce script à l'objet sélectionné.
         }
         else if (mode == (int)Modes.OBSERVATION && selection.tag == "Modifiable")
         {
             mode = (int)Modes.MODIFICATION;
             Destroy(selection.GetComponent <Observation>()); // On retire ce script à l'objet sélectionné.
             selection.GetComponent <ChangeMesh>().setSelected(true);
             /* */
         }
         else
         {
             mode = (int)Modes.DEPLACEMENT;
             Destroy(selection.GetComponent <Observation>()); // On retire ce script à l'objet sélectionné.
             if (selection.GetComponent <ChangeMesh>() != null)
             {
                 selection.GetComponent <ChangeMesh>().setSelected(false);
             }
         }
     }
 }
예제 #3
0
    void FixedUpdate()
    {
        if (joycons.Count > 0)
        {
            Joycon j = joycons [jc_ind];
            if (j.GetButtonUp(Joycon.Button.SHOULDER_2))
            {
                Debug.Log("Shoulder button 2 released");
                rb.useGravity = true;
                //Debug.Log (transform.forward);
                accel = j.GetAccel();

                Debug.Log(accel);
                // Joycon x axis is the same as Unity's y axis
                float upForce = System.Math.Abs(accel.x);
                // Joycon z axis is the same as Unity's z axis
                float   forwardForce = System.Math.Abs(accel.z);
                Vector3 force        = new Vector3(0, upForce, forwardForce) * thrust;
                rb.AddForce(force);
            }
            if (j.GetButtonDown(Joycon.Button.DPAD_UP))
            {
                reset();
            }
        }
    }
예제 #4
0
 void FixedUpdate()
 {
     if (joycons.Count > 0)
     {
         Joycon j = joycons [jc_ind];
         if (j.GetButtonUp(Joycon.Button.SHOULDER_2))
         {
             ActiveBag.Throw(j);
         }
         if (j.GetButtonDown(Joycon.Button.DPAD_UP))
         {
             ActiveBag.Reset();
         }
         if (j.GetButton(Joycon.Button.DPAD_LEFT))
         {
             ActiveBag.Move(false);
         }
         if (j.GetButton(Joycon.Button.DPAD_RIGHT))
         {
             ActiveBag.Move(true);
         }
         if (j.GetButtonDown(Joycon.Button.DPAD_DOWN))
         {
             ActiveBag = gameObject.AddComponent <Application.Bag>();
         }
         // if (j.GetButton(Joycon.Button.STICK)) {
         //  var stickX = j.GetStick()[0];
         //  if (Mathf.Abs(stickX) > 0.2) {
         //      rotateBag(stickX);
         //  }
         // }
     }
 }
예제 #5
0
        protected virtual void SplashInput()
        {
            if (transform.tag == "Player1" && JoycoCount > 0)
            {
                if (Joycon1_Right.GetButtonDown(Joycon.Button.DPAD_RIGHT) || Input.GetKeyDown(splashInput))
                {
                    cc.Splash(true);
                }
                else if (Joycon1_Right.GetButtonUp(Joycon.Button.DPAD_RIGHT) || Input.GetKeyUp(splashInput))
                {
                    cc.Splash(false);
                }

                //if (Input.GetKeyDown(splashInput) || Input.GetKeyDown(KeyCode.JoystickButton0))
                //    cc.Splash(true);
                //else if (Input.GetKeyUp(splashInput) || Input.GetKeyUp(KeyCode.JoystickButton0))
                //    cc.Splash(false);
            }
            else if (transform.tag == "Player2" && JoycoCount == 4)
            {
                if (Joycon2_Right.GetButtonDown(Joycon.Button.DPAD_RIGHT))
                {
                    cc.Splash(true);
                }
                else if (Joycon2_Right.GetButtonUp(Joycon.Button.DPAD_RIGHT))
                {
                    cc.Splash(false);
                }
            }
            else
            {
                if (Input.GetKeyDown(splashInput))
                {
                    cc.Splash(true);
                }
                else if (Input.GetKeyUp(splashInput))
                {
                    cc.Splash(false);
                }
            }
            //if (m_Input.GetComponent<JoyconInput>().GetTrigger(Joycon.Button.DPAD_RIGHT, m_PlayerIdx, false))
            //{
            //    Debug.Log("s");
            //}
        }
예제 #6
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);
        }
    }
예제 #7
0
 public bool GetKeyUp(Joycon.Button button, bool isLeft)
 {
     if (isLeft)
     {
         return(m_joyconL.GetButtonUp(button));
     }
     else
     {
         return(m_joyconR.GetButtonUp(button));
     }
 }
예제 #8
0
 public void TranslateArm()
 {
     if (currentJoycon.GetButtonDown(Joycon.Button.DPAD_UP))
     {
         isTranslateArm     = true;
         transform.position = endCourse.transform.position;
     }
     else if (currentJoycon.GetButtonUp(Joycon.Button.DPAD_UP))
     {
         isTranslateArm     = false;
         transform.position = initPosition;
     }
 }
예제 #9
0
 public void UseCameraButton()
 {
     // make sure the Joycon only gets checked if attached
     if (joycons.Count > 0)
     {
         Joycon j = joycons [jc_ind];
         if (j.GetButtonDown(Joycon.Button.SHOULDER_1))
         {
             // Joycon has no magnetometer, so it cannot accurately determine its yaw value. Joycon.Recenter allows the user to reset the yaw value.
             manager.RecalibrateJoycons();
             SetCanMove(false);
         }
         else if (j.GetButtonUp(Joycon.Button.SHOULDER_1))
         {
             manager.RecalibrateJoycons();
             SetCanMove(true);
         }
     }
 }
예제 #10
0
 // Update is called once per frame
 void Update()
 {
     if (jd != null)
     {
         //Bouton A (Joycon Droit)
         if (jd.GetButtonDown(Joycon.Button.DPAD_RIGHT))
         {
             if ((!rs) && (!us))
             {
                 StartCoroutine("retractSupport");
             }
         }
         if (jd.GetButtonUp(Joycon.Button.DPAD_RIGHT))
         {
             if (!us)
             {
                 StopCoroutine("retractSupport");
                 if (rs)
                 {
                     rs = false;
                 }
                 StartCoroutine("unleashSupport");
             }
         }
         if (gameObject.transform.position.y > spawnPos.y)
         {
             //On replace le palet exactement à sa position initiale (pour éviter que la bille ne se trouve
             //en dessous du palet lors de sa réapparition suite à une défaite)
             gameObject.transform.position = spawnPos;
         }
     }
     else
     {
         jd = grandfather.getRightJoycon();
     }
 }
예제 #11
0
파일: soul.cs 프로젝트: yuyuran/project
    // Update is called once per frame
    void Update()
    {
        Debug.Log(base.state);

        // 進行方向をカメラと同期させる
        //   gameObject.transform.rotation = Soulcamera.transform.rotation;

        //  回転を制限
        gameObject.transform.position = new Vector3(gameObject.transform.position.x, Mathf.Clamp(gameObject.transform.position.y, 0, 0), gameObject.transform.position.z);

        // HPを更新
        hpber.value = soulHP;

        // 前進(joyconR-ZR)
        if (m_joyconR.GetButtonDown(Joycon.Button.SHOULDER_2))
        {
            soulVel = 0.08f; text.text = "前進!";
        }
        if (m_joyconR.GetButtonUp(Joycon.Button.SHOULDER_2))
        {
            soulVel = 0.00f; text.text = "停止中";
        }

        // 憑依状態でYを押すと憑依解除
        if (base.state == CONDITION.POSSESSION && m_joyconR.GetButton(Joycon.Button.DPAD_LEFT))
        {
            //number.transform.parent = null;
            // soulConditionFlag = false;
            base.state = CONDITION.NORMAL;
            number.GetComponent <numbers>().SetCondition(CONDITION.NOTPOSSESSION);
        }

        gameObject.transform.localRotation = new Quaternion(0, -m_joyconL.GetVector().z, 0, m_joyconL.GetVector().w);

        gameObject.transform.Translate(0, 0, soulVel);
    }
예제 #12
0
    public static void SetControllerJoycon(Joycon joycon)
    {
        if (joycon.isLeft)
        {
            GetButtonDown = (code) =>
            {
                if (!actionEnabled)
                {
                    return(false);
                }
                switch (code)
                {
                case ButtonCode.Jump:
                    return(joycon.GetButtonDown(Joycon.Button.DPAD_LEFT));

                case ButtonCode.UpArrow:
                    if (beforeVerticalValue <= 0)
                    {
                        return(joycon.GetStick()[0] > 0);
                    }
                    return(false);

                case ButtonCode.DownArrow:
                    if (beforeVerticalValue >= 0)
                    {
                        return(joycon.GetStick()[0] < 0);
                    }
                    return(false);

                case ButtonCode.LeftArrow:
                    if (beforeHorizontalValue <= 0)
                    {
                        return(joycon.GetStick()[1] > 0);
                    }
                    return(false);

                case ButtonCode.RightArrow:
                    if (beforeHorizontalValue >= 0)
                    {
                        return(joycon.GetStick()[1] < 0);
                    }
                    return(false);

                case ButtonCode.Cancel:
                    return(joycon.GetButtonDown(Joycon.Button.DPAD_DOWN));
                }
                return(false);
            };

            GetButton = (code) =>
            {
                if (!actionEnabled)
                {
                    return(false);
                }
                switch (code)
                {
                case ButtonCode.Jump:
                    return(joycon.GetButton(Joycon.Button.DPAD_LEFT));

                case ButtonCode.UpArrow:
                    return(joycon.GetStick()[0] > deadline);

                case ButtonCode.DownArrow:
                    return(joycon.GetStick()[0] < -deadline);

                case ButtonCode.LeftArrow:
                    return(joycon.GetStick()[1] > deadline);

                case ButtonCode.RightArrow:
                    return(joycon.GetStick()[1] < -deadline);

                case ButtonCode.Cancel:
                    return(joycon.GetButton(Joycon.Button.DPAD_DOWN));
                }
                return(false);
            };

            GetButtonUp = (code) =>
            {
                if (!actionEnabled)
                {
                    return(false);
                }
                switch (code)
                {
                case ButtonCode.Jump:
                    return(joycon.GetButtonUp(Joycon.Button.DPAD_LEFT));

                case ButtonCode.UpArrow:
                    if (beforeVerticalValue > 0)
                    {
                        return(joycon.GetStick()[0] <= 0);
                    }
                    return(false);

                case ButtonCode.DownArrow:
                    if (beforeVerticalValue < 0)
                    {
                        return(joycon.GetStick()[0] >= 0);
                    }
                    return(false);

                case ButtonCode.LeftArrow:
                    if (beforeHorizontalValue > 0)
                    {
                        return(joycon.GetStick()[1] <= 0);
                    }
                    return(false);

                case ButtonCode.RightArrow:
                    if (beforeHorizontalValue < 0)
                    {
                        return(joycon.GetStick()[1] >= 0);
                    }
                    return(false);

                case ButtonCode.Cancel:
                    return(joycon.GetButtonUp(Joycon.Button.DPAD_DOWN));
                }
                return(false);
            };
        }
        else
        {
            GetButtonDown = (code) =>
            {
                if (!actionEnabled)
                {
                    return(false);
                }
                switch (code)
                {
                case ButtonCode.Jump:
                    return(joycon.GetButtonDown(Joycon.Button.DPAD_RIGHT));

                case ButtonCode.UpArrow:
                    if (beforeVerticalValue >= 0)
                    {
                        return(joycon.GetStick()[0] < 0);
                    }
                    return(false);

                case ButtonCode.DownArrow:
                    if (beforeVerticalValue <= 0)
                    {
                        return(joycon.GetStick()[0] > 0);
                    }
                    return(false);

                case ButtonCode.LeftArrow:
                    if (beforeHorizontalValue >= 0)
                    {
                        return(joycon.GetStick()[1] < 0);
                    }
                    return(false);

                case ButtonCode.RightArrow:
                    if (beforeHorizontalValue <= 0)
                    {
                        return(joycon.GetStick()[1] > 0);
                    }
                    return(false);

                case ButtonCode.Cancel:
                    return(joycon.GetButtonDown(Joycon.Button.DPAD_UP));
                }
                return(false);
            };

            GetButton = (code) =>
            {
                if (!actionEnabled)
                {
                    return(false);
                }
                switch (code)
                {
                case ButtonCode.Jump:
                    return(joycon.GetButton(Joycon.Button.DPAD_RIGHT));

                case ButtonCode.UpArrow:
                    return(joycon.GetStick()[0] < -deadline);

                case ButtonCode.DownArrow:
                    return(joycon.GetStick()[0] > deadline);

                case ButtonCode.LeftArrow:
                    return(joycon.GetStick()[1] < -deadline);

                case ButtonCode.RightArrow:
                    return(joycon.GetStick()[1] > deadline);

                case ButtonCode.Cancel:
                    return(joycon.GetButton(Joycon.Button.DPAD_UP));
                }
                return(false);
            };

            GetButtonUp = (code) =>
            {
                if (!actionEnabled)
                {
                    return(false);
                }
                switch (code)
                {
                case ButtonCode.Jump:
                    return(joycon.GetButtonUp(Joycon.Button.DPAD_RIGHT));

                case ButtonCode.UpArrow:
                    if (beforeVerticalValue < 0)
                    {
                        return(joycon.GetStick()[0] >= 0);
                    }
                    return(false);

                case ButtonCode.DownArrow:
                    if (beforeVerticalValue > 0)
                    {
                        return(joycon.GetStick()[0] <= 0);
                    }
                    return(false);

                case ButtonCode.LeftArrow:
                    if (beforeHorizontalValue < 0)
                    {
                        return(joycon.GetStick()[1] >= 0);
                    }
                    return(false);

                case ButtonCode.RightArrow:
                    if (beforeHorizontalValue > 0)
                    {
                        return(joycon.GetStick()[1] <= 0);
                    }
                    return(false);

                case ButtonCode.Cancel:
                    return(joycon.GetButtonUp(Joycon.Button.DPAD_UP));
                }
                return(false);
            };
        }
    }
예제 #13
0
    // Update is called once per frame
    void Update()
    {
        if (GameFlowManager.Instance.GameOver)
        {
            return;
        }

#if !KEYBOARD_MODE
        // 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();
            //}

            //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.
            //}

            //if (j.GetButtonDown(Joycon.Button.DPAD_LEFT))
            //{
            //    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

            //    int low_freq = Random.Range(100, 150);
            //    int high_freq = Random.Range(320, 500);
            //    float amp = Random.Range(0.5f, 1f);
            //    int time = Random.Range(100, 500);
            //    j.SetRumble(low_freq, high_freq, amp, time);

            //    // 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)
            oldAccel = accel;
            accel    = j.GetAccel();

            orientation = j.GetVector();
            var   position    = transform.position;
            float sensitivity = this.sensitivity / 1000;
            position.x += stick[0] * sensitivity;
            position.z += stick[1] * sensitivity;

            ClampPosition(ref position);

            hover1.UpdateRotation = false;
            hover2.UpdateRotation = false;

            if (handState == HandState.Idle)
            {
                if (j.GetButtonDown(Joycon.Button.SHOULDER_2))
                {
                    holdingButton  = Joycon.Button.SHOULDER_2;
                    startPressTime = Time.time;
                }
                else if (j.GetButtonDown(Joycon.Button.STICK))
                {
                    holdingButton  = Joycon.Button.STICK;
                    startPressTime = Time.time;
                }
                else if (holdingButton != Joycon.Button.CAPTURE)
                {
                    if (j.GetButtonUp(holdingButton))
                    {
                        holdingButton  = Joycon.Button.CAPTURE;
                        handState      = HandState.GoingDown;
                        startPressTime = 0;
                    }
                    else if (holdingSomethingYeetable && Time.time - startPressTime > holdDurationRequirement)
                    {
                        handState      = HandState.ChargingYeet;
                        startPressTime = 0;
                    }
                }
                //if (j.GetButton(Joycon.Button.SHOULDER_1))
                //{
                //    handState = HandState.GoingDown;
                //}
                //else if (holdingSomethingYeetable && j.GetButton(Joycon.Button.SHOULDER_2))
                //{
                //    handState = HandState.ChargingYeet;
                //}
            }

            if (handState == HandState.ChargingYeet)
            {
                if (j.GetButton(holdingButton))
                {
                    yeetingPower += (oldAccel - accel).magnitude;
                    yeetingPower  = Mathf.Clamp(yeetingPower, 0, MAX_YEETING_POWER);

                    var yeetNormalized = Mathf.Clamp01(yeetingPower / MAX_YEETING_POWER);
                    var yoteMax        = Mathf.Lerp(80, 320, yeetNormalized);
                    var yoteMin        = Mathf.Lerp(80, 160, yeetNormalized);
                    j.SetRumble(yoteMin, yoteMax, 0.6f);
                }
                else if (j.GetButtonUp(holdingButton))
                {
                    holdingButton = Joycon.Button.CAPTURE;

                    //Debug.LogFormat("Yoting {0}", yeetingPower);
                    handState = HandState.Yeeting;

                    var yeetNormalized = Mathf.Clamp01(yeetingPower / MAX_YEETING_POWER);
                    var yoteMax        = Mathf.Lerp(80, 320, yeetNormalized);
                    var yoteMin        = Mathf.Lerp(80, 160, yeetNormalized);
                    j.SetRumble(yoteMin, yoteMax, 0.6f, 200);

                    var direction = ourPosition.position.x <= opponentPosition.position.x;
                    if (yeetDirection != direction)
                    {
                        yeetRotMin *= -1;
                        yeetRotMax *= -1;
                    }
                    yeetDirection = direction;
                }
            }

            if (handState == HandState.GoingDown)
            {
                position.y -= descentSpeed * Time.deltaTime;

                var grabbyPointPosition = grabbyPoint.localPosition;
                grabbyPointPosition.y    -= descentSpeed * grabbySpeedIncrement * Time.deltaTime;
                grabbyPoint.localPosition = grabbyPointPosition;

                var positionTraveled = Mathf.InverseLerp(MaxDescentPosition, OriginalYPosition, position.y);
                materialOffset.y = GetTextureOffsetModifier(positionTraveled);
                //Debug.LogFormat("GoingDown: Position Traveled = {0} => Mat offset = {1}", positionTraveled, materialOffset.y);
                material.mainTextureOffset = materialOffset;

                if (position.y <= MaxDescentPosition)
                {
                    position.y = MaxDescentPosition;
                    DetectObjectCollision();
                    handState = HandState.GoingUp;

                    materialOffset.y           = 0;
                    material.mainTextureOffset = materialOffset;
                }
            }
            else if (handState == HandState.GoingUp)
            {
                position.y += ascentSpeed * Time.deltaTime;

                var grabbyPointPosition = grabbyPoint.localPosition;
                grabbyPointPosition.y += ascentSpeed * grabbySpeedIncrement * Time.deltaTime;

                var positionTraveled = Mathf.InverseLerp(MaxDescentPosition, OriginalYPosition, position.y);
                materialOffset.y = GetTextureOffsetModifier(positionTraveled);
                //Debug.LogFormat("GoingUp: Position Traveled = {0} => Mat offset = {1}", positionTraveled, materialOffset.y);
                material.mainTextureOffset = materialOffset;

                if (position.y >= OriginalYPosition)
                {
                    position.y = OriginalYPosition;
                    handState  = HandState.Idle;

                    materialOffset.y           = -0.5f;
                    material.mainTextureOffset = materialOffset;
                    grabbyPointPosition.y      = grabbyYOriginalPoint;
                }

                grabbyPoint.localPosition = grabbyPointPosition;
            }
            else if (handState == HandState.Yeeting)
            {
                var rotation = yeetingContrainerTransform.rotation;
                var euler    = rotation.eulerAngles;
                yeetingRotationTimer += Time.deltaTime;
                var delta = Mathf.Clamp01(yeetingRotationTimer / yeetingRotationMaxTime);

                if (delta >= 1)
                {
                    handState            = HandState.Idle;
                    yeetingRotationTimer = 0f;
                    euler.z      = yeetRotOriginal;
                    yeetingPower = 0;

                    AudioManager.Instance.PlayYeet();
                }
                else
                {
                    euler.z = Mathf.Lerp(yeetRotMin, yeetRotMax, delta);
                }

                if (delta > 0.8f && currentMergeableObject != null)
                {
                    currentMergeableObject.transform.SetParent(null);
                    currentMergeableObject.hoverScript.UpdateRotation = true;
                    currentMergeableObject.YeetToPosition.YeetInit(currentMergeableObject.transform.position, opponent.backCloud, 30, 0.5f);
                    currentMergeableObject.YeetToPosition.Yeet(Mathf.RoundToInt(currentMergeableObject.Damage * yeetingPower), onYeetEvent);
                    currentMergeableObject = null;
                }

                rotation.eulerAngles = euler;
                yeetingContrainerTransform.rotation = rotation;
            }
            else if (handState == HandState.ChargingYeet)
            {
                hover1.UpdateRotation = true;
                hover2.UpdateRotation = true;
            }

            transform.position = position;
        }
#endif
#if UNITY_EDITOR && KEYBOARD_MODE
        else
        {
            var   position    = transform.position;
            float sensitivity = this.sensitivity / 1000;
            position.x += Input.GetAxis("Horizontal") * sensitivity;
            position.z += Input.GetAxis("Vertical") * sensitivity;

            ClampPosition(ref position);

            hover1.UpdateRotation = false;
            hover2.UpdateRotation = false;

            if (handState == HandState.Idle)
            {
                if (Input.GetKeyDown(KeyCode.LeftControl))
                {
                    handState = HandState.GoingDown;
                }
                else if (holdingSomethingYeetable && Input.GetKeyDown(KeyCode.Space))
                {
                    handState = HandState.ChargingYeet;
                }
            }

            if (handState == HandState.ChargingYeet)
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    yeetingPower += (oldAccel - accel).magnitude;
                    yeetingPower  = Mathf.Clamp(yeetingPower, 0, MAX_YEETING_POWER);

                    var yeetNormalized = Mathf.Clamp01(yeetingPower / MAX_YEETING_POWER);
                    var yoteMax        = Mathf.Lerp(80, 320, yeetNormalized);
                    var yoteMin        = Mathf.Lerp(80, 160, yeetNormalized);
                }
                else if (Input.GetKeyUp(KeyCode.Space))
                {
                    //Debug.LogFormat("Yoting {0}", yeetingPower);
                    handState = HandState.Yeeting;

                    var yeetNormalized = Mathf.Clamp01(yeetingPower / MAX_YEETING_POWER);
                    var yoteMax        = Mathf.Lerp(80, 320, yeetNormalized);
                    var yoteMin        = Mathf.Lerp(80, 160, yeetNormalized);

                    var direction = ourPosition.position.x <= opponentPosition.position.x;
                    if (yeetDirection != direction)
                    {
                        yeetRotMin *= -1;
                        yeetRotMax *= -1;
                    }
                    yeetDirection = direction;
                }
            }

            if (handState == HandState.GoingDown)
            {
                position.y -= descentSpeed * Time.deltaTime;

                var grabbyPointPosition = grabbyPoint.localPosition;
                grabbyPointPosition.y    -= descentSpeed * grabbySpeedIncrement * Time.deltaTime;
                grabbyPoint.localPosition = grabbyPointPosition;

                var positionTraveled = Mathf.InverseLerp(MaxDescentPosition, OriginalYPosition, position.y);
                materialOffset.y = GetTextureOffsetModifier(positionTraveled);
                //Debug.LogFormat("GoingDown: Position Traveled = {0} => Mat offset = {1}", positionTraveled, materialOffset.y);
                material.mainTextureOffset = materialOffset;

                if (position.y <= MaxDescentPosition)
                {
                    position.y = MaxDescentPosition;
                    DetectObjectCollision();
                    handState = HandState.GoingUp;

                    materialOffset.y           = 0;
                    material.mainTextureOffset = materialOffset;
                }
            }
            else if (handState == HandState.GoingUp)
            {
                position.y += ascentSpeed * Time.deltaTime;

                var grabbyPointPosition = grabbyPoint.localPosition;
                grabbyPointPosition.y += ascentSpeed * grabbySpeedIncrement * Time.deltaTime;

                var positionTraveled = Mathf.InverseLerp(MaxDescentPosition, OriginalYPosition, position.y);
                materialOffset.y = GetTextureOffsetModifier(positionTraveled);
                //Debug.LogFormat("GoingUp: Position Traveled = {0} => Mat offset = {1}", positionTraveled, materialOffset.y);
                material.mainTextureOffset = materialOffset;

                if (position.y >= OriginalYPosition)
                {
                    position.y = OriginalYPosition;
                    handState  = HandState.Idle;

                    materialOffset.y           = -0.5f;
                    material.mainTextureOffset = materialOffset;
                    grabbyPointPosition.y      = grabbyYOriginalPoint;
                }

                grabbyPoint.localPosition = grabbyPointPosition;
            }
            else if (handState == HandState.Yeeting)
            {
                var rotation = yeetingContrainerTransform.rotation;
                var euler    = rotation.eulerAngles;
                yeetingRotationTimer += Time.deltaTime;
                var delta = Mathf.Clamp01(yeetingRotationTimer / yeetingRotationMaxTime);

                if (delta >= 1)
                {
                    handState            = HandState.Idle;
                    yeetingRotationTimer = 0f;
                    euler.z      = yeetRotOriginal;
                    yeetingPower = 0;
                }
                else
                {
                    euler.z = Mathf.Lerp(yeetRotMin, yeetRotMax, delta);
                }

                if (delta > 0.8f && currentMergeableObject != null)
                {
                    currentMergeableObject.transform.SetParent(null);
                    currentMergeableObject.hoverScript.UpdateRotation = true;
                    currentMergeableObject.YeetToPosition.YeetInit(currentMergeableObject.transform.position, opponent.backCloud, 30, 0.5f);
                    currentMergeableObject.YeetToPosition.Yeet(Mathf.RoundToInt(currentMergeableObject.Damage * yeetingPower), onYeetEvent);
                    currentMergeableObject = null;
                }

                rotation.eulerAngles = euler;
                yeetingContrainerTransform.rotation = rotation;
            }
            else if (handState == HandState.ChargingYeet)
            {
                hover1.UpdateRotation = true;
                hover2.UpdateRotation = true;
            }

            transform.position = position;
        }
#endif
    }
예제 #14
0
    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)
            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))
            {
                //gameObject.GetComponent<Renderer>().material.color = Color.red;
            }
            else
            {
                //gameObject.GetComponent<Renderer>().material.color = Color.blue;
            }

            /*
             * Quaternion adjustedQ = orientation;// * //Quaternion.Euler(-90,0,0);
             * Vector3 adjustedV = adjustedQ.eulerAngles;// + new Vector3(0,0,0);
             * Vector3 swappedV = new Vector3(adjustedV.x, adjustedV.y, adjustedV.z);
             * //gameObject.transform.localRotation = Quaternion.Euler(swappedV);
             */
            gameObject.transform.localRotation = orientation;

            gravityAngle = Quaternion.Inverse(orientation) * Vector3.forward;

            Debug.Log(accel - gravityAngle);
        }
    }
예제 #15
0
 public override bool GetButtonUp(Joycon joycon)
 {
     return(joycon.GetButtonUp(button));
 }
예제 #16
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (j != null)
        {
            // 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(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();
            if (gyro.y < -1)
            {
                Debug.Log("l'avant tourne vers le bas ");
            }
            if (gyro.y > 1)
            {
                Debug.Log("l'avant tourne vers nous ");
            }

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

            /*
             * if (accel.x > 1)
             *  Debug.Log("pointe vers la haut");
             * if (accel.x < -1)
             *  Debug.Log("pointe vers le bas");
             * if (accel.z < -0.99)
             *  Debug.Log("a plat");
             * if (accel.z > 0.99)
             *  Debug.Log("a l'envers");
             * if (accel.y > 1)
             *  Debug.Log("sur la tranche, posé sur le rail");
             * if (accel.y < -1)
             *  Debug.Log("sur la tranche, rail vers le haut");
             */

            orientation = j.GetVector();
            if (j.GetButton(Joycon.Button.DPAD_UP))
            {
                gameObject.GetComponent <Renderer>().material.color = Color.red;
            }
            else
            {
                gameObject.GetComponent <Renderer>().material.color = Color.blue;
            }
            gameObject.transform.RotateAround(gameObject.transform.localPosition, transform.forward, -gyro.z);
            gameObject.transform.RotateAround(gameObject.transform.localPosition, transform.right, -gyro.y);
            gameObject.transform.RotateAround(gameObject.transform.localPosition, transform.up, -gyro.x);
            // gameObject.transform.rotation = orientation;
        }
    }
예제 #17
0
 // Update is called once per frame
 void Update()
 {
     if ((jg != null) && (jd != null))
     {
         //Bouton ZL pressé et bras gauche initialisé.
         if ((jg.GetButtonDown(Joycon.Button.SHOULDER_2)) && (la != null))
         {
             //On s'assure que la co-routine moveLeftArm ne soit appelée qu'une seule fois.
             if (!mla)
             {
                 StopCoroutine("returnLeftArm");
                 if (rla)
                 {
                     rla = false;
                 }
                 StartCoroutine("moveLeftArm");
             }
         }
         //Bouton ZR pressé et bras droit initialisé : on stoppe le retour du bras droit à
         //sa position initiale (même si c'est en cours) et on fait bouger le bras droit vers le haut.
         if ((jd.GetButtonDown(Joycon.Button.SHOULDER_2)) && (ra != null))
         {
             if (!mra)
             {
                 StopCoroutine("returnRightArm");
                 if (rra)
                 {
                     rra = false;
                 }
                 StartCoroutine("moveRightArm");
             }
         }
         //Bouton ZL relâché et bras gauche initialisé : on stoppe la rotation du bras gauche vers
         //le haut (même si c'est en cours) et on entame le retour du bras gauche vers sa position initiale.
         if ((jg.GetButtonUp(Joycon.Button.SHOULDER_2)) && (la != null))
         {
             if (!rla)
             {
                 StopCoroutine("moveLeftArm");
                 if (mla)
                 {
                     mla = false;
                 }
                 StartCoroutine("returnLeftArm");
             }
         }
         //Bouton ZR relâché et bras droit initialisé.
         if ((jd.GetButtonUp(Joycon.Button.SHOULDER_2)) && (ra != null))
         {
             if (!rra)
             {
                 StopCoroutine("moveRightArm");
                 //Si la co-routine ci-dessus a été stoppée prématurément, on n'oublie
                 //pas de préciser que cette dernière n'est plus en cours d'exécution.
                 if (mra)
                 {
                     mra = false;
                 }
                 StartCoroutine("returnRightArm");
             }
         }
     }
     else
     {
         //On initialise ici et pas dans la fonction Start car celle du parent ne s'active
         //qu'une fois tous ses enfants initialisés.
         jg = father.getLeftJoycon();
         jd = father.getRightJoycon();
     }
 }
예제 #18
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;
        }
    }
예제 #19
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);
            }
        }
    }
예제 #20
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();
                gameObject.transform.position = Vector3.zero;
            }
            // 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(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.
            }

            if (j.GetButton(Joycon.Button.DPAD_UP))
            {
                gameObject.GetComponent <Renderer>().material.color = Color.red;
            }
            else
            {
                gameObject.GetComponent <Renderer>().material.color = Color.yellow;
            }

            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();

            accel1 = j.GetAccel1();
            accel2 = j.GetAccel2();
            accel3 = j.GetAccel3();

            bool isMoving = false;
            bool debug    = false;

            if (gyro.x > angle_mort || gyro.x < -angle_mort || debug)
            {
                isMoving      = true;
                orientation.x = j.GetVector().x;
            }
            if (gyro.y > angle_mort || gyro.y < -angle_mort || debug)
            {
                isMoving      = true;
                orientation.y = j.GetVector().y;
            }
            if (gyro.z > angle_mort || gyro.z < -angle_mort || debug)
            {
                isMoving      = true;
                orientation.z = j.GetVector().z;
            }



            if (isMoving)
            {
                orientation.w = j.GetVector().w;
                gameObject.transform.rotation = orientation;
            }

            gameObject.transform.position = new Vector3(accel3.x * vitesse, accel1.y * vitesse, accel3.z * vitesse);

            cursor1.transform.position = accel1;
            cursor2.transform.position = accel2;
            cursor3.transform.position = accel3;
            cursor4.transform.position = accel1 + accel2 + accel3;
        }
    }
예제 #21
0
    void Update()
    {
        switch (currentController)
        {
        case Controller.Keyboard:
            leftStick.x_axis = Input.GetKey(KeyCode.D) ? 1f : 0f;
            leftStick.x_axis = Input.GetKey(KeyCode.A) ? leftStick.x_axis - 1f : leftStick.x_axis;
            leftStick.y_axis = Input.GetKey(KeyCode.W) ? 1f : 0f;
            leftStick.y_axis = Input.GetKey(KeyCode.S) ? leftStick.y_axis - 1f : leftStick.y_axis;

            rightStick.x_axis = Input.GetAxis("Mouse X");
            rightStick.y_axis = Input.GetAxis("Mouse Y");


            leftTriggerAnalog.axis = Input.GetKey(KeyCode.Space) ? 1f : -1f;

            rightTriggerAnalog.axis = Input.GetKey(KeyCode.Mouse0 /*RightShift*/) ? 1f : -1f;
            //Cursor.visible = false; /*remove later on*/

            leftTriggerDigital.enter = Input.GetKeyDown(KeyCode.LeftControl);
            leftTriggerDigital.held  = Input.GetKey(KeyCode.LeftControl);
            leftTriggerDigital.exit  = Input.GetKeyUp(KeyCode.LeftControl);

            rightTriggerDigital.enter = Input.GetKeyDown(KeyCode.RightControl);
            rightTriggerDigital.held  = Input.GetKey(KeyCode.RightControl);
            rightTriggerDigital.exit  = Input.GetKeyUp(KeyCode.RightControl);

            grab.enter = Input.GetKeyDown(KeyCode.LeftShift);
            grab.held  = Input.GetKey(KeyCode.LeftShift);
            grab.exit  = Input.GetKeyUp(KeyCode.LeftShift);

            PauseButton.enter = Input.GetKeyDown(KeyCode.Escape);
            PauseButton.held  = Input.GetKey(KeyCode.Escape);
            PauseButton.exit  = Input.GetKeyUp(KeyCode.Escape);

            break;

        case Controller.Controller:


            leftStick.x_axis       = Input.GetAxis("Horizontal");
            leftTriggerAnalog.axis = Input.GetAxis("Jump");

            rightStick.x_axis = Input.GetAxis("TVertical");
            rightStick.y_axis = Input.GetAxis("THorizontal");



            //if (Input.GetAxis("Jump") > 1) { Debug.Log("JoystickButton0"); }
            if (Input.GetKeyDown(KeyCode.JoystickButton1))
            {
                Debug.Log("JoystickButton1");
            }
            if (Input.GetKeyDown(KeyCode.JoystickButton2))
            {
                Debug.Log("JoystickButton2");
            }
            //rightStick.x_axis = Input.GetAxis("RightStickHorizontal");
            //rightStick.y_axis = Input.GetAxis("RightStickVertical");


            break;

        case Controller.Unique:


            if (joycons.Count > 0)
            {
                Joycon j = joycons[0];


                Vector3 orientation = j.GetVector().eulerAngles;
                rightStick.x_axis = -(orientation.y < 0 ? orientation.y + 180 : orientation.y - 180) / 180;
                rightStick.y_axis = (orientation.x > 180 ? orientation.x - 360 : orientation.x) / 180;

                rightTriggerDigital.enter = j.GetButtonDown(Joycon.Button.SHOULDER_1);
                rightTriggerDigital.held  = j.GetButton(Joycon.Button.SHOULDER_1);
                rightTriggerDigital.exit  = j.GetButtonUp(Joycon.Button.SHOULDER_1);

                rightTriggerAnalog.axis = j.GetButton(Joycon.Button.SHOULDER_2) ? 1f : -1f;

                j = joycons[1];

                leftTriggerAnalog.axis = j.GetButton(Joycon.Button.SHOULDER_2) ? 1f : -1f;

                leftStick.x_axis = j.GetStick()[0];
                leftStick.y_axis = j.GetStick()[1];

                grab.enter = j.GetButtonDown(Joycon.Button.SHOULDER_1);
                grab.held  = j.GetButton(Joycon.Button.SHOULDER_1);
                grab.exit  = j.GetButtonUp(Joycon.Button.SHOULDER_1);
            }
            break;

        default:
            break;
        }
    }
예제 #22
0
    IEnumerator _JoyconUpdate()
    {
        while (true)
        {
            #region Triggers & bumpers
            //Triggers
            if (Left.GetButtonDown(Joycon.Button.SHOULDER_2))
            {
                LeftTrigger = true;
                if (OnLeftTrigger != null)
                {
                    OnLeftTrigger();
                }
            }
            else if (Left.GetButtonUp(Joycon.Button.SHOULDER_2))
            {
                LeftTrigger = false;
            }

            if (Right.GetButtonDown(Joycon.Button.SHOULDER_2))
            {
                RightTrigger = true;
                if (OnRightTrigger != null)
                {
                    OnRightTrigger();
                }
            }
            else if (Right.GetButtonUp(Joycon.Button.SHOULDER_2))
            {
                RightTrigger = false;
            }

            //Bumpers
            if (Left.GetButtonDown(Joycon.Button.SHOULDER_1))
            {
                LeftBumper = true;
                if (OnLeftBumper != null)
                {
                    OnLeftBumper();
                }
            }
            else if (Left.GetButtonUp(Joycon.Button.SHOULDER_1))
            {
                LeftBumper = false;
            }

            if (Right.GetButtonDown(Joycon.Button.SHOULDER_1))
            {
                RightBumper = true;
                if (OnRightBumper != null)
                {
                    OnRightBumper();
                }
            }
            else if (Right.GetButtonUp(Joycon.Button.SHOULDER_1))
            {
                RightBumper = false;
            }
            #endregion

            #region D-pad
            //D-pad
            if (Left.GetButtonDown(Joycon.Button.DPAD_RIGHT))
            {
                DRight = true;
                if (OnDRight != null)
                {
                    OnDRight();
                }
            }
            else if (Left.GetButtonUp(Joycon.Button.DPAD_RIGHT))
            {
                DRight = false;
            }

            if (Left.GetButtonDown(Joycon.Button.DPAD_DOWN))
            {
                DDown = true;
                if (OnDDown != null)
                {
                    OnDDown();
                }
            }
            else if (Left.GetButtonUp(Joycon.Button.DPAD_DOWN))
            {
                DDown = false;
            }

            if (Left.GetButtonDown(Joycon.Button.DPAD_LEFT))
            {
                DLeft = true;
                if (OnDLeft != null)
                {
                    OnDLeft();
                }
            }
            else if (Left.GetButtonUp(Joycon.Button.DPAD_LEFT))
            {
                DLeft = false;
            }

            if (Left.GetButtonDown(Joycon.Button.DPAD_UP))
            {
                DUp = true;
                if (OnDUp != null)
                {
                    OnDUp();
                }
            }
            else if (Left.GetButtonUp(Joycon.Button.DPAD_UP))
            {
                DUp = false;
            }
            #endregion

            #region ABYX
            if (Right.GetButtonDown(Joycon.Button.DPAD_RIGHT))
            {
                A = true;
                if (OnA != null)
                {
                    OnA();
                }
            }
            else if (Right.GetButtonUp(Joycon.Button.DPAD_RIGHT))
            {
                A = false;
            }

            if (Right.GetButtonDown(Joycon.Button.DPAD_DOWN))
            {
                B = true;
                if (OnB != null)
                {
                    OnB();
                }
            }
            else if (Right.GetButtonUp(Joycon.Button.DPAD_DOWN))
            {
                B = false;
            }

            if (Right.GetButtonDown(Joycon.Button.DPAD_LEFT))
            {
                Y = true;
                if (OnY != null)
                {
                    OnY();
                }
            }
            else if (Right.GetButtonUp(Joycon.Button.DPAD_LEFT))
            {
                Y = false;
            }

            if (Right.GetButtonDown(Joycon.Button.DPAD_UP))
            {
                X = true;
                if (OnX != null)
                {
                    OnX();
                }
            }
            else if (Right.GetButtonUp(Joycon.Button.DPAD_UP))
            {
                X = false;
            }
            #endregion

            #region Plus & Minus
            //Minus
            if (Left.GetButtonDown(Joycon.Button.MINUS))
            {
                Minus = true;
                if (OnMinus != null)
                {
                    OnMinus();
                }
            }
            else if (Left.GetButtonUp(Joycon.Button.MINUS))
            {
                Minus = false;
            }

            //Plus
            if (Right.GetButtonDown(Joycon.Button.PLUS))
            {
                Plus = true;
                if (OnPlus != null)
                {
                    OnPlus();
                }
            }
            else if (Right.GetButtonUp(Joycon.Button.PLUS))
            {
                Plus = false;
            }
            #endregion

            #region Sticks
            //Left stick
            float[] stick = Left.GetStick();
            //Checks if the sticks axis are getting moved enough
            if (Mathf.Abs(stick[0]) > StickActivation || Mathf.Abs(stick[1]) > StickActivation)
            {
                //Start moving the cursor
                OnLeftStick(stick);
            }

            //Right stick
            stick = Right.GetStick();
            //Checks if the sticks x-axis is getting moved enough
            if (Mathf.Abs(stick[0]) > StickActivation || Mathf.Abs(stick[1]) > StickActivation)
            {
                //Start moving the camera
                OnRightStick(stick);
            }
            #endregion

            yield return(null);
        }
    }
예제 #23
0
    // Update is called once per frame
    void Update()
    {
        //DEBUG Simulate button press on Keyboard
        if (Input.GetKeyUp(KeyCode.Home))
        {
            ButtonPressed = false;
        }
        if (Input.GetKeyDown(KeyCode.Home))
        {
            ButtonPressed = true;
        }
        //END DEBUG

        // make sure the Joycon only gets checked if attached
        if (j != null && j.state > Joycon.state_.ATTACHED && GameUtils.playState != GameUtils.GamePlayState.ExpMode)
        {
            if (GameUtils.playState == GameUtils.GamePlayState.Menu && InitSinglePlayerMenu())
            {
                if (j.GetButtonUp(Joycon.Button.DPAD_UP))
                {
                    spScript.ToggleHighlightedButton(true);
                }
                if (j.GetButtonUp(Joycon.Button.DPAD_DOWN))
                {
                    spScript.ToggleHighlightedButton(false);
                }
                if (j.GetButtonUp(Joycon.Button.SHOULDER_2))
                {
                    spScript.ClickSelectedButton();
                }
            }

            //Back button while playing the game
            if (j.GetButtonUp(Joycon.Button.HOME) || j.GetButtonUp(Joycon.Button.CAPTURE))
            {
                SceneManager.LoadSceneAsync("SinglePlayer", LoadSceneMode.Single);
            }


            // GetButtonDown checks if a button has been released
            if (j.GetButtonUp(Joycon.Button.SHOULDER_2) ||
                j.GetButtonUp(Joycon.Button.DPAD_UP) ||
                j.GetButtonUp(Joycon.Button.DPAD_DOWN) ||
                j.GetButtonUp(Joycon.Button.DPAD_RIGHT) ||
                j.GetButtonUp(Joycon.Button.DPAD_LEFT) ||
                j.GetButtonUp(Joycon.Button.SHOULDER_1) ||
                j.GetButtonUp(Joycon.Button.PLUS) ||
                j.GetButtonUp(Joycon.Button.MINUS))
            {
                ButtonPressed = false;
                //ExperimentLog.Log("Button Released", "Joycon");
            }
            // GetButtonDown checks if a button is currently down (pressed or held)
            if (j.GetButton(Joycon.Button.SHOULDER_2) ||
                j.GetButton(Joycon.Button.DPAD_UP) ||
                j.GetButton(Joycon.Button.DPAD_DOWN) ||
                j.GetButton(Joycon.Button.DPAD_RIGHT) ||
                j.GetButton(Joycon.Button.DPAD_LEFT) ||
                j.GetButton(Joycon.Button.SHOULDER_1) ||
                j.GetButton(Joycon.Button.PLUS) ||
                j.GetButton(Joycon.Button.MINUS))
            {
                ButtonPressed = true;
                //ExperimentLog.Log("Button Pressed", "Joycon");
            }
        }
    }
예제 #24
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;
        }
    }
예제 #25
0
    // Update is called once per frame
    void Update()
    {
        // make sure the Joycon only gets checked if attached
        if (j != null && j.state > Joycon.state_.ATTACHED)
        {
            // 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();

            stick = j.GetStick();

            orientation = j.GetVector();
            gameObject.transform.rotation = orientation;

            //Test motion detection
            //x-rotation -> turn tetrimino
            //z-rotation -> move tetrimino
            //tilt forward (rotation.Y and rotation.Z negative) -> make tetrimino go faster

            if (gyro.x <= -20 && !_isMoving)
            {
                Debug.Log(gyro.x);
                StartCoroutine(TurnLeft());
            }


            if (gyro.x >= 20 && !_isMoving)
            {
                Debug.Log(gyro.x);
                StartCoroutine(TurnRight());
            }

            if (gyro.z <= -5 && !_isMoving)
            {
                Debug.Log(gyro.z);
                StartCoroutine(MoveLeft());
            }


            if (gyro.z >= 5 && !_isMoving)
            {
                Debug.Log(gyro.z);
                StartCoroutine(MoveRight());
            }

            if (orientation.w < 0.44)
            {
                Debug.Log("Tetrimino falling faster");
            }


            // 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(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.
            }

            if (j.GetButtonDown(Joycon.Button.DPAD_LEFT))
            {
                j.Recenter();
            }
        }
    }