// Update is called once per frame void Update() { if (select.areYouLookingAtMe) { button.color = flamingo; } else if (!select.areYouLookingAtMe) { button.color = Color.white; } if (WaveVR_Controller.Input(device).GetPressDown(trigger) && select.areYouLookingAtMe) { button.color = Color.yellow; LoadMainMenu(); } else if (WaveVR_Controller.Input(device).GetPressDown(touchPad)) { AntMan(); } }
// Update is called once per frame void Update() { if (WaveVR_Controller.Input(device).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Trigger)) { #if UNITY_EDITOR Debug.Log(WVR_InputId.WVR_InputId_Alias1_Trigger + " press down"); #endif Log.d(LOG_TAG, "button " + WVR_InputId.WVR_InputId_Alias1_Trigger + " press down"); ControlledObject.SetActive(true); } if (WaveVR_Controller.Input(device).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Digital_Trigger)) { #if UNITY_EDITOR Debug.Log(WVR_InputId.WVR_InputId_Alias1_Digital_Trigger + " press down"); #endif Log.d(LOG_TAG, "button " + WVR_InputId.WVR_InputId_Alias1_Digital_Trigger + " press down"); ControlledObject.SetActive(true); } }
private void SetHmdInputRequest() { this.usableButtons_hmd.Clear(); #if UNITY_EDITOR if (Application.isEditor) { for (int _i = 0; _i < this.inputAttribtues_hmd.Length; _i++) { PrintDebugLog("SetHmdInputRequest() " + this.inputAttribtues_hmd [_i].id); // Set all request buttons usable in editor mode. this.usableButtons_hmd.Add(this.inputAttribtues_hmd [_i].id); } } else #endif { if (WaveVR.Instance == null) { return; } WVR_DeviceType _type = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Head).DeviceType; bool _ret = Interop.WVR_SetInputRequest(_type, this.inputAttribtues_hmd, (uint)this.inputAttribtues_hmd.Length); if (_ret) { uint _size = Interop.WVR_GetInputMappingTable(_type, this.inputTable, WaveVR_ButtonList.inputTableSize); if (_size > 0) { for (int _i = 0; _i < (int)_size; _i++) { this.usableButtons_hmd.Add(this.inputTable [_i].destination.id); PrintDebugLog("SetHmdInputRequest() " + _type + " button: " + this.inputTable [_i].source.id + " is mapping to HMD input ID: " + this.inputTable [_i].destination.id); } } } } }
public void SetDefaultButtons() { if (!this.Initialized) { return; } PrintInfoLog("SetDefaultButtons()"); WVR_InputAttribute_t[] inputAttribtues_hmd = new WVR_InputAttribute_t[1]; inputAttribtues_hmd [0].id = WVR_InputId.WVR_InputId_Alias1_Enter; inputAttribtues_hmd [0].capability = (uint)WVR_InputType.WVR_InputType_Button; inputAttribtues_hmd [0].axis_type = WVR_AnalogType.WVR_AnalogType_None; WVR_DeviceType _type = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Head).DeviceType; bool _ret = Interop.WVR_SetInputRequest(_type, inputAttribtues_hmd, (uint)inputAttribtues_hmd.Length); if (_ret) { uint inputTableSize = (uint)WVR_InputId.WVR_InputId_Max; WVR_InputMappingPair_t[] inputTable = new WVR_InputMappingPair_t[inputTableSize]; uint _size = Interop.WVR_GetInputMappingTable(_type, inputTable, inputTableSize); if (_size > 0) { for (int _i = 0; _i < (int)_size; _i++) { Log.d(LOG_TAG, Log.CSB .Append("SetDefaultButtons() ") .Append(_type.Name()) .Append(" button: ") .Append(inputTable[_i].source.id) .Append(" is mapping to HMD input ID: ") .Append(inputTable[_i].destination.id) .ToString()); } } } }
void Update() { if (teleportOn) { hasPosition = UpdateSprite(); teleportSprite.SetActive(hasPosition); //only visible if we can teleport there //trigger down, teleport if possible if (hasPosition && WaveVR_Controller.Input(DomFocusControllerType).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Trigger)) { Vector3 teleportPos = teleportSprite.transform.position; Vector3 oldPos = this.gameObject.transform.position; this.gameObject.transform.position = new Vector3(teleportPos.x, oldPos.y, teleportPos.z); ToggleTeleportMode(); } } //double click to toggle teleport mode if (WaveVR_Controller.Input(DomFocusControllerType).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Trigger)) // The trigger is pressed. { if (!firstClick) // The first click is detected. { firstClick = true; firstClickTime = Time.unscaledTime; } else // The second click detected, so toggle teleport mode. { firstClick = false; ToggleTeleportMode(); } } if (Time.unscaledTime - firstClickTime > doubleClickTimeLimit) // Time for the double click has run out. { firstClick = false; } }
private void updatePressText() { if (this.press_text == null) { return; } WVR_DeviceType _type = WaveVR_Controller.Input(this.DeviceType).DeviceType; foreach (WVR_InputId _pressId in this.pressIds) { if (WaveVR_ButtonList.Instance != null && WaveVR_ButtonList.Instance.IsButtonAvailable(this.DeviceType, _pressId)) { if (WaveVR_Controller.Input(this.DeviceType).GetPressDown(_pressId)) { this.press_text.text = _pressId.ToString(); PrintDebugLog("updatePressText() " + _pressId + " is pressed down."); WVR_InputId _btn = _pressId; bool _result = WaveVR_ButtonList.Instance.GetInputMappingPair(this.DeviceType, ref _btn); if (_result) { PrintDebugLog("updatePressText() " + _pressId + " is mapping from " + _type + " button " + _btn); } } if (WaveVR_Controller.Input(this.DeviceType).GetPressUp(_pressId)) { this.press_text.text = ""; PrintDebugLog("updatePressText() " + _pressId + " is pressed up."); if (_pressId == WVR_InputId.WVR_InputId_Alias1_Trigger) { WaveVR_Controller.Input(this.DeviceType).TriggerHapticPulse(); } } } } }
// Update is called once per frame void Update() { bool rightTriggerDown = false, leftTriggerDown = false; //bool rightTriggerUp = false, leftTriggerUp = false; //rightTriggerUp |= WaveVR_Controller.Input (Controller1Index).GetPressUp (WVR_InputId.WVR_InputId_Alias1_Touchpad); #if UNITY_EDITOR /// We don't need to set #if UNITY_EDITOR condition. /// In editor mode, XXXTriggerDown value will be overwritten by WaveVR_Controller /// In WaveVR_Controller.Update, it checks whether editor mode or not. /// In editor mode -> call to emulator provider, otherwise call to SDK. rightTriggerDown = Input.GetMouseButtonDown(1); // mouse right key //rightTriggerUp = Input.GetMouseButtonUp(1); leftTriggerDown = Input.GetMouseButtonDown(0); // mouse left key //leftTriggerUp = Input.GetMouseButtonUp(0); if (rightTriggerDown) { UpdateTargetText("showKeyboardEng"); } if (leftTriggerDown) { UpdateTargetText("hideKeyboard"); } #endif rightTriggerDown |= WaveVR_Controller.Input(Controller1Index).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Touchpad); leftTriggerDown |= WaveVR_Controller.Input(Controller1Index).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Menu); if (rightTriggerDown) { showKeyboardEng(); } if (leftTriggerDown) { hideKeyboard(); } }
// Update is called once per frame void Update() { if (treeContainerEventHandler.treeTargeted) { if (WaveVR_Controller.Input(device).GetTouch(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { switch (inputEventManager.Current_Controller_State) { case InputEventManager.ControllerState.Rotate: { RotateByAxis(); break; } case InputEventManager.ControllerState.Scale: { ScaleByAxis(); break; } } } } }
private bool IsAnyControllerConnected() { bool _result = false; foreach (WVR_DeviceType _dt in Enum.GetValues(typeof(WVR_DeviceType))) { if (_dt == WVR_DeviceType.WVR_DeviceType_HMD) { continue; } #if UNITY_EDITOR if (Application.isEditor) { if (WaveVR_Controller.Input(_dt).connected) { _result = true; break; } } else #endif { if (WaveVR.Instance != null) { WaveVR.Device _dev = WaveVR.Instance.getDeviceByType(_dt); if (_dev.connected) { _result = true; break; } } } } return(_result); }
void OnEnable() { controllerPrefab = null; controllerFileName = ""; genericControllerFileName = "Generic_"; if (WhichHand == ControllerHand.Controller_Right) { deviceType = WVR_DeviceType.WVR_DeviceType_Controller_Right; } else { deviceType = WVR_DeviceType.WVR_DeviceType_Controller_Left; } #if UNITY_EDITOR if (Application.isPlaying) { WVR_DeviceType _type = WaveVR_Controller.Input(this.deviceType).DeviceType; onLoadController(_type); return; } #endif WaveVR_Utils.Event.Listen(WaveVR_Utils.Event.DEVICE_CONNECTED, onDeviceConnected); }
void Update() { //Debug3D.Instance.Debug(m_RightController.transform.position.ToString()); //if (shoubing != null) //{ // // Debug.Log(shoubing.transform.position.ToString()); // Debug3D.Instance.Debug(shoubing.transform.position.ToString()); //} if (isControllerFocus_R || isControllerFocus_L) { // Log.d(LOG_TAG,"Bumber Down :"+WaveVR_Controller.Input(curFocusControllerType).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Bumper)); // Log.d(LOG_TAG,"Bumber Up :"+WaveVR_Controller.Input(curFocusControllerType).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Bumper)); if (WaveVR_Controller.Input(curFocusControllerType).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Touchpad) || WaveVR_Controller.Input(curFocusControllerType).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Bumper)) { //moveSphere(); } } if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } }
// Use this for initialization void Start() { #if UNITY_EDITOR if (Application.isPlaying) { bool _connected = false; WVR_DeviceType _type = this.deviceType; _connected = WaveVR_Controller.Input(this.deviceType).connected; _type = WaveVR_Controller.Input(this.deviceType).DeviceType; onLoadController(_type); return; } #endif PrintDebugLog("start() connect: " + connected + " Which hand: " + WhichHand); ImgMaterial = new Material(Shader.Find("Unlit/Texture")); wfef = new WaitForEndOfFrame(); wfs = new WaitForSeconds(1.0f); if (updateDynamically) { PrintDebugLog("updateDynamically, start a coroutine to check connection and render model name periodly"); StartCoroutine(checkRenderModelAndDelete()); } }
public static string GetControllerName(WaveVR_Controller.EDeviceType type) { string retString = ""; if (type == WaveVR_Controller.EDeviceType.Head) { Log.w(LOG_TAG, "EDeviceType is Head"); return(retString); } WVR_DeviceType deviceType = WaveVR_Controller.Input(type).DeviceType; if (WaveVR_Controller.Input(type).connected) { int bufferSize = 128; uint resultVertLength = 128; string parameterName = "GetRenderModelName"; IntPtr ptrParameterName = Marshal.StringToHGlobalAnsi(parameterName); IntPtr ptrResult = Marshal.AllocHGlobal(bufferSize); uint ret = Interop.WVR_GetParameters(deviceType, ptrParameterName, ptrResult, resultVertLength); if (ret > 0) { retString = Marshal.PtrToStringAnsi(ptrResult); } else { Log.w(LOG_TAG, "WVR_GetParameters returns empty"); } } else { Log.w(LOG_TAG, type + " controller is disconnect"); } Log.i(LOG_TAG, "GetControllerName returns " + retString); return(retString); }
private void processVREvent(WVR_Event_t vrEvent) { WVR_DeviceType _type = vrEvent.device.type; WVR_InputId _btn = vrEvent.input.inputId; // Process events used by plugin switch ((WVR_EventType)vrEvent.common.type) { case WVR_EventType.WVR_EventType_IpdChanged: { WaveVR_Utils.Event.Send("IpdChanged"); if (WaveVR_Render.Instance != null) { WaveVR_Render.Expand(WaveVR_Render.Instance); } } break; case WVR_EventType.WVR_EventType_DeviceStatusUpdate: { WaveVR_Utils.Event.Send("TrackedDeviceUpdated", vrEvent.device.common.type); } break; case WVR_EventType.WVR_EventType_BatteryStatusUpdate: { WaveVR_Utils.Event.Send("BatteryStatusUpdate"); } break; case WVR_EventType.WVR_EventType_LeftToRightSwipe: case WVR_EventType.WVR_EventType_RightToLeftSwipe: case WVR_EventType.WVR_EventType_DownToUpSwipe: case WVR_EventType.WVR_EventType_UpToDownSwipe: Log.i(LOG_TAG, "Swipe event: " + (WVR_EventType)vrEvent.common.type); WaveVR_Utils.Event.Send(WaveVR_Utils.Event.SWIPE_EVENT, vrEvent.common.type, _type); break; case WVR_EventType.WVR_EventType_DeviceRoleChanged: Log.i(LOG_TAG, "WVR_EventType_DeviceRoleChanged() " + _type + ", " + _btn + ", Resend connection notification after switching hand."); WaveVR.Instance.SetConnectionStatus(); if (WaveVR.Instance.SetLeftHandedMode()) { WaveVR_Utils.Event.Send(WaveVR_Utils.Event.DEVICE_ROLE_CHANGED); WaveVR.Instance.ResetAllButtonStates(); } break; case WVR_EventType.WVR_EventType_ButtonPressed: Log.d(LOG_TAG, "WVR_EventType_ButtonPressed() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded); if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance != null) { _type = WaveVR.Instance.getDeviceByType(_type).type; } WaveVR_Controller.Input(_type).SetEventState_Press(_btn, true); break; case WVR_EventType.WVR_EventType_ButtonUnpressed: Log.d(LOG_TAG, "WVR_EventType_ButtonUnpressed() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded); if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance != null) { _type = WaveVR.Instance.getDeviceByType(_type).type; } WaveVR_Controller.Input(_type).SetEventState_Press(_btn, false); break; case WVR_EventType.WVR_EventType_TouchTapped: Log.d(LOG_TAG, "WVR_EventType_TouchTapped() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded); if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance != null) { _type = WaveVR.Instance.getDeviceByType(_type).type; } WaveVR_Controller.Input(_type).SetEventState_Touch(_btn, true); break; case WVR_EventType.WVR_EventType_TouchUntapped: Log.d(LOG_TAG, "WVR_EventType_TouchUntapped() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded); if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance != null) { _type = WaveVR.Instance.getDeviceByType(_type).type; } WaveVR_Controller.Input(_type).SetEventState_Touch(_btn, false); break; case WVR_EventType.WVR_EventType_DeviceConnected: Log.d(LOG_TAG, "WVR_EventType_DeviceConnected() " + _type + ", left-handed? " + WaveVR_Controller.IsLeftHanded); WaveVR.Instance.SetConnectionStatus(_type, true); break; case WVR_EventType.WVR_EventType_DeviceDisconnected: Log.d(LOG_TAG, "WVR_EventType_DeviceDisconnected() " + _type + ", left-handed? " + WaveVR_Controller.IsLeftHanded); WaveVR.Instance.SetConnectionStatus(_type, false); break; default: break; } // Send event to developer for all kind of event if developer don't want to add callbacks for every event. WaveVR_Utils.Event.Send(WaveVR_Utils.Event.ALL_VREVENT, vrEvent); // Send event to developer by name. WaveVR_Utils.Event.Send(vrEvent.common.type.ToString(), vrEvent); }
void Update() { if (ListenToDevice) { #if UNITY_EDITOR if (Application.isEditor) { enabledReticle = WaveVR_Controller.Input(this.device).connected ? true : false; } else #endif { WaveVR.Device _device = WaveVR.Instance.getDeviceByType(this.device); enabledReticle = _device.connected; } } if (enabledReticle) { if (!meshIsCreated) { initialReticle(); } } else { if (meshIsCreated) { removeReticle(); } return; } reticleDistanceInMeters = Mathf.Clamp(reticleDistanceInMeters, kReticleDistanceMin, kReticleDistanceMax); if (reticleInnerAngle < kReticleMinInnerAngle) { reticleInnerAngle = kReticleMinInnerAngle; } if (reticleOuterAngle < kReticleMinOuterAngle) { reticleOuterAngle = kReticleMinOuterAngle; } float innerHalfAngelRadians = Mathf.Deg2Rad * reticleInnerAngle * 0.5f; float outerHalfAngelRadians = Mathf.Deg2Rad * reticleOuterAngle * 0.5f; float innerDiameter = 2.0f * Mathf.Tan(innerHalfAngelRadians); float outerDiameter = 2.0f * Mathf.Tan(outerHalfAngelRadians); if (rotationSpeed < 1) { rotationSpeed = 1; } if (internalRotationSpeed != rotationSpeed * 4) { UpdateRotSpeedBound(rotationSpeed * 4); } if (colorFlickerPerSecond) { if (Time.unscaledTime - colorFlickerTime >= 1.0f) { colorFlickerTime = Time.unscaledTime; if (isTriggerProgress) { colorFactor = deepeningColorRotation ? Color.Lerp(Color.white, reticleColor == Color.white ? Color.black : reticleColor, progressTime / 100) : reticleColor; } else { if (reticleColor != Color.white) { colorFactor = Color.white; } else { colorFactor = Color.black; } } } else { if (isTriggerProgress) { colorFactor = deepeningColorRotation ? Color.Lerp(Color.white, reticleColor == Color.white ? Color.black : reticleColor, progressTime / 100) : reticleColor; } else { colorFactor = reticleColor; } } } else { if (isTriggerProgress) { colorFactor = deepeningColorRotation ? Color.Lerp(Color.white, reticleColor == Color.white ? Color.black : reticleColor, progressTime / 100) : reticleColor; } else { colorFactor = reticleColor; } } int option = colorIter % internalRotationSpeed; if (option >= rotSpeedBound[0] && option <= rotSpeedBound[1]) { colorRotation[0] = 1f; colorRotation[1] = 0f; colorRotation[2] = 0f; colorRotation[3] = 0f; } else if (option >= rotSpeedBound[2] && option <= rotSpeedBound[3]) { colorRotation[0] = 0f; colorRotation[1] = 1f; colorRotation[2] = 0f; colorRotation[3] = 0f; } else if (option >= rotSpeedBound[4] && option <= rotSpeedBound[5]) { colorRotation[0] = 0f; colorRotation[1] = 0f; colorRotation[2] = 1f; colorRotation[3] = 0f; } else if (option >= rotSpeedBound[6] && option <= rotSpeedBound[7]) { colorRotation[0] = 0f; colorRotation[1] = 0f; colorRotation[2] = 0f; colorRotation[3] = 1f; } var materialProperty = new MaterialPropertyBlock(); materialProperty.SetFloatArray("colorRotFactor", colorRotation); gameObject.GetComponent <Renderer>().SetPropertyBlock(materialProperty); materialComp.SetColor("_Color", colorFactor); colorIter = (colorIter + 1) % internalRotationSpeed; reticleInnerDiameter = Mathf.Lerp(reticleInnerDiameter, innerDiameter, Time.deltaTime * reticleGrowthSpeed); reticleOuterDiameter = Mathf.Lerp(reticleOuterDiameter, outerDiameter, Time.deltaTime * reticleGrowthSpeed); materialComp.SetFloat("_InnerDiameter", reticleInnerDiameter * reticleDistanceInMeters); materialComp.SetFloat("_OuterDiameter", reticleOuterDiameter * reticleDistanceInMeters); materialComp.SetFloat("_DistanceInMeters", reticleDistanceInMeters); }
// Update is called once per frame void Update() { var device = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Dominant); //if (device.GetPressUp(WVR_InputId.WVR_InputId_Alias1_Menu)) // moviemode.ToggleMovieMode(); if (animator == null || poseTracker == null) { return; } if (device.GetTouchUp(WVR_InputId.WVR_InputId_Alias1_Touchpad) || TouchpadTouchUp) { if (touchControlDyn && dynRes != null) { float gap = 0.3f; Vector2 axis = device.GetAxis(WVR_InputId.WVR_InputId_Alias1_Touchpad); if (Mathf.Abs(axis.x) < gap || TouchpadTouchUp) { if (axis.y < -gap || (!IsTouchUpper && TouchpadTouchUp)) { dynRes.Lower(); } else if (axis.y > gap || (IsTouchUpper && TouchpadTouchUp)) { dynRes.Higher(); } } //if (Mathf.Abs(axis.y) < gap || TouchpadTouchUp) //{ // if (axis.x < -gap) // { // //moviemode.ToggleMovieMode(); // } // else if (axis.x > gap) // { // if (aq != null) // aq.enabled = !aq.enabled; // } //} if (Mathf.Abs(axis.y) < gap || TouchpadTouchUp) { if (axis.x > gap) { if (aq != null) { aq.enabled = !aq.enabled; } } else if (axis.x < gap) { //render.SetDiscardContent(!render.NeedDiscardContent); } } } if (touchControlObj && ControlledObjectList != null) { float gap = 0.3f; Vector2 axis = device.GetAxis(WVR_InputId.WVR_InputId_Alias1_Touchpad); if (Mathf.Abs(axis.x) < gap || TouchpadTouchUp) { var oldIndex = controlledObjectIndex; if (axis.y < -gap || (!IsTouchUpper && TouchpadTouchUp)) { Log.d(TAG, "Obj --"); controlledObjectIndex = Mathf.Clamp(++controlledObjectIndex, 0, ControlledObjectList.Count - 1); } else if (axis.y > gap || (IsTouchUpper && TouchpadTouchUp)) { Log.d(TAG, "Obj ++"); controlledObjectIndex = Mathf.Clamp(--controlledObjectIndex, 0, ControlledObjectList.Count - 1); } if (oldIndex != controlledObjectIndex) { SetControlledObjectActive(ControlledObjectList[oldIndex], false); SetControlledObjectActive(ControlledObjectList[controlledObjectIndex], true); } } if (Mathf.Abs(axis.y) < gap || TouchpadTouchUp) { if (axis.x > gap) { if (aq != null) { aq.enabled = !aq.enabled; } } else if (axis.x < gap) { //render.SetDiscardContent(!render.NeedDiscardContent); } } } TouchpadTouchUp = false; } if (device.GetPressDown(WVR_InputId.WVR_InputId_Alias1_Touchpad) || TriggerPressDown) { if (animator.speed == 0) { } else { animator.speed = 0; Time.timeScale = 0; poseTracker.enabled = true; if (obj1) { obj1.enabled = false; } if (obj2) { obj2.enabled = false; } moviemode.DisableMovieMode(); } } if (device.GetPressUp(WVR_InputId.WVR_InputId_Alias1_Touchpad) || TriggerPressUp) { if (animator.speed == 0) { animator.speed = 1; Time.timeScale = 1; poseTracker.transform.localPosition = Vector3.zero; poseTracker.transform.localRotation = Quaternion.identity; poseTracker.enabled = false; if (obj1) { obj1.enabled = true; } if (obj2) { obj2.enabled = true; } moviemode.EnableMovieMode(); } else { } TriggerPressDown = false; TriggerPressUp = false; } if (Interop.WVR_IsInputFocusCapturedBySystem()) { moviemode.DisableMovieMode(); isSystem = true; statusBeforeSystem = moviemode.GetMovieModeStatus(); } else if (isSystem) { if (statusBeforeSystem) { moviemode.EnableMovieMode(); } isSystem = false; } }
private void ProcessControllerInput() { bool rightTriggerDown = false, rightTriggerUp = false, leftTriggerDown = false, leftTriggerUp = false; // Right controller touchpad clicked if (RightController != null) { rightTriggerDown |= WaveVR_Controller.Input(ControllerRIndex).GetPress((WVR_InputId)ButtonToTrigger); rightTriggerUp |= WaveVR_Controller.Input(ControllerRIndex).GetPressUp((WVR_InputId)ButtonToTrigger); } // Left controller touchpad clicked if (LeftController != null) { leftTriggerDown |= WaveVR_Controller.Input(ControllerLIndex).GetPress((WVR_InputId)ButtonToTrigger); leftTriggerUp |= WaveVR_Controller.Input(ControllerLIndex).GetPressUp((WVR_InputId)ButtonToTrigger); } /// Keys can be pressed: /// - menu key: WaveVR_Controller.Input (index).GetPressDown (WVR_InputId.WVR_InputId_Alias1_Menu) /// - grep key: WaveVR_Controller.Input (index).GetPressDown (WVR_InputId.WVR_InputId_Alias1_Grip) /// - trigger key: WaveVR_Controller.Input (index).GetPressDown (WVR_InputId.WVR_InputId_Alias1_Trigger) /// Keys can be touched: /// - touchpad: WaveVR_Controller.Input(index).GetTouchDown(WVR_InputId.WVR_InputId_Alias1_Touchpad) /// - trigger key: WaveVR_Controller.Input(index).GetTouchDown(WVR_InputId.WVR_InputId_Alias1_Trigger) if ((rightTriggerDown || rightTriggerUp || leftTriggerDown || leftTriggerUp) /* && !pointerData.eligibleForClick*/) { // Before casting , change event camera of canvas. if (rightTriggerDown || rightTriggerUp) { ChangeCanvasEventCamera(ControllerRIndex); } if (leftTriggerDown || leftTriggerUp) { ChangeCanvasEventCamera(ControllerLIndex); } // Statically casting first. CastToCenterOfScreen(); // If nothing being casted statically, continuing casting dynamically. if (GetCurrentGameObject() == null) { if (rightTriggerDown || rightTriggerUp) { CastToRayHitObject(ControllerRIndex); } if (leftTriggerDown || leftTriggerUp) { CastToRayHitObject(ControllerLIndex); } } if (rightTriggerDown || leftTriggerDown) { OnTriggerEnterAndExit(); // Trigger "Enter" to current object and "Exit" to prev. object } else if (rightTriggerUp || leftTriggerUp) { OnTriggerClick(); OnTriggerExit(); // Trigger "Exit" to current object } } }
void Update() { if (ListenToDevice) { #if UNITY_EDITOR if (Application.isEditor) { enabledpointer = WaveVR_Controller.Input(this.device).connected ? true : false; } else #endif { WaveVR.Device _device = WaveVR.Instance.getDeviceByType(this.device); enabledpointer = _device.connected; } } if (enabledpointer) { if (!meshIsCreated) { initialPointer(); } } else { if (meshIsCreated) { removePointer(); } return; } if (RaycastMode == ERaycastMode.Fixed) { pointerDistanceInMeters = kpointerDistanceMax; } else if (RaycastMode == ERaycastMode.Mouse) { pointerDistanceInMeters = kpointerDistanceMin; } else { pointerDistanceInMeters = Mathf.Clamp(pointerDistanceInMeters, kpointerDistanceMin, kpointerDistanceMax); } if (pointerOuterAngle < kpointerMinOuterAngle) { pointerOuterAngle = kpointerMinOuterAngle; } float outerHalfAngelRadians = Mathf.Deg2Rad * pointerOuterAngle * 0.5f; float outerDiameter = 2.0f * Mathf.Tan(outerHalfAngelRadians); if (RaycastMode == ERaycastMode.Fixed) { pointerOuterDiameter = 0.2f; } else if (RaycastMode == ERaycastMode.Mouse) { pointerOuterDiameter = pointerOuterDiameterMin; } else { pointerOuterDiameter = Mathf.Lerp(pointerOuterDiameter, outerDiameter, Time.deltaTime * pointerGrowthSpeed); } if (RaycastMode == ERaycastMode.Fixed) { materialComp.renderQueue = 1000; } else { materialComp.renderQueue = 5000; } materialComp.SetFloat("_OuterDiameter", (RaycastMode != ERaycastMode.Fixed)? 0.03f + (pointerDistanceInMeters / kpointerGrowthAngle) : pointerOuterDiameter * pointerDistanceInMeters); materialComp.SetFloat("_DistanceInMeters", pointerDistanceInMeters); }
// Update is called once per frame void Update() { if (!WaveVR.Instance.Initialized) { return; } if (WaveVR.Instance.FocusCapturedBySystem) { return; } #if UNITY_EDITOR if (Application.isEditor) { return; } #endif if (!WaveVR_Controller.Input(this.device).connected) { return; } WVR_DeviceType _type = WaveVR_Controller.Input(this.device).DeviceType; uint buttons = 0, touches = 0; uint analogArrayCount = (uint)Interop.WVR_GetInputTypeCount(_type, WVR_InputType.WVR_InputType_Analog); WVR_AnalogState_t[] analogArray = new WVR_AnalogState_t[analogArrayCount]; if (Interop.WVR_GetInputDeviceState(_type, inputMask, ref buttons, ref touches, analogArray, analogArrayCount)) { ClickedEventArgs e; e.device = _type; e.flags = buttons; e.axis = Vector2.zero; /** * for Button **/ if (buttons != 0) { ulong btnState = (ulong)buttons; //if (Log.FLAG_BUTTON) // Log.d (LOG_TAG, "_type: " + _type + " btnState: " + btnState); if ((btnState & Input_Mask_Trigger) != 0) { if (triggerPressed == false) // trigger false -> true { triggerPressed = true; e.axis = GetAxis( analogArray, WVR_InputId.WVR_InputId_Alias1_Trigger, WVR_AnalogType.WVR_AnalogType_1D, (int)analogArrayCount); OnTriggerClicked(e); } } if ((btnState & Input_Mask_Grip) != 0) { if (gripPressed == false) // grep false -> true { gripPressed = true; OnGripped(e); } } if ((btnState & Input_Mask_Touchpad) != 0) { if (padPressed == false) // touchpad false -> true { e.axis = GetAxis( analogArray, WVR_InputId.WVR_InputId_Alias1_Touchpad, WVR_AnalogType.WVR_AnalogType_2D, (int)analogArrayCount); padPressed = true; OnPadClicked(e); } } if ((btnState & Input_Mask_Menu) != 0) { if (menuPressed == false) // menu false -> true { menuPressed = true; OnMenuClicked(e); } } if ((btnState & Input_Mask_Hmd_Enter) != 0) { if (hmdEnterPressed == false) { hmdEnterPressed = true; OnHmdEnterClicked(e); } } } else { if (triggerPressed == true) { triggerPressed = false; OnTriggerUnclicked(e); } if (gripPressed == true) { gripPressed = false; OnUngripped(e); } if (padPressed == true) { padPressed = false; OnPadUnclicked(e); } if (menuPressed == true) { menuPressed = false; OnMenuUnclicked(e); } if (hmdEnterPressed == true) { hmdEnterPressed = false; OnHmdEnterUnclicked(e); } } // if (buttons != 0) /** * for Touch **/ e.flags = touches; if (touches != 0) { ulong touchState = (ulong)touches; //if (Log.FLAG_BUTTON) // Log.d (LOG_TAG, "_type: " + _type + " touchState: " + touchState); if ((touchState & Input_Mask_Touchpad) != 0) { if (padTouched == false) // touchpad false -> true { padTouched = true; e.axis = GetAxis( analogArray, WVR_InputId.WVR_InputId_Alias1_Touchpad, WVR_AnalogType.WVR_AnalogType_2D, (int)analogArrayCount); OnPadTouched(e); } } } else { if (padTouched == true) { padTouched = false; OnPadUntouched(e); } } // if (touches != 0) } else { Log.e(LOG_TAG, "_type: " + _type + " WVR_GetInputDeviceState failed!"); } // WVR_GetInputDeviceState } // Update
// Update is called once per frame void Update() { if (Battery_Effect != null) { if (!getValidBattery) { if (t++ > 300) { getValidBattery = updateBatteryInfo(); t = 0; } } } //WVR_InputId_Alias1_Trigger if (WaveVR_Controller.Input(device).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Trigger)) { Log.d(LOG_TAG, "WVR_InputId_Alias1_Trigger press down"); if (Trigger_Effect != null) { Trigger_Effect.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPress(WVR_InputId.WVR_InputId_Alias1_Trigger)) { if (Trigger_Effect != null) { Trigger_Effect.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Trigger)) { Log.d(LOG_TAG, "WVR_InputId_Alias1_Trigger press up"); if (Trigger_Effect != null) { Trigger_Effect.SetActive(false); } } //WVR_InputId_Alias1_Volume_Up if (WaveVR_Controller.Input(device).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Volume_Up)) { Log.d(LOG_TAG, "WVR_InputId_Alias1_Volume_Up press down"); if (VolumeUp_Effect != null) { VolumeUp_Effect.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPress(WVR_InputId.WVR_InputId_Alias1_Volume_Up)) { if (VolumeUp_Effect != null) { VolumeUp_Effect.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Volume_Up)) { Log.d(LOG_TAG, "WVR_InputId_Alias1_Volume_Up press up"); if (VolumeUp_Effect != null) { VolumeUp_Effect.SetActive(false); } } //WVR_InputId_Alias1_Volume_Down if (WaveVR_Controller.Input(device).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Volume_Down)) { Log.d(LOG_TAG, "WVR_InputId_Alias1_Volume_Down press down"); if (VolumeDown_Effect != null) { VolumeDown_Effect.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPress(WVR_InputId.WVR_InputId_Alias1_Volume_Down)) { if (VolumeDown_Effect != null) { VolumeDown_Effect.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Volume_Down)) { Log.d(LOG_TAG, "WVR_InputId_Alias1_Volume_Down press up"); if (VolumeDown_Effect != null) { VolumeDown_Effect.SetActive(false); } } //WVR_InputId_Alias1_Grip if (WaveVR_Controller.Input(device).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Grip)) { Log.d(LOG_TAG, "WVR_InputId_Alias1_Grip press down"); if (Grip_Effect != null) { Grip_Effect.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPress(WVR_InputId.WVR_InputId_Alias1_Grip)) { if (Grip_Effect != null) { Grip_Effect.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Grip)) { Log.d(LOG_TAG, "WVR_InputId_Alias1_Grip press up"); if (Grip_Effect != null) { Grip_Effect.SetActive(false); } } //WVR_InputId_Alias1_Bumper if (WaveVR_Controller.Input(device).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Bumper)) { Log.d(LOG_TAG, "WVR_InputId_Alias1_Bumper press down"); if (BumperPress != null) { BumperPress.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPress(WVR_InputId.WVR_InputId_Alias1_Bumper)) { if (BumperPress != null) { BumperPress.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Bumper)) { Log.d(LOG_TAG, "WVR_InputId_Alias1_Bumper press up"); if (BumperPress != null) { BumperPress.SetActive(false); } } //WVR_InputId_Alias1_Touchpad if (WaveVR_Controller.Input(device).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { isTouchPressed = true; if (Touch_Press != null) { Touch_Press.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPress(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { if (Touch_Press != null) { if (Touch_Effect != null) { Touch_Effect.SetActive(false); } Touch_Press.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { isTouchPressed = false; if (Touch_Press != null) { Touch_Press.SetActive(false); } } // button touch down if (WaveVR_Controller.Input(device).GetTouchDown(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { if (!isTouchPressed && Touch_Effect != null) { Touch_Effect.SetActive(true); } } // button touch up if (WaveVR_Controller.Input(device).GetTouchUp(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { if (Touch_Effect != null) { Touch_Effect.SetActive(false); } } // button touched if (WaveVR_Controller.Input(device).GetTouch(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { if (!isTouchPressed) { if (Touch_Effect != null) { Touch_Effect.SetActive(true); } if (TouchPad != null && Touch_Effect != null) { var axis = WaveVR_Controller.Input(device).GetAxis(WVR_InputId.WVR_InputId_Alias1_Touchpad); float xangle = axis.x * (touchpadMesh.bounds.size.x * TouchPad.transform.localScale.x - toucheffectMesh.bounds.size.x * Touch_Effect.transform.localScale.x) / 2; float yangle = axis.y * (touchpadMesh.bounds.size.y * TouchPad.transform.localScale.y - toucheffectMesh.bounds.size.y * Touch_Effect.transform.localScale.y) / 2; Log.d(LOG_TAG, "WVR_InputId_Alias1_Touchpad axis x: " + axis.x + ", xangle: " + xangle + " axis.y: " + axis.y + ", yangle: " + yangle); #if DEBUG Log.d(LOG_TAG, "Touch_EffectMesh.bounds.size.x: " + toucheffectMesh.bounds.size.x); Log.d(LOG_TAG, "Touch_EffectMesh.bounds.size.y: " + toucheffectMesh.bounds.size.y); Log.d(LOG_TAG, "Touch_EffectMesh. x scale: " + Touch_Effect.transform.localScale.x); Log.d(LOG_TAG, "Touch_EffectMesh. y scale: " + Touch_Effect.transform.localScale.y); Log.d(LOG_TAG, "touchpadMesh.bounds.size.x: " + touchpadMesh.bounds.size.x); Log.d(LOG_TAG, "touchpadMesh.bounds.size.y: " + touchpadMesh.bounds.size.y); Log.d(LOG_TAG, "touchpadMesh. x scale: " + TouchPad.transform.localScale.x); Log.d(LOG_TAG, "touchpadMesh. y scale: " + TouchPad.transform.localScale.y); #endif var translateVec = new Vector3(xangle, yangle, 0); Touch_Effect.transform.localPosition = originPosition + translateVec; } } } }
private void processVREvent(WVR_Event_t vrEvent) { WVR_DeviceType _type = vrEvent.device.type; WVR_InputId _btn = vrEvent.input.inputId; // Process events used by plugin switch ((WVR_EventType)vrEvent.common.type) { case WVR_EventType.WVR_EventType_IpdChanged: WaveVR_Utils.Event.Send(WaveVR_Utils.Event.IPD_CHANGED); if (WaveVR_Render.Instance != null) { WaveVR_Render.Expand(WaveVR_Render.Instance); } break; case WVR_EventType.WVR_EventType_DeviceStatusUpdate: WaveVR_Utils.Event.Send(WaveVR_Utils.Event.DEVICE_STATUS_UPDATE, vrEvent.device.common.type); break; case WVR_EventType.WVR_EventType_BatteryStatusUpdate: WaveVR_Utils.Event.Send(WaveVR_Utils.Event.BATTERY_STATUS_UPDATE); break; case WVR_EventType.WVR_EventType_LeftToRightSwipe: case WVR_EventType.WVR_EventType_RightToLeftSwipe: case WVR_EventType.WVR_EventType_DownToUpSwipe: case WVR_EventType.WVR_EventType_UpToDownSwipe: PrintDebugLog("Swipe event: " + (WVR_EventType)vrEvent.common.type); WaveVR_Utils.Event.Send(WaveVR_Utils.Event.SWIPE_EVENT, vrEvent.common.type, _type); break; case WVR_EventType.WVR_EventType_DeviceRoleChanged: PrintDebugLog("WVR_EventType_DeviceRoleChanged() " + _type + ", " + _btn + ", Resend connection notification after switching hand."); WaveVR.Instance.UpdateAllConnection(); if (WaveVR.Instance.SetLeftHandedMode()) { // Due to connected, valid pose and role change are not synchronized, DEVICE_ROLE_CHANGED will be obseleted. WaveVR_Utils.Event.Send(WaveVR_Utils.Event.DEVICE_ROLE_CHANGED); WaveVR.Instance.ResetAllButtonStates(); } break; case WVR_EventType.WVR_EventType_ButtonPressed: PrintDebugLog("WVR_EventType_ButtonPressed() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded); if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance.Initialized) { _type = WaveVR.Instance.getDeviceByType(_type).type; } WaveVR_Controller.Input(_type).SetEventState_Press(_btn, true); break; case WVR_EventType.WVR_EventType_ButtonUnpressed: PrintDebugLog("WVR_EventType_ButtonUnpressed() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded); if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance.Initialized) { _type = WaveVR.Instance.getDeviceByType(_type).type; } WaveVR_Controller.Input(_type).SetEventState_Press(_btn, false); break; case WVR_EventType.WVR_EventType_TouchTapped: PrintDebugLog("WVR_EventType_TouchTapped() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded); if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance.Initialized) { _type = WaveVR.Instance.getDeviceByType(_type).type; } WaveVR_Controller.Input(_type).SetEventState_Touch(_btn, true); break; case WVR_EventType.WVR_EventType_TouchUntapped: PrintDebugLog("WVR_EventType_TouchUntapped() " + _type + ", " + _btn + ", left-handed? " + WaveVR_Controller.IsLeftHanded); if (_type != WVR_DeviceType.WVR_DeviceType_Invalid && WaveVR.Instance.Initialized) { _type = WaveVR.Instance.getDeviceByType(_type).type; } WaveVR_Controller.Input(_type).SetEventState_Touch(_btn, false); break; case WVR_EventType.WVR_EventType_DeviceConnected: PrintDebugLog("WVR_EventType_DeviceConnected() " + _type + ", left-handed? " + WaveVR_Controller.IsLeftHanded); WaveVR.Instance.SetConnectionStatus(_type, true); break; case WVR_EventType.WVR_EventType_DeviceDisconnected: PrintDebugLog("WVR_EventType_DeviceDisconnected() " + _type + ", left-handed? " + WaveVR_Controller.IsLeftHanded); WaveVR.Instance.SetConnectionStatus(_type, false); if (_type != WVR_DeviceType.WVR_DeviceType_Invalid) { _type = WaveVR_Controller.Input(_type).DeviceType; WaveVR_Controller.Input(_type).ResetButtonEvents(); } break; default: break; } // Send event to developer for all kind of event if developer don't want to add callbacks for every event. WaveVR_Utils.Event.Send(WaveVR_Utils.Event.ALL_VREVENT, vrEvent); // Send event to developer by name. WaveVR_Utils.Event.Send(vrEvent.common.type.ToString(), vrEvent); }
private void onDeviceConnected(params object[] args) { WVR_DeviceType eventType = (WVR_DeviceType)args[0]; WVR_DeviceType _type = WVR_DeviceType.WVR_DeviceType_Invalid; bool _connected = false; #if UNITY_EDITOR if (Application.isEditor) { _connected = WaveVR_Controller.Input(this.deviceType).connected; _type = WaveVR_Controller.Input(this.deviceType).DeviceType; } else #endif { WaveVR.Device _device = WaveVR.Instance.getDeviceByType(this.deviceType); _connected = _device.connected; _type = _device.type; if (eventType != _type) { PrintDebugLog("onDeviceConnected() event type is " + eventType + ", this.deviceType is " + _type + ", skip"); return; } } PrintDebugLog("onDeviceConnected() " + _type + " is " + (_connected ? "connected" : "disconnected") + ", left-handed? " + WaveVR_Controller.IsLeftHanded); if (connected != _connected) { connected = _connected; if (connected) { if (!checkChild()) { if (isProcessing) { PrintDebugLog("onDeviceConnected - Controller connected, model is loading!"); } else { PrintDebugLog("Controller load when onDeviceConnected!"); onLoadController(_type); } } else { if (isRenderModelNameSameAsPrevious()) { PrintDebugLog("onDeviceConnected - Controller connected, model was loaded!"); } else { PrintDebugLog("Controller load when onDeviceConnected, render model is different!"); deleteChild(); onLoadController(_type); } } } } }
public override void Process() { if (!enableControllerInputModule) { return; } SetControllerModel(); SetPointerCameraTracker(); foreach (WVR_DeviceType _dt in Enum.GetValues(typeof(WVR_DeviceType))) { // HMD uses Gaze, not controller input module. if (_dt == WVR_DeviceType.WVR_DeviceType_HMD) { continue; } EventController _eventController = (EventController)EventControllers [_dt]; if (_eventController == null) { continue; } GameObject _controller = _eventController.controller; if (_controller == null) { continue; } bool _connected = false; #if UNITY_EDITOR if (Application.isEditor) { // "connected" from WaveVR_Controller means the real connection status of controller. _connected = WaveVR_Controller.Input(_dt).connected; } else #endif { // "connected" from WaveVR means the "pose" is valid or not. WaveVR.Device _device = WaveVR.Instance.getDeviceByType(_dt); _connected = _device.connected; } if (!_connected) { continue; } if (_eventController.pointer == null) { _eventController.pointer = _eventController.controller.GetComponentInChildren <WaveVR_ControllerPointer> (); } if (_connected) { if ((_dt == WVR_DeviceType.WVR_DeviceType_Controller_Left && pointCameraL == null) || (_dt == WVR_DeviceType.WVR_DeviceType_Controller_Right && pointCameraR == null)) { SetupPointerCamera(_dt); } } Camera _event_camera; // Mouse mode: raycasting from HMD after direct raycasting from controller if (RaycastMode == ERaycastMode.Mouse) { _event_camera = _dt == WVR_DeviceType.WVR_DeviceType_Controller_Left ? pointCameraL.GetComponent <Camera>() : pointCameraR.GetComponent <Camera>(); _eventController.prevRaycastedObject = GetRaycastedObject(_dt); if (_eventController.pointer != null) { _eventController.pointer.setRaycastMode(RaycastMode); } // 1. Get graphic raycast object. ResetPointerEventData_Hybrid(_dt, _event_camera); } else { _event_camera = (Camera)_controller.GetComponent(typeof(Camera)); if (_event_camera == null) { continue; } if (_eventController.pointer != null) { _eventController.pointer.setRaycastMode(RaycastMode); } _eventController.prevRaycastedObject = GetRaycastedObject(_dt); // 1. Get graphic raycast object. ResetPointerEventData(_dt); } GraphicRaycast(_eventController, _event_camera); if (GetRaycastedObject(_dt) == null) { // 2. Get physic raycast object. PhysicsRaycaster _raycaster = null; if (RaycastMode == ERaycastMode.Mouse) { _raycaster = _event_camera.GetComponent <PhysicsRaycaster>(); } else { _raycaster = _controller.GetComponent <PhysicsRaycaster>(); } if (_raycaster == null) { continue; } if (RaycastMode == ERaycastMode.Mouse) { ResetPointerEventData_Hybrid(_dt, _event_camera); } else { ResetPointerEventData(_dt); } PhysicRaycast(_eventController, _raycaster); } // 3. Exit previous object, enter new object. OnTriggerEnterAndExit(_dt, _eventController.event_data); // 4. Hover object. GameObject _curRaycastedObject = GetRaycastedObject(_dt); if (_curRaycastedObject != null && _curRaycastedObject == _eventController.prevRaycastedObject) { OnTriggerHover(_dt, _eventController.event_data); } // 5. Get button state. bool btnPressDown = false, btnPressed = false, btnPressUp = false; if (_dt == WVR_DeviceType.WVR_DeviceType_Controller_Left || _dt == WVR_DeviceType.WVR_DeviceType_Controller_Right) { int _mousekey = _dt == WVR_DeviceType.WVR_DeviceType_Controller_Left ? 0 : 1; btnPressDown = Input.GetMouseButtonDown(_mousekey); btnPressed = Input.GetMouseButton(_mousekey); btnPressUp = Input.GetMouseButtonUp(_mousekey); } btnPressDown |= WaveVR_Controller.Input(_dt).GetPressDown((WVR_InputId)ButtonToTrigger); btnPressed |= WaveVR_Controller.Input(_dt).GetPress((WVR_InputId)ButtonToTrigger); btnPressUp |= WaveVR_Controller.Input(_dt).GetPressUp((WVR_InputId)ButtonToTrigger); if (btnPressDown) { _eventController.eligibleForButtonClick = true; } // Pointer Click equals to Button.onClick, we sent Pointer Click in OnTriggerUp() //if (btnPressUp && _eventController.eligibleForButtonClick) //onButtonClick (_eventController); if (!btnPressDown && btnPressed) { // button hold means to drag. OnDrag(_dt, _eventController.event_data); } else if (Time.unscaledTime - _eventController.event_data.clickTime < CLICK_TIME) { // Delay new events until CLICK_TIME has passed. } else if (btnPressDown && !_eventController.event_data.eligibleForClick) { // 1. button not pressed -> pressed. // 2. no pending Click should be procced. OnTriggerDown(_dt, _eventController.event_data); } else if (!btnPressed) { // 1. If Down before, send Up event and clear Down state. // 2. If Dragging, send Drop & EndDrag event and clear Dragging state. // 3. If no Down or Dragging state, do NOTHING. OnTriggerUp(_dt, _eventController.event_data); } if (RaycastMode != ERaycastMode.Mouse) { UpdateReticlePointer(_eventController); } } }
private void OnEnable() { #if CVR_VIVEWAVE if (IsController && !hasCompletedDelay) { return; } #endif StartingScale = transform.lossyScale; if (CognitiveVR.Core.IsInitialized) { string tempMeshName = UseCustomMesh ? MeshName : CommonMesh.ToString().ToLower(); if (!UseCustomMesh && CommonMesh == CommonDynamicMesh.WindowsMixedRealityRight) { tempMeshName = "windows_mixed_reality_controller_right"; } if (!UseCustomMesh && CommonMesh == CommonDynamicMesh.WindowsMixedRealityLeft) { tempMeshName = "windows_mixed_reality_controller_left"; } if (SyncWithPlayerGazeTick) { UpdateRate = 64; } string registerid = UseCustomId ? CustomId : ""; if (!UseCustomId && IdPool != null) { UseCustomId = true; CustomId = IdPool.GetId(); registerid = CustomId; } var Data = new DynamicData(gameObject.name, registerid, tempMeshName, transform, transform.position, transform.rotation, transform.lossyScale, PositionThreshold, RotationThreshold, ScaleThreshold, UpdateRate, IsController, ControllerType.ToString(), IsRight); DataId = Data.Id; if (IsController) { #if CVR_VIVEWAVE var devicetype = GetComponent <WaveVR_PoseTrackerManager>().Type; if (WaveVR_Controller.Input(devicetype).DeviceType == wvr.WVR_DeviceType.WVR_DeviceType_Controller_Left) { Data.IsRightHand = false; } else { Data.IsRightHand = true; } CognitiveVR.GameplayReferences.SetController(gameObject, Data.IsRightHand); #endif #if CVR_WINDOWSMR CognitiveVR.GameplayReferences.SetController(gameObject, IsRight); #endif CognitiveVR.DynamicManager.RegisterController(Data); } else { CognitiveVR.DynamicManager.RegisterDynamicObject(Data); } if (SyncWithPlayerGazeTick) { CognitiveVR.Core.TickEvent += Core_TickEvent; } } else { CognitiveVR.Core.InitEvent += OnCoreInitialize; } }
public void OnPointerHover(PointerEventData eventData) { if (GameManager.Instance.controller == null) { if (GameManager.Instance.GetCurrentstate().Equals("MARK")) { Debug3D.Instance.Debug("mark" + this.gameObject.name); if (WaveVR_Controller.Input(WVR_DeviceType.WVR_DeviceType_Controller_Right).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Bumper) && this.gameObject.layer == 4) { Debug3D.Instance.Debug("开始捡去物体"); GameManager.Instance.PutObject(this.gameObject); //GameManager.Instance.SetColliderEnableFalse(this.gameObject); GameManager.Instance.BecomeChild(this.gameObject); if (this.gameObject.name.Equals(GameManager.Instance.curGuideassemblestate.ToString())) { if (this.gameObject.name == "jiban") { SourceManager.Instance.PlayTrue(); LogicManager.Instance.SetComponents("jiban", false); LogicManager.Instance.Setposition("jiban", true); LogicManager.Instance.SetValueColor("jiban", 1, false); //GameManager.Instance.SetcurGuideassemblestate("jiban"); GameManager.Instance.controller = null; } LogicManager.Instance.SetValueColor(this.gameObject.name, 0, true); } else { SourceManager.Instance.PlayError(); LogicManager.Instance.SetValueColor(this.gameObject.name, 2, true); } } } } if (GameManager.Instance.controller != null) { Debug3D.Instance.Debug("kaishimark+:" + this.name); if (GameManager.Instance.GetCurrentstate().Equals("MARK")) { Debug3D.Instance.Debug("jiaixngmark:" + this.name); if (this.gameObject.layer == 1) { GameManager.Instance.isColliter = false; Debug3D.Instance.Debug("开始move" + this.name); if (WaveVR_Controller.Input(WVR_DeviceType.WVR_DeviceType_Controller_Right).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Bumper)) { if (this.gameObject.name.Equals(GameManager.Instance.curGuideassemblestate.ToString())) { GameManager.Instance.MoveDestination(this.gameObject); GameManager.Instance.LeaveParent(); // GameManager.Instance.SetColliderEnableTrue(); GameManager.Instance.controller = null; } } } } } GameManager.Instance.isColliter = true; }
// Update is called once per frame void Update() { //WVR_InputId_Alias1_Menu if (WaveVR_Controller.Input(device).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Menu)) { if (MenuButtonPress_Effect != null) { MenuButtonPress_Effect.SetActive(true); } } // button pressed if (WaveVR_Controller.Input(device).GetPress(WVR_InputId.WVR_InputId_Alias1_Menu)) { if (MenuButtonPress_Effect != null) { MenuButtonPress_Effect.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Menu)) { if (MenuButtonPress_Effect != null) { MenuButtonPress_Effect.SetActive(false); } } //WVR_InputId_Alias1_Touchpad if (WaveVR_Controller.Input(device).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { if (Touch_Effect != null) { Touch_Effect.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPress(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { if (Touch_Effect != null) { Touch_Effect.SetActive(true); } } if (WaveVR_Controller.Input(device).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { if (Touch_Effect != null) { Touch_Effect.SetActive(false); } } // button touch down if (WaveVR_Controller.Input(device).GetTouchDown(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { if (Touch_Effect != null) { Touch_Effect.SetActive(true); } } // button touch up if (WaveVR_Controller.Input(device).GetTouchUp(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { if (Touch_Effect != null) { Touch_Effect.SetActive(false); } } // button touched if (WaveVR_Controller.Input(device).GetTouch(WVR_InputId.WVR_InputId_Alias1_Touchpad)) { var axis = WaveVR_Controller.Input(device).GetAxis(WVR_InputId.WVR_InputId_Alias1_Touchpad); float xangle = axis.x / 100, yangle = axis.y / 100; //Log.d(LOG_TAG, "WVR_InputId_Alias1_Touchpad axis xangle: " + xangle + ", yangle: " + yangle); if (xangle > 0.006f) { xangle = 0.006f; } if (xangle < -0.009f) { xangle = -0.009f; } if (yangle > 0.006f) { yangle = 0.006f; } if (yangle < -0.009f) { yangle = -0.009f; } if (Touch_Effect != null) { var translateVec = new Vector3(xangle, yangle, 0); Touch_Effect.transform.localPosition = originPosition + translateVec; } } //WVR_InputId_Alias1_Grip if (WaveVR_Controller.Input(device).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Grip)) { Log.d(LOG_TAG, "WVR_InputId.WVR_InputId_Alias1_Grip press down."); } // button pressed if (WaveVR_Controller.Input(device).GetPress(WVR_InputId.WVR_InputId_Alias1_Grip)) { Log.d(LOG_TAG, "WVR_InputId.WVR_InputId_Alias1_Grip press down."); } if (WaveVR_Controller.Input(device).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Grip)) { Log.d(LOG_TAG, "WVR_InputId.WVR_InputId_Alias1_Grip press down."); } //WVR_InputId_Alias1_Trigger if (WaveVR_Controller.Input(device).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Trigger)) { Log.d(LOG_TAG, "WVR_InputId.WVR_InputId_Alias1_Trigger press down."); } // button pressed if (WaveVR_Controller.Input(device).GetPress(WVR_InputId.WVR_InputId_Alias1_Trigger)) { Log.d(LOG_TAG, "WVR_InputId.WVR_InputId_Alias1_Trigger press down."); } if (WaveVR_Controller.Input(device).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Trigger)) { Log.d(LOG_TAG, "WVR_InputId.WVR_InputId_Alias1_Trigger press down."); } // button touch down if (WaveVR_Controller.Input(device).GetTouchDown(WVR_InputId.WVR_InputId_Alias1_Trigger)) { // do nothing } // button touch up if (WaveVR_Controller.Input(device).GetTouchUp(WVR_InputId.WVR_InputId_Alias1_Trigger)) { // do nothing } // button touched if (WaveVR_Controller.Input(device).GetTouch(WVR_InputId.WVR_InputId_Alias1_Trigger)) { // do nothing } }
// Update is called once per frame void Update() { if (!enableButtonEffect) { return; } if (currentIsLeftHandMode != WaveVR_Controller.IsLeftHanded) { currentIsLeftHandMode = WaveVR_Controller.IsLeftHanded; PrintInfoLog("Controller role is changed to " + (currentIsLeftHandMode ? "Left" : "Right") + " and reset button state"); resetButtonState(); } for (int i = 0; i < pressIds.Length; i++) { if (pressObjectArrays[i] == null) { continue; } if (WaveVR_Controller.Input(device).GetPressDown(pressIds[i])) { PrintInfoLog(pressIds[i] + " press down"); if (pressObjectArrays[i].hasEffect) { if (pressObjectArrays[i].gameObject != null && pressObjectArrays[i].originMat != null && pressObjectArrays[i].effectMat != null) { pressObjectArrays[i].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[i].effectMat; } } } if (WaveVR_Controller.Input(device).GetPress(pressIds[i])) { if (pressObjectArrays[i].hasEffect) { if (pressObjectArrays[i].gameObject != null && pressObjectArrays[i].originMat != null && pressObjectArrays[i].effectMat != null) { pressObjectArrays[i].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[i].effectMat; } } } if (WaveVR_Controller.Input(device).GetPressUp(pressIds[i])) { PrintInfoLog(pressIds[i] + " press up"); if (pressObjectArrays[i].hasEffect) { if (pressObjectArrays[i].gameObject != null && pressObjectArrays[i].originMat != null && pressObjectArrays[i].effectMat != null) { pressObjectArrays[i].gameObject.GetComponent <MeshRenderer>().material = pressObjectArrays[i].originMat; } } } } for (int i = 0; i < touchIds.Length; i++) { if (touchObjectArrays[i] == null) { continue; } if (WaveVR_Controller.Input(device).GetTouchDown(touchIds[i])) { PrintInfoLog(touchIds[i] + " touch down"); if (touchObjectArrays[i].hasEffect) { if (touchObjectArrays[i].gameObject != null && touchObjectArrays[i].originMat != null && touchObjectArrays[i].effectMat != null) { touchObjectArrays[i].gameObject.GetComponent <MeshRenderer>().material = touchObjectArrays[i].effectMat; touchObjectArrays[i].gameObject.SetActive(true); } } } if (WaveVR_Controller.Input(device).GetTouch(touchIds[i])) { if (touchObjectArrays[i].hasEffect && touchObjectArrays[i].MeshName == "__CM__TouchPad_Touch") { if (touchObjectArrays[i].gameObject != null && touchObjectArrays[i].originMat != null && touchObjectArrays[i].effectMat != null) { var axis = WaveVR_Controller.Input(this.device).GetAxis(WVR_InputId.WVR_InputId_Alias1_Touchpad); float xangle = axis.x * (touchpadMesh.bounds.size.x * touchpad.transform.localScale.x - toucheffectMesh.bounds.size.x * touchObjectArrays[i].gameObject.transform.localScale.x) / 2; float yangle = axis.y * (touchpadMesh.bounds.size.z * touchpad.transform.localScale.z - toucheffectMesh.bounds.size.z * touchObjectArrays[i].gameObject.transform.localScale.z) / 2; var height = touchpadMesh.bounds.size.y * touchpad.transform.localScale.y; Log.gpl.d(LOG_TAG, "WVR_InputId_Alias1_Touchpad axis x: " + axis.x + " axis.y: " + axis.y + ", xangle: " + xangle + ", yangle: " + yangle + ", height: " + height); #if DEBUG Log.gpl.d(LOG_TAG, "TouchEffectMesh.bounds.size: " + toucheffectMesh.bounds.size.x + ", " + toucheffectMesh.bounds.size.y + ", " + toucheffectMesh.bounds.size.z); Log.gpl.d(LOG_TAG, "TouchEffectMesh.scale: " + touchObjectArrays[i].gameObject.transform.localScale.x + ", " + touchObjectArrays[i].gameObject.transform.localScale.y + ", " + touchObjectArrays[i].gameObject.transform.localScale.z); Log.gpl.d(LOG_TAG, "TouchpadMesh.bounds.size: " + touchpadMesh.bounds.size.x + ", " + touchpadMesh.bounds.size.y + ", " + touchpadMesh.bounds.size.z); Log.gpl.d(LOG_TAG, "TouchpadMesh. scale: " + touchObjectArrays[i].gameObject.transform.localScale.x + ", " + touchObjectArrays[i].gameObject.transform.localScale.y + ", " + touchObjectArrays[i].gameObject.transform.localScale.z); Log.gpl.d(LOG_TAG, "TouchEffect.originPosition: " + touchObjectArrays[i].originPosition.x + ", " + touchObjectArrays[i].originPosition.y + ", " + touchObjectArrays[i].originPosition.z); #endif Vector3 translateVec = Vector3.zero; translateVec = new Vector3(xangle, height, yangle); touchObjectArrays[i].gameObject.transform.localPosition = touchObjectArrays[i].originPosition + translateVec; } } } if (WaveVR_Controller.Input(device).GetTouchUp(touchIds[i])) { PrintInfoLog(touchIds[i] + " touch up"); if (touchObjectArrays[i].hasEffect) { if (touchObjectArrays[i].gameObject != null && touchObjectArrays[i].originMat != null && touchObjectArrays[i].effectMat != null) { touchObjectArrays[i].gameObject.GetComponent <MeshRenderer>().material = touchObjectArrays[i].originMat; touchObjectArrays[i].gameObject.SetActive(false); } } } } }
void Update() { /** * 1. Resets the input requests when the input options change. **/ UpdateOptionValues(); if (m_HmdOptionValue != m_HmdOptions.optionValue) { m_HmdOptionValue = m_HmdOptions.optionValue; DEBUG("Update() HMD options changed to " + m_HmdOptionValue); ResetInputRequest(WaveVR_Controller.EDeviceType.Head); } if (m_DominantOptionValue != m_DominantOptions.optionValue) { m_DominantOptionValue = m_DominantOptions.optionValue; DEBUG("Update() Dominant options changed to " + m_DominantOptionValue); ResetInputRequest(WaveVR_Controller.EDeviceType.Dominant); } if (m_NonDominantOptionValue != m_NonDominantOptions.optionValue) { m_NonDominantOptionValue = m_NonDominantOptions.optionValue; DEBUG("Update() Dominant options changed to " + m_NonDominantOptionValue); ResetInputRequest(WaveVR_Controller.EDeviceType.NonDominant); } /** * 2. [Important] Resets the input requests when a device is going to be connected. * Considers below two cases when using only 1 controller: * Case 1. * 1. Right-handed mode * 2. Right (dominant): connected, left (non-dominant): disconnected * 3. Connection events. * 4. Right: connected -> disconnected, left: disconnected -> connected, * 5. Dominant (right): connected -> disconnected, non-dominant (left): disconnected -> connected * 6. SetInputRequest (non-dominant) * 7. Role change to left-handed mode * 8. Dominant (left): disconnected -> connected. non-dominant (right): connected -> disconnected * 9. SetInputRequest (dominant) * Case 2. * 1. Right-handed mode * 2. Right (dominant): connected, left (non-dominant): disconnected * 3. Role change to left-handed mode * 4. Dominant (left): connected -> disconnected, non-dominant (right): disconnected -> connected * 5. SetInputRequest (non-dominant) * 6. Connection events. * 7. Right: connected -> disconnected, left: disconnected -> connected * 8. Dominant (left): disconnected -> connected, non-dominant (right): connected -> disconnected * 9. SetInputRequest (dominant) **/ if (connectionHmd != WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Head).connected) { connectionHmd = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Head).connected; if (connectionHmd) { DEBUG("Update() HMD is connected."); ResetInputRequest(WaveVR_Controller.EDeviceType.Head); } } if (connectionDominant != WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Dominant).connected) { connectionDominant = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Dominant).connected; if (connectionDominant) { DEBUG("Update() Dominant controller is connected."); ResetInputRequest(WaveVR_Controller.EDeviceType.Dominant); } } if (connectionNonDominant != WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.NonDominant).connected) { connectionNonDominant = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.NonDominant).connected; if (connectionNonDominant) { DEBUG("Update() Non-Dominant controller is connected."); ResetInputRequest(WaveVR_Controller.EDeviceType.NonDominant); } } }
private void OnTriggeGaze() { // The gameobject to which raycast positions var currentOverGO = pointerData.pointerCurrentRaycast.gameObject; UpdateReticle(currentOverGO, pointerData); bool sendEvent = false; this.HmdEnterPressDown = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Head).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Enter); if (this.HmdEnterPressDown) { sendEvent = true; } if (pointerData.pointerEnter != currentOverGO) { PrintDebugLog("OnTriggeGaze() pointerEnter: " + pointerData.pointerEnter + ", currentOverGO: " + currentOverGO); HandlePointerExitAndEnter(pointerData, currentOverGO); if (currentOverGO != null) { gazeTime = this.currUnscaledTime; } } else { if (currentOverGO != null) { if (gazePointer != null) { gazePointer.triggerProgressBar(true); } if (this.currUnscaledTime - gazeTime > TimeToGaze) { sendEvent = true; gazeTime = this.currUnscaledTime; } else { float rate = ((this.currUnscaledTime - gazeTime) / TimeToGaze) * 100; if (gazePointer != null) { gazePointer.setProgressBarTime(rate); } } if (this.BtnControl) { if (!this.WithTimeGaze) { gazeTime = this.currUnscaledTime; gazePointer.triggerProgressBar(false); } UpdateButtonStates(); if (btnPressDown) { sendEvent = true; this.gazeTime = this.currUnscaledTime; } } } else { if (gazePointer != null) { gazePointer.triggerProgressBar(false); } } } // Standalone Input Module information pointerData.delta = Vector2.zero; pointerData.dragging = false; DeselectIfSelectionChanged(currentOverGO, pointerData); if (sendEvent) { PrintDebugLog("OnTriggeGaze() selected " + currentOverGO.name); if (InputEvent == EGazeInputEvent.PointerClick) { ExecuteEvents.ExecuteHierarchy(currentOverGO, pointerData, ExecuteEvents.pointerClickHandler); pointerData.clickTime = this.currUnscaledTime; } else if (InputEvent == EGazeInputEvent.PointerDown) { // like "mouse" action, press->release soon, do NOT keep the pointerPressRaycast cause do NOT need to controll "down" object while not gazing. pointerData.pressPosition = pointerData.position; pointerData.pointerPressRaycast = pointerData.pointerCurrentRaycast; var _pointerDownGO = ExecuteEvents.ExecuteHierarchy(currentOverGO, pointerData, ExecuteEvents.pointerDownHandler); ExecuteEvents.ExecuteHierarchy(_pointerDownGO, pointerData, ExecuteEvents.pointerUpHandler); } else if (InputEvent == EGazeInputEvent.PointerSubmit) { ExecuteEvents.ExecuteHierarchy(currentOverGO, pointerData, ExecuteEvents.submitHandler); } } }
public Device Input(WaveVR_Controller.EDeviceType type) { WVR_DeviceType _type = WaveVR_Controller.Input(type).DeviceType; return(ChangeRole(_type)); }