/// <summary> /// Input state of the controler /// </summary> typedefstruct_DS5InputState { /// <summary> /// Position of left stick /// </summary> AnalogStick leftStick;
/// <summary> /// Posisiton of right stick /// </summary> AnalogStick rightStick;
/// <summary> /// Left trigger position /// </summary> unsignedchar leftTrigger;
/// <summary> /// Right trigger position /// </summary> unsignedchar rightTrigger;
/// <summary> /// Buttons and dpad bitmask DS5W_ISTATE_BTX_?? and DS5W_ISTATE_DPAD_?? indices check with if(buttonsAndDpad & DS5W_ISTATE_DPAD_??)... /// </summary> unsignedchar buttonsAndDpad;
/// <summary> /// Gyroscope (Currently only raw values will be dispayed! Probably needs calibration (Will be done within the lib in the future)) /// </summary> Vector3 gyroscope;
/// <summary> /// First touch point /// </summary> Touch touchPoint1;
/// <summary> /// Second touch point /// </summary> Touch touchPoint2;
/// <summary> /// Battery information /// </summary> Battery battery;
/// <summary> /// Indicates the connection of headphone /// </summary> bool headPhoneConnected;
/// <summary> /// EXPERIMAENTAL: Feedback of the left adaptive trigger (only when trigger effect is active) /// </summary> unsignedchar leftTriggerFeedback;
/// <summary> /// EXPERIMAENTAL: Feedback of the right adaptive trigger (only when trigger effect is active) /// </summary> unsignedchar rightTriggerFeedback; } DS5InputState;
// 麦克风LED Mic led if (inState.buttonsB & DS5W_ISTATE_BTN_B_MIC_BUTTON) { outState.microphoneLed = DS5W::MicLed::ON; } elseif (inState.buttonsB & DS5W_ISTATE_BTN_B_PLAYSTATION_LOGO) { outState.microphoneLed = DS5W::MicLed::OFF; }
Unity中检测当前平台是否支持陀螺仪功能
1 2 3 4 5 6 7 8 9 10 11 12 13
//检查是否支持陀螺仪 if (SystemInfo.supportsGyroscope) { //启用陀螺仪 Input.gyro.enabled = true; //获取陀螺仪的信息 //... } else { //提示不支持陀螺仪 Debug.Log("Gyroscope is not supported on this platform."); }
for (var i = 0; i < s_EnabledInstances.Count; ++i) { var component = s_EnabledInstances[i]; if (change == InputDeviceChange.Removed && component.m_Control != null && component.m_Control.device == device) component.ResolveControl(); elseif (change == InputDeviceChange.Added) component.ResolveControl(); } }
privatestaticvoidOnEvent(InputEventPtr eventPtr, InputDevice device) { // Ignore very first update as we usually get huge lag spikes and event count // spikes in it from stuff that has accumulated while going into play mode or // starting up the player. if (InputState.updateCount <= 1) return;
if (InputState.currentUpdateType == InputUpdateType.Editor) return;
if (!eventPtr.IsA<StateEvent>() && !eventPtr.IsA<DeltaStateEvent>()) return;
for (var i = 0; i < s_EnabledInstances.Count; ++i) { var component = s_EnabledInstances[i]; if (component.m_Control?.device != device || component.m_Visualizer == null) continue;
component.OnEventImpl(eventPtr, device); } }
//值的获取方式 privateunsafevoidOnEventImpl(InputEventPtr eventPtr, InputDevice device) { switch (m_Visualization) { case Mode.Value: { var statePtr = m_Control.GetStatePtrFromStateEvent(eventPtr); if (statePtr == null) return; // No value for control in event. varvalue = m_Control.ReadValueFromStateAsObject(statePtr); m_Visualizer.AddSample(value, eventPtr.time); break; }
case Mode.Events: { var visualizer = (VisualizationHelpers.TimelineVisualizer)m_Visualizer; var frame = (int)InputState.updateCount; refvar valueRef = ref visualizer.GetOrCreateSample(0, frame); varvalue = valueRef.ToInt32() + 1; valueRef = value; visualizer.limitsY = new Vector2(0, Mathf.Max(value, visualizer.limitsY.y)); break; }
case Mode.MaximumLag: { var visualizer = (VisualizationHelpers.TimelineVisualizer)m_Visualizer; var lag = (Time.realtimeSinceStartup - eventPtr.time) * 1000; // In milliseconds. var frame = (int)InputState.updateCount; refvar valueRef = ref visualizer.GetOrCreateSample(0, frame);
if (lag > valueRef.ToDouble()) { valueRef = lag; if (lag > visualizer.limitsY.y) visualizer.limitsY = new Vector2(0, Mathf.Ceil((float)lag)); } break; }
case Mode.Bytes: { var visualizer = (VisualizationHelpers.TimelineVisualizer)m_Visualizer; var frame = (int)InputState.updateCount; refvar valueRef = ref visualizer.GetOrCreateSample(0, frame); varvalue = valueRef.ToInt32() + eventPtr.sizeInBytes; valueRef = value; visualizer.limitsY = new Vector2(0, Mathf.Max(value, visualizer.limitsY.y)); break; }
case Mode.DeviceCurrent: { m_Visualizer.AddSample(device, eventPtr.time); break; } } }
publicvoidUpdate() { var look = lookAction.ReadValue<Vector2>(); var move = moveAction.ReadValue<Vector2>();
// Update orientation first, then move. Otherwise move orientation will lag // behind by one frame. Look(look); Move(move); }
privatevoidMove(Vector2 direction) { if (direction.sqrMagnitude < 0.01) return; var scaledMoveSpeed = moveSpeed * Time.deltaTime; // For simplicity's sake, we just keep movement in a single plane here. Rotate // direction according to world Y rotation of player. var move = Quaternion.Euler(0, transform.eulerAngles.y, 0) * new Vector3(direction.x, 0, direction.y); transform.position += move * scaledMoveSpeed; }
publicvoidAwake() { // We could use `fireAction.triggered` in Update() but that makes it more difficult to // implement the charging mechanism. So instead we use the `started`, `performed`, and // `canceled` callbacks to run the firing logic right from within the action.