|
@@ -1,494 +0,0 @@
|
|
|
-using NibiruAxis;
|
|
|
-using SC.InputSystem;
|
|
|
-using SC.InputSystem.InputDeviceHandShank;
|
|
|
-using System.Collections;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Linq;
|
|
|
-using UnityEngine;
|
|
|
-using UnityEngine.InputSystem;
|
|
|
-using UnityEngine.XR;
|
|
|
-using WCQ.CommonV1_20200325;
|
|
|
-
|
|
|
-public class ControllerInputFromAction : MonoBehaviour
|
|
|
-{
|
|
|
- public ControllerIndex index = ControllerIndex.Left;
|
|
|
- public List<InputActionReference> listinput;
|
|
|
- public List<InputActionReference> listtrack;
|
|
|
-
|
|
|
- public Transform Controller
|
|
|
- {
|
|
|
- get {
|
|
|
- return GetController(index)?.inputDeviceHandShankUI.transform;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void Start() {
|
|
|
- SC.InputSystem.InputSystem.ISInitializeCallBack += InputSystemVaildCallBack;
|
|
|
- }
|
|
|
-
|
|
|
- private void OnDestroy() {
|
|
|
- SC.InputSystem.InputSystem.ISInitializeCallBack -= InputSystemVaildCallBack;
|
|
|
- }
|
|
|
- public Transform right;
|
|
|
- private void Update()
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- void InputSystemVaildCallBack()
|
|
|
- {
|
|
|
- Invoke("DelayInvoke", 1);
|
|
|
- }
|
|
|
-
|
|
|
- void DelayInvoke() {
|
|
|
- Debug.Log("InputSystem Initialize ===" + index + " ");
|
|
|
-
|
|
|
- var HandedControllers = new List<UnityEngine.XR.InputDevice>();
|
|
|
- var desiredCharacteristics = (index == ControllerIndex.Left ? UnityEngine.XR.InputDeviceCharacteristics.Left : UnityEngine.XR.InputDeviceCharacteristics.Right) | UnityEngine.XR.InputDeviceCharacteristics.Controller;
|
|
|
- UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(desiredCharacteristics, HandedControllers);
|
|
|
-
|
|
|
- Debug.Log(HandedControllers.Count + " ===========");
|
|
|
-
|
|
|
- foreach (var device in HandedControllers)
|
|
|
- {
|
|
|
- Debug.Log(string.Format("Device name '{0}' has characteristics '{1}'", device.name, device.characteristics.ToString()));
|
|
|
- }
|
|
|
-
|
|
|
- if (HandedControllers.Count == 1)
|
|
|
- {
|
|
|
- onDeviceConnected(HandedControllers[0]);
|
|
|
- }
|
|
|
-
|
|
|
- if (Application.platform != RuntimePlatform.Android)
|
|
|
- {
|
|
|
- onDeviceConnected(new UnityEngine.XR.InputDevice());
|
|
|
- }
|
|
|
-
|
|
|
- InputDevices.deviceConnected += onDeviceConnected;
|
|
|
- InputDevices.deviceDisconnected += onDeviceDisConnected;
|
|
|
-
|
|
|
- */
|
|
|
- if(index== ControllerIndex.Left)
|
|
|
- {
|
|
|
-
|
|
|
- Debug.Log("Left onDeviceDisConnected===>" + index);
|
|
|
- InputDataHandShank.HSData.HS0Connect = false;
|
|
|
- GetController(ControllerIndex.Left)?.gameObject.SetActive(false);
|
|
|
-
|
|
|
- GetController(index).inputDataHandShank.blueToothName = "K07";
|
|
|
- GetController(index).inputDataHandShank.handShankType = HandShankType.K07;
|
|
|
- GetController(index).inputDataHandShank.isVaild = false;
|
|
|
-
|
|
|
- GetController(index).inputDataGetHandShank.inputDataGetHandShank3DOF.updateRotationCallBack -= updateRotationCallBack;
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Debug.Log("Right onDeviceConnected===>" + index);
|
|
|
- InputDataHandShank.HSData.HS1Connect = true;
|
|
|
- GetController(ControllerIndex.Right)?.gameObject.SetActive(true);
|
|
|
-
|
|
|
- GetController(index).inputDataHandShank.blueToothName = "K07";
|
|
|
- GetController(index).inputDataHandShank.handShankType = HandShankType.K07;
|
|
|
- GetController(index).inputDataHandShank.isVaild = true;
|
|
|
-
|
|
|
-
|
|
|
- GetController(index).inputDataGetHandShank.inputDataGetHandShank3DOF.updateRotationCallBack += updateRotationCallBack;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- Invoke("DelayInvoke", 1);
|
|
|
- }
|
|
|
- private void onDeviceDisConnected(UnityEngine.XR.InputDevice obj) {
|
|
|
- if (Application.platform == RuntimePlatform.Android)
|
|
|
- {
|
|
|
- if (obj.characteristics.ToString().Contains(InputDeviceCharacteristics.Left.ToString()))
|
|
|
- {
|
|
|
- Debug.Log("Left onDeviceDisConnected===>" + index);
|
|
|
- InputDataHandShank.HSData.HS0Connect = false;
|
|
|
- GetController(ControllerIndex.Left)?.gameObject.SetActive(false);
|
|
|
-
|
|
|
- GetController(index).inputDataHandShank.blueToothName = "K07";
|
|
|
- GetController(index).inputDataHandShank.handShankType = HandShankType.K07;
|
|
|
- GetController(index).inputDataHandShank.isVaild = false;
|
|
|
-
|
|
|
- GetController(index).inputDataGetHandShank.inputDataGetHandShank3DOF.updateRotationCallBack -= updateRotationCallBack;
|
|
|
- }
|
|
|
-
|
|
|
- if (obj.characteristics.ToString().Contains(InputDeviceCharacteristics.Right.ToString()))
|
|
|
- {
|
|
|
- Debug.Log("Right onDeviceDisConnected===>" + index);
|
|
|
- InputDataHandShank.HSData.HS1Connect = false;
|
|
|
- GetController(ControllerIndex.Right)?.gameObject.SetActive(false);
|
|
|
-
|
|
|
- GetController(index).inputDataHandShank.blueToothName = "K07";
|
|
|
- GetController(index).inputDataHandShank.handShankType = HandShankType.K07;
|
|
|
- GetController(index).inputDataHandShank.isVaild = false;
|
|
|
-
|
|
|
- GetController(index).inputDataGetHandShank.inputDataGetHandShank3DOF.updateRotationCallBack -= updateRotationCallBack;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
- GetController(index)?.gameObject.SetActive(false);
|
|
|
- if (index == ControllerIndex.Left)
|
|
|
- InputDataHandShank.HSData.HS0Connect = false;
|
|
|
- else
|
|
|
- InputDataHandShank.HSData.HS1Connect = false;
|
|
|
-
|
|
|
- GetController(index).inputDataHandShank.blueToothName = "K07";
|
|
|
- GetController(index).inputDataHandShank.handShankType = HandShankType.K07;
|
|
|
- GetController(index).inputDataHandShank.isVaild = false;
|
|
|
- GetController(index).inputDataGetHandShank.inputDataGetHandShank3DOF.updateRotationCallBack -= updateRotationCallBack;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- foreach ( var inputactionreference in listinput ) {
|
|
|
- inputactionreference.action.Disable();
|
|
|
- inputactionreference.action.performed -= OnInputPerformed;
|
|
|
- inputactionreference.action.canceled -= OnInputCanceled;
|
|
|
- }
|
|
|
-
|
|
|
- foreach ( var inputactionreference in listtrack ) {
|
|
|
- inputactionreference.action.Disable();
|
|
|
- inputactionreference.action.performed -= OnTrackPerformed;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- private void onDeviceConnected(UnityEngine.XR.InputDevice obj)
|
|
|
- {
|
|
|
- if (Application.platform == RuntimePlatform.Android)
|
|
|
- {
|
|
|
- if (obj.characteristics.ToString().Contains(InputDeviceCharacteristics.Left.ToString()))
|
|
|
- {
|
|
|
- Debug.Log("Left onDeviceConnected===>" + index);
|
|
|
- InputDataHandShank.HSData.HS0Connect = true;
|
|
|
- GetController(ControllerIndex.Left)?.gameObject.SetActive(true);
|
|
|
-
|
|
|
- GetController(index).inputDataHandShank.blueToothName = "K07";
|
|
|
- GetController(index).inputDataHandShank.handShankType = HandShankType.K07;
|
|
|
- GetController(index).inputDataHandShank.isVaild = true;
|
|
|
-
|
|
|
-
|
|
|
- GetController(index).inputDataGetHandShank.inputDataGetHandShank3DOF.updateRotationCallBack += updateRotationCallBack;
|
|
|
- }
|
|
|
-
|
|
|
- if (obj.characteristics.ToString().Contains(InputDeviceCharacteristics.Right.ToString()))
|
|
|
- {
|
|
|
- Debug.Log("Right onDeviceConnected===>" + index);
|
|
|
- InputDataHandShank.HSData.HS1Connect = true;
|
|
|
- GetController(ControllerIndex.Right)?.gameObject.SetActive(true);
|
|
|
-
|
|
|
- GetController(index).inputDataHandShank.blueToothName = "K07";
|
|
|
- GetController(index).inputDataHandShank.handShankType = HandShankType.K07;
|
|
|
- GetController(index).inputDataHandShank.isVaild = true;
|
|
|
-
|
|
|
-
|
|
|
- GetController(index).inputDataGetHandShank.inputDataGetHandShank3DOF.updateRotationCallBack += updateRotationCallBack;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- GetController(index)?.gameObject.SetActive(true);
|
|
|
- if (index == ControllerIndex.Left)
|
|
|
- InputDataHandShank.HSData.HS0Connect = true;
|
|
|
- else
|
|
|
- InputDataHandShank.HSData.HS1Connect = true;
|
|
|
-
|
|
|
- GetController(index).inputDataHandShank.blueToothName = "K07";
|
|
|
- GetController(index).inputDataHandShank.handShankType = HandShankType.K07;
|
|
|
- GetController(index).inputDataHandShank.isVaild = true;
|
|
|
-
|
|
|
- GetController(index).inputDataGetHandShank.inputDataGetHandShank3DOF.updateRotationCallBack += updateRotationCallBack;
|
|
|
- }
|
|
|
-
|
|
|
- foreach ( var inputactionreference in listinput ) {
|
|
|
- inputactionreference.action.Enable();
|
|
|
- inputactionreference.action.performed += OnInputPerformed;
|
|
|
- inputactionreference.action.canceled += OnInputCanceled;
|
|
|
- }
|
|
|
-
|
|
|
- foreach ( var inputactionreference in listtrack ) {
|
|
|
- inputactionreference.action.Enable();
|
|
|
- inputactionreference.action.performed += OnTrackPerformed;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public Quaternion controllerRotation { get; private set; }
|
|
|
- public Vector3 controllerPosition { get; private set; }
|
|
|
-
|
|
|
- void OnTrackPerformed(InputAction.CallbackContext context) {
|
|
|
-
|
|
|
- switch ( context.control.name ) {
|
|
|
- case "deviceposition":
|
|
|
- case "devicePosition":
|
|
|
- controllerPosition = context.ReadValue<Vector3>();
|
|
|
- break;
|
|
|
- case "devicerotation":
|
|
|
- case "deviceRotation":
|
|
|
-
|
|
|
-
|
|
|
- controllerRotation = context.ReadValue<Quaternion>();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- void updateRotationCallBack() {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (index == ControllerIndex.Right)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- GetController(index).inputDataHandShank.rotation = NxrPlayerCtrl.Instance.mTransform.rotation;
|
|
|
- GetController(index).inputDataHandShank.position = NxrPlayerCtrl.Instance.mTransform.position;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void LateUpdate()
|
|
|
- {
|
|
|
- return;
|
|
|
-
|
|
|
- if (GetController(index))
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- int xy = 8;
|
|
|
-
|
|
|
-
|
|
|
- void OnInputPerformed(InputAction.CallbackContext context) {
|
|
|
-
|
|
|
- switch ( context.control.name ) {
|
|
|
- case "secondarytouched":
|
|
|
- break;
|
|
|
- case "secondarybutton":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.DOWN);
|
|
|
-
|
|
|
- break;
|
|
|
- case "primarytouched":
|
|
|
- break;
|
|
|
- case "primarybutton":
|
|
|
-
|
|
|
- break;
|
|
|
- case "touchpadtouched":
|
|
|
- break;
|
|
|
- case "thumbstickclicked":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Tp, InputKeyState.DOWN);
|
|
|
- break;
|
|
|
- case "thumbstick":
|
|
|
- GetController(index)?.inputDataHandShank.InputDataAddTouch(true,
|
|
|
- new Vector2(xy + (int)(context.ReadValue<Vector2>().x * 10), xy + (int)(context.ReadValue<Vector2>().y * 10)));
|
|
|
- break;
|
|
|
- case "grip":
|
|
|
-
|
|
|
- break;
|
|
|
- case "grippressed":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.DOWN);
|
|
|
-
|
|
|
- break;
|
|
|
- case "trigger":
|
|
|
- break;
|
|
|
- case "triggerpressed":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.DOWN);
|
|
|
- break;
|
|
|
- case "menu":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Function, InputKeyState.DOWN);
|
|
|
- break;
|
|
|
- case "triggerButton":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.DOWN);
|
|
|
- break;
|
|
|
- case "gripButton":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.DOWN);
|
|
|
- break;
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- private void OnInputCanceled(InputAction.CallbackContext context) {
|
|
|
-
|
|
|
- switch ( context.control.name ) {
|
|
|
- case "secondarytouched":
|
|
|
- break;
|
|
|
- case "secondarybutton":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.UP);
|
|
|
-
|
|
|
- break;
|
|
|
- case "primarytouched":
|
|
|
- break;
|
|
|
- case "primarybutton":
|
|
|
-
|
|
|
- break;
|
|
|
- case "touchpadtouched":
|
|
|
- break;
|
|
|
- case "thumbstickclicked":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Tp, InputKeyState.UP);
|
|
|
- break;
|
|
|
- case "thumbstick":
|
|
|
- GetController(index)?.inputDataHandShank.InputDataAddTouch(true,
|
|
|
- new Vector2(xy + (int)(context.ReadValue<Vector2>().x * 10), xy + (int)(context.ReadValue<Vector2>().y * 10)));
|
|
|
- break;
|
|
|
- case "grip":
|
|
|
-
|
|
|
- break;
|
|
|
- case "grippressed":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.UP);
|
|
|
-
|
|
|
- break;
|
|
|
- case "trigger":
|
|
|
- break;
|
|
|
- case "triggerpressed":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.UP);
|
|
|
- break;
|
|
|
- case "menu":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Function, InputKeyState.UP);
|
|
|
- break;
|
|
|
- case "triggerButton":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.UP);
|
|
|
- break;
|
|
|
- case "gripButton":
|
|
|
- GetController(index)?.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.UP);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public enum ControllerIndex {
|
|
|
- Left = 0,
|
|
|
- Right = 1
|
|
|
- }
|
|
|
- InputDeviceHandShankPart GetController(ControllerIndex controllerIndex) {
|
|
|
- if ( SC.InputSystem.InputSystem.Instant && SC.InputSystem.InputSystem.Instant.HandShank ) {
|
|
|
- if ( ControllerIndex.Left == controllerIndex ) {
|
|
|
- return SC.InputSystem.InputSystem.Instant.HandShank.inputDeviceHandShankPartList.Where(e => e.PartType == SC.InputSystem.InputDevicePartType.HandShankOne).FirstOrDefault();
|
|
|
- } else if ( ControllerIndex.Right == controllerIndex ) {
|
|
|
- return SC.InputSystem.InputSystem.Instant.HandShank.inputDeviceHandShankPartList.Where(e => e.PartType == SC.InputSystem.InputDevicePartType.HandShankTwo).FirstOrDefault();
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|