Esempio n. 1
0
        private void Update()
        {
            _prevPointerDownState = _pointerDownState;

            if (UnityEngine.Input.GetMouseButtonDown(0))
            {
                OnPointerDown?.Invoke();
                _pointerDownState = true;
            }

            if (UnityEngine.Input.GetMouseButtonUp(0))
            {
                OnPointerUp?.Invoke();
                _pointerDownState = false;
            }

            Vector2 mousePosition = UnityEngine.Input.mousePosition;
            Vector2 posDifference = mousePosition - _prevMousePos;

            if (posDifference.magnitude > 0f)
            {
                OnPointerMoved?.Invoke(posDifference);
                _prevMousePos = mousePosition;

                if (_prevPointerDownState && _pointerDownState)
                {
                    OnPointerDragged?.Invoke(posDifference);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Executes the OnPointerUp trigger. You can force an execution of this trigger (regardless if it's enabled or not) by calling this method with forcedExecution set to TRUE
        /// </summary>
        /// <param name="forcedExecution">Fires this trigger regardless if it is enabled or not (default:false)</param>
        public void ExecutePointerUp(bool forcedExecution = false)
        {
            if (forcedExecution)
            {
                if (debugThis)
                {
                    Debug.Log("DebugMode - UIButton - " + name + " | Executing OnPointerUp initiated through forcedExecution");
                }
                OnPointerUp.Invoke();
                return;
            }

            if (useOnPointerUp)
            {
                if (debugThis)
                {
                    Debug.Log("DebugMode - UIButton - " + name + " | Executing OnPointerUp");
                }
                if (interactable)
                {
                    OnPointerUp.Invoke();
                }
            }

            if (useOnLongClick)
            {
                StopLongClickListener();
            }
        }
Esempio n. 3
0
        private void ProcessButtonUp(WebInterface.ACTION_BUTTON buttonId, bool useRaycast, LayerMask pointerEventLayer, int globalLayer)
        {
            RaycastHitInfo raycastGlobalLayerHitInfo;
            Ray            ray = GetRayFromCamera();

            // Raycast for global pointer events
            RaycastResultInfo raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer, null);

            raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo;

            if (pointerUpEvent != null)
            {
                // Raycast for pointer event components
                RaycastResultInfo raycastInfoPointerEventLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, pointerEventLayer, null);

                bool isOnClickComponentBlocked  = IsBlockingOnClick(raycastInfoPointerEventLayer.hitInfo, raycastGlobalLayerHitInfo);
                bool isSameEntityThatWasPressed = AreCollidersFromSameEntity(raycastInfoPointerEventLayer.hitInfo, lastPointerDownEventHitInfo);

                if (!isOnClickComponentBlocked && isSameEntityThatWasPressed)
                {
                    bool isHitInfoValid = raycastInfoPointerEventLayer.hitInfo.hit.collider != null;
                    pointerUpEvent.Report(buttonId, ray, raycastInfoPointerEventLayer.hitInfo.hit, isHitInfoValid);
                }

                pointerUpEvent = null;
            }

            string sceneId = SceneController.i.currentSceneId;

            if (useRaycast && raycastGlobalLayerHitInfo.isValid)
            {
                CollidersManager.i.GetColliderInfo(raycastGlobalLayerHitInfo.hit.collider, out ColliderInfo colliderInfo);

                WebInterface.ReportGlobalPointerUpEvent(
                    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.ReportGlobalPointerUpEvent(buttonId, raycastInfoGlobalLayer.ray, Vector3.zero, Vector3.zero, 0, sceneId);
            }
        }
Esempio n. 4
0
        private void ProcessButtonUp(WebInterface.ACTION_BUTTON buttonId, bool useRaycast, LayerMask pointerEventLayer, int globalLayer)
        {
            IWorldState    worldState = Environment.i.world.state;
            RaycastHitInfo raycastGlobalLayerHitInfo;
            Ray            ray = GetRayFromCamera();

            // Raycast for global pointer events
            RaycastResultInfo raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer, worldState.loadedScenes[worldState.currentSceneId]);

            raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo;

            if (pointerUpEvent != null)
            {
                // Raycast for pointer event components
                RaycastResultInfo raycastInfoPointerEventLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, pointerEventLayer, worldState.loadedScenes[worldState.currentSceneId]);

                bool isOnClickComponentBlocked  = IsBlockingOnClick(raycastInfoPointerEventLayer.hitInfo, raycastGlobalLayerHitInfo);
                bool isSameEntityThatWasPressed = AreCollidersFromSameEntity(raycastInfoPointerEventLayer.hitInfo, lastPointerDownEventHitInfo);

                if (!isOnClickComponentBlocked && isSameEntityThatWasPressed)
                {
                    bool isHitInfoValid = raycastInfoPointerEventLayer.hitInfo.hit.collider != null;
                    pointerUpEvent.Report(buttonId, ray, raycastInfoPointerEventLayer.hitInfo.hit, isHitInfoValid);
                }

                pointerUpEvent = null;
            }

            ReportGlobalPointerUpEvent(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;

                ReportGlobalPointerUpEvent(buttonId, useRaycast, raycastGlobalLayerHitInfo, raycastInfoGlobalLayer, currentPortableExperienceIds[i]);
            }
        }
Esempio n. 5
0
 void IPointerUpHandler.OnPointerUp(PointerEventData eventData)
 {
     OnPointerUp?.Invoke(this);
 }
Esempio n. 6
0
 void IPointerUpHandler.OnPointerUp(PointerEventData eventData)
 {
     IsPointerDowned = false;
     OnPointerUp?.Invoke();
 }
 private void OnMouseUp() => OnPointerUp?.Invoke(this);
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
 public virtual void InvokeUp() => OnPointerUp?.Invoke();
Esempio n. 10
0
        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]);
            }
        }
 public void PointerUp()
 {
     OnPointerUp?.Invoke();
 }