private void SetGazeInputActive(bool active) { if (reticlePointer == null) { return; } reticlePointer.SetActive(active); // Update the pointer type only if this is currently activated. if (!active) { return; } GvrBasePointer pointer = reticlePointer.GetComponent <GvrBasePointer>(); if (pointer != null) { GvrPointerManager.Pointer = pointer; } }
public void UpdateData() { #if UNITY_HAS_GOOGLEVR && UNITY_ANDROID && !UNITY_EDITOR // Update controller state. GvrBasePointer pointer = GvrPointerManager.Pointer; if (pointer != null && GvrController.State == GvrConnectionState.Connected) { bool pressed = GvrController.ClickButton; gvr_keyboard_update_button_state(keyboard_context, kGvrControllerButtonClick, pressed); Vector3 startPoint = pointer.PointerTransform.position; // Need to flip Z for native library startPoint.z *= -1; IntPtr start_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(startPoint)); Marshal.StructureToPtr(startPoint, start_ptr, true); Vector3 endPoint = pointer.LineEndPoint; // Need to flip Z for native library endPoint.z *= -1; IntPtr end_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(endPoint)); Marshal.StructureToPtr(endPoint, end_ptr, true); Vector3 hit = Vector3.one; IntPtr hit_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(Vector3.zero)); Marshal.StructureToPtr(Vector3.zero, hit_ptr, true); gvr_keyboard_update_controller_ray(keyboard_context, start_ptr, end_ptr, hit_ptr); hit = (Vector3)Marshal.PtrToStructure(hit_ptr, typeof(Vector3)); hit.z *= -1; } #endif // UNITY_HAS_GOOGLEVR && UNITY_ANDROID && !UNITY_EDITOR // Get time stamp. gvr_clock_time_point time = gvr_get_time_point_now(); time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; // Update frame data. GvrKeyboardSetFrameData(keyboard_context, time); GL.IssuePluginEvent(renderEventFunction, advanceID); }
public void Setup() { SubstituteComponent.BeginComponentContext(); // Create input module implementation. module = new GvrPointerInputModuleImpl(); // Create Event System. GameObject eventSystemObj = new GameObject("EventSystem"); eventSytem = eventSystemObj.AddComponent <EventSystem>(); // Create mock pointer. pointer = SubstituteComponent.For <GvrBasePointer>(eventSystemObj); pointer.PointerTransform.Returns(eventSytem.transform); pointer.IsAvailable.Returns(true); module.Pointer = pointer; // Create mock scroll input. scrollInput = new GvrPointerScrollInput(); module.ScrollInput = scrollInput; // Create mock module controller. moduleController = Substitute.For <IGvrInputModuleController>(); moduleController.eventSystem.Returns(eventSytem); resultCache = new List <RaycastResult>(); moduleController.RaycastResultCache.Returns(resultCache); module.ModuleController = moduleController; // Create mock event executor. eventExecutor = Substitute.For <IGvrEventExecutor>(); module.EventExecutor = eventExecutor; // Create dummy objects to use for hit detection. raycastResult = new RaycastResult(); hitObject = new GameObject("HitObject"); hitPos = new Vector3(1.0f, 2.0f, 3.0f); dummyRaycastResult = new RaycastResult(); }
public void HandleScroll(GameObject currentGameObject, PointerEventData pointerData, GvrBasePointer pointer, IGvrEventExecutor eventExecutor) { bool touchDown = false; bool touching = false; bool touchUp = false; Vector2 currentScroll = Vector2.zero; if (pointer != null && pointer.IsAvailable) { touchDown = pointer.TouchDown; touching = pointer.IsTouching; touchUp = pointer.TouchUp; currentScroll = pointer.TouchPos * SCROLL_DELTA_MULTIPLIER; } GameObject currentScrollHandler = eventExecutor.GetEventHandler <IScrollHandler>(currentGameObject); if (touchDown) { RemoveScrollHandler(currentScrollHandler); } if (currentScrollHandler != null && (touchDown || touching)) { OnTouchingScrollHandler( currentScrollHandler, pointerData, currentScroll, eventExecutor); } else if (touchUp && currentScrollHandler != null) { OnReleaseScrollHandler(currentScrollHandler); } StopScrollingIfNecessary(touching, currentScrollHandler); UpdateInertiaScrollHandlers(touching, currentScrollHandler, pointerData, eventExecutor); }
private Camera GetCameraForRaycastMode(GvrBasePointer pointer, GvrBasePointer.RaycastMode mode) { switch (mode) { case GvrBasePointer.RaycastMode.Direct: if (cachedPointerEventCamera == null) { Transform pointerTransform = GvrPointerInputModule.Pointer.PointerTransform; cachedPointerEventCamera = pointerTransform.GetComponent <Camera>(); } if (cachedPointerEventCamera == null) { cachedPointerEventCamera = AddDummyCameraToPointer(pointer); return(null); } return(cachedPointerEventCamera); case GvrBasePointer.RaycastMode.Camera: default: return(pointer.PointerCamera); } }
void Start() { armModels = GameObject.Find("ModesArmModel"); Assert.IsNotNull(armModels); modeController = SceneHelpers.FindObjectOfType <ModeController>(true); Assert.IsNotNull(modeController); initialPointer = GvrPointerInputModule.Pointer; for (int i = 0; i < Camera.allCameras.Length; i++) { GvrPointerPhysicsRaycaster raycaster = Camera.allCameras[i].GetComponent <GvrPointerPhysicsRaycaster>(); if (raycaster != null) { physicsRaycasters.Add(raycaster); } } wasPhysicsRaycasterEnabledArray = new bool[physicsRaycasters.Count]; GameObject customizeMenu = GameObject.Find("CustomizeArmModelUI"); Assert.IsNotNull(customizeMenu); graphicRaycaster = customizeMenu.GetComponent <GvrPointerGraphicRaycaster>(); Assert.IsNotNull(graphicRaycaster); }
private void SetControllerInputActive(bool active) { if (controllerMain != null) { controllerMain.SetActive(active); } if (controllerPointer == null) { return; } controllerPointer.SetActive(active); // Update the pointer type only if this is currently activated. if (!active) { return; } GvrBasePointer pointer = controllerPointer.GetComponentInChildren <GvrBasePointer>(); if (pointer != null) { GvrPointerManager.Pointer = pointer; } }
private void Initialize() { //GazePointer = GazeInputModule.gazePointer; //GazeInputModule.gazePointer = this; if (InternalPointer == null) { InternalPointer = gameObject.AddComponent <GazeClickInternalPointer> (); } if (InternalPointer != GvrPointerInputModule.Pointer) { GazePointer = GvrPointerInputModule.Pointer; } InternalPointer.GazePointer = this; //InternalPointer.transform = GazePointer.transform; InternalPointer.ShouldUseExitRadiusForRaycast = GazePointer.ShouldUseExitRadiusForRaycast; GvrPointerInputModule.Pointer = InternalPointer; TargetMesh = Parent.GetComponent <MeshFilter> ().mesh; RingMesh.vertices = TargetMesh.vertices; RingMesh.triangles = TargetMesh.triangles; RingMesh.RecalculateBounds(); Color[] Colors = new Color[RingMesh.vertices.Length]; for (int i = 0; i < Colors.Length; i++) { if (UseOriginalColor) { Colors [i] = new Color(OriginalColor.r, OriginalColor.g, OriginalColor.b, 1); } else { Colors [i] = new Color(FillColor.r, FillColor.g, FillColor.b, 1); } } RingMesh.colors = Colors; isInitialized = true; }
private Camera GetCameraForRaycastMode(GvrBasePointer pointer, GvrBasePointer.RaycastMode mode) { switch (mode) { case GvrBasePointer.RaycastMode.Direct: if (cachedPointerEventCamera == null) { Transform pointerTransform = GvrPointerInputModule.Pointer.PointerTransform; cachedPointerEventCamera = pointerTransform.GetComponent <Camera>(); } if (cachedPointerEventCamera == null) { Debug.LogError("GvrPointerGraphicRaycaster requires GvrPointer to have a Camera when in Direct mode."); return(null); } return(cachedPointerEventCamera); case GvrBasePointer.RaycastMode.Camera: default: return(pointer.PointerCamera); } }
public void UpdateData() { #if UNITY_ANDROID && !UNITY_EDITOR // Running on Android device. // Update controller state. GvrBasePointer pointer = GvrPointerInputModule.Pointer; bool isPointerAvailable = pointer != null && pointer.IsAvailable; if (isPointerAvailable) { GvrControllerInputDevice controllerInputDevice = pointer.ControllerInputDevice; if (controllerInputDevice != null && controllerInputDevice.State == GvrConnectionState.Connected) { bool pressed = controllerInputDevice.GetButton(GvrControllerButton.TouchPadButton); gvr_keyboard_update_button_state(keyboard_context, kGvrControllerButtonClick, pressed); // Update touch state Vector2 touch_pos = controllerInputDevice.TouchPos; IntPtr touch_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(touch_pos)); Marshal.StructureToPtr(touch_pos, touch_ptr, true); bool isTouching = controllerInputDevice.GetButton(GvrControllerButton.TouchPadTouch); gvr_keyboard_update_controller_touch(keyboard_context, isTouching, touch_ptr); GvrBasePointer.PointerRay pointerRay = pointer.GetRayForDistance(currentDistance); Vector3 startPoint = pointerRay.ray.origin; // Need to flip Z for native library startPoint.z *= -1; IntPtr start_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(startPoint)); Marshal.StructureToPtr(startPoint, start_ptr, true); Vector3 endPoint = pointerRay.ray.GetPoint(pointerRay.distance); // Need to flip Z for native library endPoint.z *= -1; IntPtr end_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(endPoint)); Marshal.StructureToPtr(endPoint, end_ptr, true); Vector3 hit = Vector3.one; IntPtr hit_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(Vector3.zero)); Marshal.StructureToPtr(Vector3.zero, hit_ptr, true); gvr_keyboard_update_controller_ray(keyboard_context, start_ptr, end_ptr, hit_ptr); hit = (Vector3)Marshal.PtrToStructure(hit_ptr, typeof(Vector3)); hit.z *= -1; Marshal.FreeHGlobal(touch_ptr); Marshal.FreeHGlobal(hit_ptr); Marshal.FreeHGlobal(end_ptr); Marshal.FreeHGlobal(start_ptr); } } #endif // UNITY_ANDROID && !UNITY_EDITOR // Get time stamp. gvr_clock_time_point time = gvr_get_time_point_now(); time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; // Update frame data. GvrKeyboardSetFrameData(keyboard_context, time); GL.IssuePluginEvent(renderEventFunction, advanceID); }
public static void OnPointerCreated(GvrBasePointer createdPointer) { GvrPointerInputModule.OnPointerCreated(createdPointer); }
void OnEnable() { previousPointer = GvrPointerInputModule.Pointer; GvrPointerInputModule.Pointer = pointer; }
private Camera GetCameraForRaycastMode(GvrBasePointer pointer, GvrBasePointer.RaycastMode mode) { return(pointer.PointerCamera); }
void Start() { SetGazedAt(false); Drag(false); pointer = GvrPointerInputModule.Pointer; }
/// Calculates the ray for a given Raycast mode. /// Will throw an exception if the raycast mode Hybrid is passed in. /// If you need to calculate the ray for the direct or camera segment of the Hybrid raycast, /// use CalculateHybridRay instead. public static PointerRay CalculateRay(GvrBasePointer pointer, RaycastMode mode) { PointerRay result = new PointerRay(); if (pointer == null || !pointer.IsAvailable) { //Debug.LogError("Cannot calculate ray when the pointer isn't available."); return(result); } Transform pointerTransform = pointer.PointerTransform; if (pointerTransform == null) { Debug.LogError("Cannot calculate ray when pointerTransform is null."); return(result); } result.distance = pointer.MaxPointerDistance; switch (mode) { case RaycastMode.Camera: Camera camera = pointer.PointerCamera; if (camera == null) { Debug.LogError("Cannot calculate ray because pointer.PointerCamera is null." + "To fix this, either tag a Camera as \"MainCamera\" or set overridePointerCamera."); return(result); } Vector3 rayPointerStart = pointerTransform.position; Vector3 rayPointerEnd = rayPointerStart + (pointerTransform.forward * pointer.CameraRayIntersectionDistance); Vector3 cameraLocation = camera.transform.position; Vector3 finalRayDirection = rayPointerEnd - cameraLocation; finalRayDirection.Normalize(); Vector3 finalRayStart = cameraLocation + (finalRayDirection * camera.nearClipPlane); //result.ray = new Ray(finalRayStart, finalRayDirection); break; case RaycastMode.Direct: result.ray = RaycastHelper.singleton.GetDirectRay(); break; case RaycastMode.Hybrid: result.ray = RaycastHelper.singleton.GetDirectRay(); break; case RaycastMode.Mouse: result.ray = pointer.PointerCamera.ScreenPointToRay(Input.mousePosition); break; default: throw new UnityException("Invalid RaycastMode " + mode + " passed into CalculateRay."); } return(result); }