private void ProcessButtonDown(WebInterface.ACTION_BUTTON buttonId, bool useRaycast, LayerMask pointerEventLayer, int globalLayer) { RaycastHitInfo raycastGlobalLayerHitInfo; Ray ray = GetRayFromCamera(); // Raycast for pointer event components RaycastResultInfo raycastInfoPointerEventLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, pointerEventLayer, null); // Raycast for global pointer events RaycastResultInfo raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer, null); raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo; bool isOnClickComponentBlocked = IsBlockingOnClick(raycastInfoPointerEventLayer.hitInfo, raycastGlobalLayerHitInfo); if (!isOnClickComponentBlocked && raycastInfoPointerEventLayer.hitInfo.hit.collider) { Collider collider = raycastInfoPointerEventLayer.hitInfo.hit.collider; GameObject hitGameObject; if (CollidersManager.i.GetColliderInfo(collider, out ColliderInfo info)) { hitGameObject = info.entity.gameObject; } else { hitGameObject = collider.gameObject; } OnClick onClick = hitGameObject.GetComponentInChildren <OnClick>(); if (AreSameEntity(onClick, info)) { onClick.Report(buttonId, raycastInfoPointerEventLayer.hitInfo.hit); } OnPointerDown onPointerDown = hitGameObject.GetComponentInChildren <OnPointerDown>(); if (IsAvatarPointerEvent(onPointerDown) || AreSameEntity(onPointerDown, info)) { onPointerDown.Report(buttonId, ray, raycastInfoPointerEventLayer.hitInfo.hit); } pointerUpEvent = hitGameObject.GetComponentInChildren <OnPointerUp>(); if (!AreSameEntity(pointerUpEvent, info)) { pointerUpEvent = null; } lastPointerDownEventHitInfo = raycastInfoPointerEventLayer.hitInfo; } string sceneId = SceneController.i.currentSceneId; if (useRaycast && raycastGlobalLayerHitInfo.isValid) { CollidersManager.i.GetColliderInfo(raycastGlobalLayerHitInfo.hit.collider, out ColliderInfo colliderInfo); WebInterface.ReportGlobalPointerDownEvent( buttonId, raycastInfoGlobalLayer.ray, raycastGlobalLayerHitInfo.hit.point, raycastGlobalLayerHitInfo.hit.normal, raycastGlobalLayerHitInfo.hit.distance, sceneId, colliderInfo.entity != null ? colliderInfo.entity.entityId : null, colliderInfo.meshName, isHitInfoValid: true); } else { WebInterface.ReportGlobalPointerDownEvent(buttonId, raycastInfoGlobalLayer.ray, Vector3.zero, Vector3.zero, 0, sceneId); } }
private void OnMouseDown() => OnPointerDown?.Invoke(this);
public virtual void InvokeDown() => OnPointerDown?.Invoke();
void IPointerDownHandler.OnPointerDown(PointerEventData eventData) { OnPointerDown?.Invoke(); }
private void ProcessButtonDown(WebInterface.ACTION_BUTTON buttonId, bool useRaycast, LayerMask pointerEventLayer, int globalLayer) { IWorldState worldState = Environment.i.world.state; RaycastHitInfo raycastGlobalLayerHitInfo; Ray ray = GetRayFromCamera(); // Raycast for pointer event components RaycastResultInfo raycastInfoPointerEventLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, pointerEventLayer, worldState.loadedScenes[worldState.currentSceneId]); // Raycast for global pointer events RaycastResultInfo raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer, worldState.loadedScenes[worldState.currentSceneId]); raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo; bool isOnClickComponentBlocked = IsBlockingOnClick(raycastInfoPointerEventLayer.hitInfo, raycastGlobalLayerHitInfo); if (!isOnClickComponentBlocked && raycastInfoPointerEventLayer.hitInfo.hit.collider) { Collider collider = raycastInfoPointerEventLayer.hitInfo.hit.collider; GameObject hitGameObject; if (CollidersManager.i.GetColliderInfo(collider, out ColliderInfo info)) { hitGameObject = info.entity.gameObject; } else { hitGameObject = collider.gameObject; } OnClick onClick = hitGameObject.GetComponentInChildren <OnClick>(); if (AreSameEntity(onClick, info)) { onClick.Report(buttonId, raycastInfoPointerEventLayer.hitInfo.hit); } OnPointerDown onPointerDown = hitGameObject.GetComponentInChildren <OnPointerDown>(); if (IsAvatarPointerEvent(onPointerDown) || AreSameEntity(onPointerDown, info)) { onPointerDown.Report(buttonId, ray, raycastInfoPointerEventLayer.hitInfo.hit); } pointerUpEvent = hitGameObject.GetComponentInChildren <OnPointerUp>(); if (!AreSameEntity(pointerUpEvent, info)) { pointerUpEvent = null; } lastPointerDownEventHitInfo = raycastInfoPointerEventLayer.hitInfo; } ReportGlobalPointerDownEvent(buttonId, useRaycast, raycastGlobalLayerHitInfo, raycastInfoGlobalLayer, worldState.currentSceneId); // Raycast for global pointer events (for each PE scene) List <string> currentPortableExperienceIds = WorldStateUtils.GetActivePortableExperienceIds(); for (int i = 0; i < currentPortableExperienceIds.Count; i++) { raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer, worldState.loadedScenes[currentPortableExperienceIds[i]]); raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo; ReportGlobalPointerDownEvent(buttonId, useRaycast, raycastGlobalLayerHitInfo, raycastInfoGlobalLayer, currentPortableExperienceIds[i]); } }
private void Update() { //Raycast from the current camera forward if (Physics.Raycast(transform.position, transform.forward, out pointerHit, 250f)) { //Update the current pointer args currPointerArgs.target = pointerHit.transform; currPointerArgs.point = pointerHit.point; currPointerArgs.normal = pointerHit.normal; if (prevPointerArgs.target == null || pointerHit.transform == prevPointerArgs.target) { timeToClickCountdown -= Time.deltaTime; //Send the entered event if (enteredTriggered == false) { OnPointerEnter?.Invoke(this, currPointerArgs); enteredTriggered = true; } if (timeToClickCountdown <= 0) { //Send the one time click event if (clickTriggered == false) { OnPointerClicked?.Invoke(this, currPointerArgs); ExecuteEvents.Execute(pointerHit.transform.gameObject, new PointerEventData(EventSystem.current), ExecuteEvents.pointerClickHandler); clickTriggered = true; } OnPointerDown?.Invoke(this, currPointerArgs); //Set the previous hit to the new target prevPointerArgs.target = pointerHit.transform; prevPointerArgs.point = pointerHit.point; prevPointerArgs.normal = pointerHit.normal; } } else { //Exit the old target and enter the new one OnPointerExit?.Invoke(this, prevPointerArgs); OnPointerEnter?.Invoke(this, currPointerArgs); //Set the previous hit to the new target prevPointerArgs.target = pointerHit.transform; prevPointerArgs.point = pointerHit.point; prevPointerArgs.normal = pointerHit.normal; //Reset state variables timeToClickCountdown = timeToClick; enteredTriggered = false; clickTriggered = false; } } else { if (prevPointerArgs.target != null) { //Send the exit event OnPointerExit?.Invoke(this, prevPointerArgs); //Reset state variables prevPointerArgs.target = null; timeToClickCountdown = timeToClick; enteredTriggered = false; clickTriggered = false; } else { timeToClickCountdown = timeToClick; } } //Draw the debug gizmos if (drawDebug) { Debug.DrawLine(transform.position, prevPointerArgs.point, Color.red); } }
public void PointerDown() { OnPointerDown?.Invoke(); }