public static bool GetJoyConButtonDown(Joycon.Button button, bool isUsingRightJoyCon = true) { if (isUsingRightJoyCon) { if (m_joyconR == null) { return(false); } else { return(m_joyconR.GetButtonDown(button)); } } else { if (m_joyconL == null) { return(false); } else { return(m_joyconL.GetButtonDown(button)); } } }
//=============================================================== // 押されていたボタンがリリースされたかを確認 // Joycon.Button reqButton : 確認したいボタン(JoyconManagerのenum) // int reqIdx : 確認したいコントローラーのインデックス番号(プレイヤー番号) // bool isLeft : 確認したいコントローラーが左であるかの確認 // return bool //=============================================================== public bool GetRelease(Joycon.Button reqButton, int reqIdx, bool isLeft) { // 使用してるコントローラがあるか if (m_joycons == null || m_joycons.Count <= 0) { return(false); } // ジョイコンのリストを確認するロープ foreach (var joycon in m_joycons) { // インデックス番号、また確認したい側であるかを確認 if (joycon.Id != reqIdx || joycon.isLeft != isLeft) { continue; } // ボタンのリストの中を確認する foreach (var button in m_buttons) { // 要求しているボタンと一致しているかを確認 if (button != reqButton) { continue; } // ボタンがリリースされたかを確認 if (joycon.GetButtonUp(button)) { return(true); } } } return(false); }
public bool GetKeyUp(Joycon.Button button, bool isLeft) { if (isLeft) { return(m_joyconL.GetButtonUp(button)); } else { return(m_joyconR.GetButtonUp(button)); } }
public static bool GetJoyConButton(Joycon.Button button, bool isUsingRightJoyCon = true) { if (isUsingRightJoyCon) { return(m_joyconR.GetButton(button)); } else { return(m_joyconL.GetButton(button)); } }
bool SwitchConvert(Key_Hub k, ref Joycon.Button button, ref bool isLeft) { button = Joycon.Button.HOME; isLeft = false; switch (k) { case Key_Hub.U: { button = Joycon.Button.DPAD_UP; isLeft = true; } break; case Key_Hub.R: { button = Joycon.Button.DPAD_RIGHT; isLeft = true; } break; case Key_Hub.D: { button = Joycon.Button.DPAD_DOWN; isLeft = true; } break; case Key_Hub.L: { button = Joycon.Button.DPAD_LEFT; isLeft = true; } break; case Key_Hub.X: { button = Joycon.Button.DPAD_UP; isLeft = false; } break; case Key_Hub.A: { button = Joycon.Button.DPAD_RIGHT; isLeft = false; } break; case Key_Hub.B: { button = Joycon.Button.DPAD_DOWN; isLeft = false; } break; case Key_Hub.Y: { button = Joycon.Button.DPAD_LEFT; isLeft = false; } break; case Key_Hub.L1: { button = Joycon.Button.SHOULDER_1; isLeft = true; } break; case Key_Hub.L2: { button = Joycon.Button.SHOULDER_2; isLeft = true; } break; case Key_Hub.L3: { button = Joycon.Button.STICK; isLeft = true; } break; case Key_Hub.R1: { button = Joycon.Button.SHOULDER_1; isLeft = false; } break; case Key_Hub.R2: { button = Joycon.Button.SHOULDER_2; isLeft = false; } break; case Key_Hub.R3: { button = Joycon.Button.STICK; isLeft = false; } break; case Key_Hub.Option: { button = Joycon.Button.PLUS; isLeft = false; } break; case Key_Hub.Select: { button = Joycon.Button.MINUS; isLeft = true; } break; case Key_Hub.Home: { button = Joycon.Button.HOME; isLeft = false; } break; case Key_Hub.Share: { button = Joycon.Button.CAPTURE; isLeft = true; } break; default: { return(false); } } return(true); }
public static bool GetJoyConAnykeyDown() { if (m_pressedButtonL != null) { Joycon.Button b = (Joycon.Button)m_pressedButtonL; return(m_joyconL.GetButtonDown(b)); } else if (m_pressedButtonR != null) { Joycon.Button b = (Joycon.Button)m_pressedButtonR; return(m_joyconR.GetButtonDown(b)); } else { return(false); } }
public JoyconButton(Joycon.Button button) { this.button = button; }
public JoyconScheme(string name, JoyconAxisType axis, Joycon.Button button = Joycon.Button.STICK) { this.name = name; this.axis = axis; this.button = button; }
public bool PollJoyconForButton(Joycon.Button buttonPressed) { return(CONTROLLER.GetButtonDown(buttonPressed)); }
// 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 }