public void RefreshSelectedRoleBindings() { var roleMap = m_roleSetButtonList[m_selectedRoleIndex].roleMap; var bindingTable = roleMap.BindingTable; // update bound device list and keep the original order for (int i = 0, imax = m_boundDevices.Count; i < imax; ++i) { m_tempDevices.Add(m_boundDevices[i]); } for (int i = 0, imax = bindingTable.Count; i < imax; ++i) { var boundDevice = bindingTable.GetKeyByIndex(i); if (!m_tempDevices.Remove(boundDevice)) { m_boundDevices.Add(boundDevice); } } for (int i = 0, imax = m_tempDevices.Count; i < imax; ++i) { m_boundDevices.Remove(m_tempDevices[i]); } m_tempDevices.Clear(); if (m_bindingList.Count == 0) { m_bindingList.Add(m_bindingItem); m_bindingItem.onEditPress += StartEditBinding; m_bindingItem.onRemovePress += RemoveBinding; } var bindingIndex = 0; for (int max = m_boundDevices.Count; bindingIndex < max; ++bindingIndex) { BindingInterfaceRoleSetBindingItem item; if (bindingIndex >= m_bindingList.Count) { var itemObj = Instantiate(m_bindingItem.gameObject); itemObj.transform.SetParent(m_bindingItem.transform.parent, false); // set child index to secnd last, last index is for add item itemObj.transform.SetSiblingIndex(itemObj.transform.parent.childCount - 2); m_bindingList.Add(item = itemObj.GetComponent <BindingInterfaceRoleSetBindingItem>()); item.onEditPress += StartEditBinding; item.onRemovePress += RemoveBinding; } else { item = m_bindingList[bindingIndex]; } item.gameObject.SetActive(true); item.deviceSN = m_boundDevices[bindingIndex]; item.isEditing = isEditing && item.deviceSN == m_editingDevice; item.isHeighLight = hasHeightLight && item.deviceSN == m_heighLightDevice; item.RefreshDisplayInfo(roleMap); } // FIXME: issue in 2017.2.0b2, item won't refresh at the first time, force refresh m_bindingItem.transform.parent.gameObject.SetActive(false); m_bindingItem.transform.parent.gameObject.SetActive(true); for (int max = m_bindingList.Count; bindingIndex < max; ++bindingIndex) { m_bindingList[bindingIndex].gameObject.SetActive(false); } }
public override void UpdateDeviceState(IVRModuleDeviceState[] prevState, IVRModuleDeviceStateRW[] currState) { if (XRSettings.isDeviceActive && XRDevice.isPresent) { InputTracking.GetNodeStates(m_nodeStateList); } var rightIndex = INVALID_DEVICE_INDEX; var leftIndex = INVALID_DEVICE_INDEX; for (int i = 0, imax = m_nodeStateList.Count; i < imax; ++i) { uint deviceIndex; if (!TryGetNodeDeviceIndex(m_nodeStateList[i], out deviceIndex)) { continue; } m_prevExistNodeUids.Remove(m_nodeStateList[i].uniqueID); m_currExistNodeUids.Add(m_nodeStateList[i].uniqueID); var prevDeviceState = prevState[deviceIndex]; var currDeviceState = currState[deviceIndex]; currDeviceState.isConnected = true; switch (m_nodeStateList[i].nodeType) { case XRNode.Head: currDeviceState.deviceClass = VRModuleDeviceClass.HMD; break; case XRNode.RightHand: currDeviceState.deviceClass = VRModuleDeviceClass.Controller; rightIndex = deviceIndex; break; case XRNode.LeftHand: currDeviceState.deviceClass = VRModuleDeviceClass.Controller; leftIndex = deviceIndex; break; case XRNode.GameController: currDeviceState.deviceClass = VRModuleDeviceClass.Controller; break; case XRNode.HardwareTracker: currDeviceState.deviceClass = VRModuleDeviceClass.GenericTracker; break; case XRNode.TrackingReference: currDeviceState.deviceClass = VRModuleDeviceClass.TrackingReference; break; default: currDeviceState.deviceClass = VRModuleDeviceClass.Invalid; break; } if (!prevDeviceState.isConnected) { // FIXME: getting wrong name in Unity 2017.1f1 //currDeviceState.serialNumber = InputTracking.GetNodeName(m_nodeStateList[i].uniqueID) ?? string.Empty; currDeviceState.serialNumber = XRDevice.model + " " + m_nodeStateList[i].uniqueID.ToString("X8"); currDeviceState.modelNumber = XRDevice.model + " " + m_nodeStateList[i].nodeType; currDeviceState.renderModelName = XRDevice.model + " " + m_nodeStateList[i].nodeType; SetupKnownDeviceModel(currDeviceState); } // update device status currDeviceState.isPoseValid = m_nodeStateList[i].tracked; var velocity = default(Vector3); if (m_nodeStateList[i].TryGetVelocity(out velocity)) { currDeviceState.velocity = velocity; } var position = default(Vector3); if (m_nodeStateList[i].TryGetPosition(out position)) { currDeviceState.position = position; } var rotation = default(Quaternion); if (m_nodeStateList[i].TryGetRotation(out rotation)) { currDeviceState.rotation = rotation; } } m_nodeStateList.Clear(); if (VRModule.IsValidDeviceIndex(rightIndex)) { var rightCurrState = currState[m_rightIndex]; var rightPrevState = prevState[m_rightIndex]; var rightMenuPress = Input.GetKey(ButtonKeyCode.RMenuPress); var rightAButtonPress = Input.GetKey(ButtonKeyCode.RAKeyPress); var rightPadPress = Input.GetKey(ButtonKeyCode.RPadPress); var rightMenuTouch = Input.GetKey(ButtonKeyCode.RMenuTouch); var rightAButtonTouch = Input.GetKey(ButtonKeyCode.RAKeyTouch); var rightPadTouch = Input.GetKey(ButtonKeyCode.RPadTouch); var rightTriggerTouch = Input.GetKey(ButtonKeyCode.RTriggerTouch); var rightTrackpadX = Input.GetAxisRaw(ButtonAxisName.RPadX); var rightTrackpadY = Input.GetAxisRaw(ButtonAxisName.RPadY); var rightTrigger = Input.GetAxisRaw(ButtonAxisName.RTrigger); var rightGrip = Input.GetAxisRaw(ButtonAxisName.RGrip); rightCurrState.SetButtonPress(VRModuleRawButton.ApplicationMenu, rightMenuPress); rightCurrState.SetButtonPress(VRModuleRawButton.A, rightAButtonPress); rightCurrState.SetButtonPress(VRModuleRawButton.Touchpad, rightPadPress); rightCurrState.SetButtonPress(VRModuleRawButton.Trigger, AxisToPress(rightPrevState.GetButtonPress(VRModuleRawButton.Trigger), rightTrigger, 0.55f, 0.45f)); rightCurrState.SetButtonPress(VRModuleRawButton.Grip, AxisToPress(rightPrevState.GetButtonPress(VRModuleRawButton.Grip), rightGrip, 0.55f, 0.45f)); rightCurrState.SetButtonPress(VRModuleRawButton.CapSenseGrip, AxisToPress(rightPrevState.GetButtonPress(VRModuleRawButton.CapSenseGrip), rightGrip, 0.55f, 0.45f)); rightCurrState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, rightMenuTouch); rightCurrState.SetButtonTouch(VRModuleRawButton.A, rightAButtonTouch); rightCurrState.SetButtonTouch(VRModuleRawButton.Touchpad, rightPadTouch); rightCurrState.SetButtonTouch(VRModuleRawButton.Trigger, rightTriggerTouch); rightCurrState.SetButtonTouch(VRModuleRawButton.CapSenseGrip, AxisToPress(rightPrevState.GetButtonTouch(VRModuleRawButton.CapSenseGrip), rightGrip, 0.25f, 0.20f)); rightCurrState.SetAxisValue(VRModuleRawAxis.TouchpadX, rightTrackpadX); rightCurrState.SetAxisValue(VRModuleRawAxis.TouchpadY, rightTrackpadY); rightCurrState.SetAxisValue(VRModuleRawAxis.Trigger, rightTrigger); rightCurrState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, rightGrip); } if (VRModule.IsValidDeviceIndex(leftIndex)) { var leftCurrState = currState[m_leftIndex]; var leftPrevState = prevState[m_leftIndex]; var leftMenuPress = Input.GetKey(ButtonKeyCode.LMenuPress); var leftAButtonPress = Input.GetKey(ButtonKeyCode.LAKeyPress); var leftPadPress = Input.GetKey(ButtonKeyCode.LPadPress); var leftMenuTouch = Input.GetKey(ButtonKeyCode.LMenuTouch); var leftAButtonTouch = Input.GetKey(ButtonKeyCode.LAKeyTouch); var leftPadTouch = Input.GetKey(ButtonKeyCode.LPadTouch); var leftTriggerTouch = Input.GetKey(ButtonKeyCode.LTriggerTouch); var leftTrackpadX = Input.GetAxisRaw(ButtonAxisName.LPadX); var leftTrackpadY = Input.GetAxisRaw(ButtonAxisName.LPadY); var leftTrigger = Input.GetAxisRaw(ButtonAxisName.LTrigger); var leftGrip = Input.GetAxisRaw(ButtonAxisName.LGrip); leftCurrState.SetButtonPress(VRModuleRawButton.ApplicationMenu, leftMenuPress); leftCurrState.SetButtonPress(VRModuleRawButton.A, leftAButtonPress); leftCurrState.SetButtonPress(VRModuleRawButton.Touchpad, leftPadPress); leftCurrState.SetButtonPress(VRModuleRawButton.Trigger, AxisToPress(leftPrevState.GetButtonPress(VRModuleRawButton.Trigger), leftTrigger, 0.55f, 0.45f)); leftCurrState.SetButtonPress(VRModuleRawButton.Grip, AxisToPress(leftPrevState.GetButtonPress(VRModuleRawButton.Grip), leftGrip, 0.55f, 0.45f)); leftCurrState.SetButtonPress(VRModuleRawButton.CapSenseGrip, AxisToPress(leftPrevState.GetButtonPress(VRModuleRawButton.CapSenseGrip), leftGrip, 0.55f, 0.45f)); leftCurrState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, leftMenuTouch); leftCurrState.SetButtonTouch(VRModuleRawButton.A, leftAButtonTouch); leftCurrState.SetButtonTouch(VRModuleRawButton.Touchpad, leftPadTouch); leftCurrState.SetButtonTouch(VRModuleRawButton.Trigger, leftTriggerTouch); leftCurrState.SetButtonTouch(VRModuleRawButton.CapSenseGrip, AxisToPress(leftPrevState.GetButtonTouch(VRModuleRawButton.CapSenseGrip), leftGrip, 0.25f, 0.20f)); leftCurrState.SetAxisValue(VRModuleRawAxis.TouchpadX, leftTrackpadX); leftCurrState.SetAxisValue(VRModuleRawAxis.TouchpadY, leftTrackpadY); leftCurrState.SetAxisValue(VRModuleRawAxis.Trigger, leftTrigger); leftCurrState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, leftGrip); } // remove disconnected nodes for (int i = m_prevExistNodeUids.Count - 1; i >= 0; --i) { var removedIndex = RemoveNodeDeviceIndex(m_prevExistNodeUids[i]); if (VRModule.IsValidDeviceIndex(removedIndex)) { currState[removedIndex].Reset(); } } var temp = m_prevExistNodeUids; m_prevExistNodeUids = m_currExistNodeUids; m_currExistNodeUids = temp; m_currExistNodeUids.Clear(); if (m_rightIndex != rightIndex || m_leftIndex != leftIndex) { m_rightIndex = rightIndex; m_leftIndex = leftIndex; InvokeControllerRoleChangedEvent(); } }
private void OnDisable() { hovers.Clear(); presses.Clear(); drags.Clear(); }
protected virtual void ProcessRaycast() { if (m_processedFrame == Time.frameCount) { return; } m_processedFrame = Time.frameCount; // use another list to iterate raycasters // incase that raycasters may changed during this process cycle for (int i = 0, imax = raycasters.Count; i < imax; ++i) { var r = raycasters[i]; if (r != null) { processingRaycasters.Add(r); } } for (var i = processingRaycasters.Count - 1; i >= 0; --i) { var raycaster = processingRaycasters[i]; if (raycaster == null) { continue; } raycaster.Raycast(); var result = raycaster.FirstRaycastResult(); // prepare raycaster value var scrollDelta = raycaster.GetScrollDelta(); var raycasterPos = raycaster.transform.position; var raycasterRot = raycaster.transform.rotation; var hoverEventData = raycaster.HoverEventData; if (hoverEventData == null) { continue; } // gen shared data and put in hover event hoverEventData.Reset(); hoverEventData.delta = Vector2.zero; hoverEventData.scrollDelta = scrollDelta; hoverEventData.position = ScreenCenterPoint; hoverEventData.pointerCurrentRaycast = result; hoverEventData.position3DDelta = raycasterPos - hoverEventData.position3D; hoverEventData.position3D = raycasterPos; hoverEventData.rotationDelta = Quaternion.Inverse(hoverEventData.rotation) * raycasterRot; hoverEventData.rotation = raycasterRot; // copy data to other button event for (int j = 0, jmax = raycaster.ButtonEventDataList.Count; j < jmax; ++j) { var buttonEventData = raycaster.ButtonEventDataList[j]; if (buttonEventData == null || buttonEventData == hoverEventData) { continue; } buttonEventData.Reset(); buttonEventData.delta = Vector2.zero; buttonEventData.scrollDelta = scrollDelta; buttonEventData.position = ScreenCenterPoint; buttonEventData.pointerCurrentRaycast = result; buttonEventData.position3DDelta = hoverEventData.position3DDelta; buttonEventData.position3D = hoverEventData.position3D; buttonEventData.rotationDelta = hoverEventData.rotationDelta; buttonEventData.rotation = hoverEventData.rotation; } ProcessPress(hoverEventData); ProcessMove(hoverEventData); ProcessDrag(hoverEventData); // other buttons event for (int j = 1, jmax = raycaster.ButtonEventDataList.Count; j < jmax; ++j) { var buttonEventData = raycaster.ButtonEventDataList[j]; if (buttonEventData == null || buttonEventData == hoverEventData) { continue; } buttonEventData.pointerEnter = hoverEventData.pointerEnter; ProcessPress(buttonEventData); ProcessDrag(buttonEventData); } // scroll event if (result.isValid && !Mathf.Approximately(scrollDelta.sqrMagnitude, 0.0f)) { var scrollHandler = ExecuteEvents.GetEventHandler <IScrollHandler>(result.gameObject); ExecuteEvents.ExecuteHierarchy(scrollHandler, hoverEventData, ExecuteEvents.scrollHandler); } } if (isActiveAndEnabled) { for (var i = processingRaycasters.Count - 1; i >= 0; --i) { var r = processingRaycasters[i]; if (!raycasters.Contains(r)) { CleanUpRaycaster(r); } } } else { for (var i = processingRaycasters.Count - 1; i >= 0; --i) { CleanUpRaycaster(processingRaycasters[i]); } } processingRaycasters.Clear(); }