< Summary

Class:DCL.PointerEventsController
Assembly:DCL.Components.Events
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/UUIDEventComponentsPlugin/UUIDComponent/PointerEventsController/PointerEventsController.cs
Covered lines:200
Uncovered lines:56
Coverable lines:256
Total lines:663
Line coverage:78.1% (200 of 256)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PointerEventsController(...)0%330100%
Update()0%28.327087.88%
GetPointerEventList(...)0%4.254075%
GetPointerEvent(...)0%2.152066.67%
GetPointerInputEvents(...)0%3.333066.67%
EventObjectCanBeHovered(...)0%440100%
ResolveGenericRaycastHandlers(...)0%1101000%
UnhoverLastHoveredObject()0%660100%
Dispose()0%330100%
RetrieveCamera()0%220100%
GetRayFromCamera()0%110100%
OnButtonEvent(...)0%15.789056.25%
ProcessButtonUp(...)0%6.56076%
ProcessButtonDown(...)0%16.5615080.95%
ReportGlobalPointerUpEvent(...)0%4.254075%
ReportGlobalPointerDownEvent(...)0%440100%
AreSameEntity(...)0%330100%
IsBlockingOnClick(...)0%440100%
EntityHasPointerEvent(...)0%440100%
AreCollidersFromSameEntity(...)0%5.025090.91%
HandleCursorLockChanges(...)0%6200%
HideOrShowCursor(...)0%110100%
SetHoverCursor()0%110100%
SetNormalCursor()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/UUIDEventComponentsPlugin/UUIDComponent/PointerEventsController/PointerEventsController.cs

#LineLine coverage
 1using System;
 2using DCL.Components;
 3using DCL.Configuration;
 4using DCL.Helpers;
 5using DCL.Interface;
 6using UnityEngine;
 7using UnityEngine.UI;
 8using UnityEngine.EventSystems;
 9using System.Collections.Generic;
 10using System.Linq;
 11using DCL.Models;
 12using DCLPlugins.UUIDEventComponentsPlugin.UUIDComponent.Interfaces;
 13using Ray = UnityEngine.Ray;
 14
 15namespace DCL
 16{
 17    public class PointerEventsController
 18    {
 019        private static bool renderingEnabled => CommonScriptableObjects.rendererState.Get();
 20        public System.Action OnPointerHoverStarts;
 21        public System.Action OnPointerHoverEnds;
 22
 23        RaycastHitInfo lastPointerDownEventHitInfo;
 24        IPointerInputEvent pointerInputUpEvent;
 6025        IRaycastHandler raycastHandler = new RaycastHandler();
 26
 27        Camera charCamera;
 28
 29        GameObject lastHoveredObject = null;
 30        GameObject newHoveredGO = null;
 31
 32        IPointerEvent newHoveredInputEvent = null;
 33        IList<IPointerEvent> lastHoveredEventList = null;
 34
 35        RaycastHit hitInfo;
 6036        PointerEventData uiGraphicRaycastPointerEventData = new PointerEventData(null);
 6037        List<RaycastResult> uiGraphicRaycastResults = new List<RaycastResult>();
 38        GraphicRaycaster uiGraphicRaycaster;
 39
 40        private IRaycastPointerClickHandler clickHandler;
 41        private InputController_Legacy inputControllerLegacy;
 42        private InteractionHoverCanvasController hoverCanvas;
 43
 6044        public PointerEventsController(InputController_Legacy inputControllerLegacy,
 45            InteractionHoverCanvasController hoverCanvas)
 46        {
 6047            this.inputControllerLegacy = inputControllerLegacy;
 6048            this.hoverCanvas = hoverCanvas;
 49
 180050            for (int i = 0; i < Enum.GetValues(typeof(WebInterface.ACTION_BUTTON)).Length; i++)
 51            {
 84052                var buttonId = (WebInterface.ACTION_BUTTON) i;
 53
 84054                if (buttonId == WebInterface.ACTION_BUTTON.ANY)
 55                    continue;
 56
 78057                inputControllerLegacy.AddListener(buttonId, OnButtonEvent);
 58            }
 59
 6060            OnPointerHoverStarts += SetHoverCursor;
 6061            OnPointerHoverEnds += SetNormalCursor;
 62
 6063            RetrieveCamera();
 64
 6065            Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.Update, Update);
 6066            Utils.OnCursorLockChanged += HandleCursorLockChanges;
 67
 6068            HideOrShowCursor(Utils.IsCursorLocked);
 6069        }
 70
 71        public void Update()
 72        {
 1801873            if (charCamera == null)
 574                RetrieveCamera();
 75
 1801876            if (!CommonScriptableObjects.rendererState.Get() || charCamera == null)
 077                return;
 78
 1801879            if (!Utils.IsCursorLocked)
 86580                return;
 81
 1715382            IWorldState worldState = Environment.i.world.state;
 83
 84            // We use Physics.Raycast() instead of our raycastHandler.Raycast() as that one is slower, sometimes 2x, bec
 1715385            bool didHit = Physics.Raycast(GetRayFromCamera(), out hitInfo, Mathf.Infinity,
 86                PhysicsLayers.physicsCastLayerMaskWithoutCharacter);
 87
 1715388            bool uiIsBlocking = false;
 1715389            string currentSceneId = worldState.GetCurrentSceneId();
 90
 1715391            bool validCurrentSceneId = !string.IsNullOrEmpty(currentSceneId);
 1715392            bool validCurrentScene = validCurrentSceneId && worldState.ContainsScene(currentSceneId);
 93
 94            // NOTE: in case of a single scene loaded (preview or builder) sceneId is set to null when stepping outside
 1715395            if (didHit && validCurrentSceneId && validCurrentScene)
 96            {
 1667997                DataStore_World worldData = DataStore.i.Get<DataStore_World>();
 1667998                GraphicRaycaster raycaster = worldData.currentRaycaster.Get();
 99
 16679100                if (raycaster)
 101                {
 6102                    uiGraphicRaycastPointerEventData.position = new Vector2(Screen.width / 2, Screen.height / 2);
 6103                    uiGraphicRaycastResults.Clear();
 6104                    raycaster.Raycast(uiGraphicRaycastPointerEventData, uiGraphicRaycastResults);
 6105                    uiIsBlocking = uiGraphicRaycastResults.Count > 0;
 106                }
 107            }
 108
 17153109            if (!didHit || uiIsBlocking)
 110            {
 476111                clickHandler = null;
 476112                UnhoverLastHoveredObject();
 113
 476114                return;
 115            }
 116
 16677117            var raycastHandlerTarget = hitInfo.collider.GetComponent<IRaycastPointerHandler>();
 118
 16677119            if (raycastHandlerTarget != null)
 120            {
 0121                ResolveGenericRaycastHandlers(raycastHandlerTarget);
 0122                UnhoverLastHoveredObject();
 123
 0124                return;
 125            }
 126
 16677127            if (CollidersManager.i.GetColliderInfo(hitInfo.collider, out ColliderInfo info))
 16677128                newHoveredInputEvent = GetPointerEvent(info.entity);
 129            else
 0130                newHoveredInputEvent = hitInfo.collider.GetComponentInChildren<IPointerEvent>();
 131
 16677132            clickHandler = null;
 133
 16677134            if (!EventObjectCanBeHovered(info, hitInfo.distance))
 135            {
 17136                UnhoverLastHoveredObject();
 137
 17138                return;
 139            }
 140
 16660141            newHoveredGO = newHoveredInputEvent.GetTransform().gameObject;
 142
 16660143            if (newHoveredGO != lastHoveredObject)
 144            {
 18145                UnhoverLastHoveredObject();
 146
 18147                lastHoveredObject = newHoveredGO;
 148
 18149                lastHoveredEventList = GetPointerEventList(newHoveredInputEvent.entity);
 150
 151                // NOTE: this case is for the Avatar, since it hierarchy differs from other ECS components
 18152                if (lastHoveredEventList?.Count == 0)
 153                {
 0154                    lastHoveredEventList = newHoveredGO.GetComponents<IPointerEvent>();
 155                }
 156
 18157                OnPointerHoverStarts?.Invoke();
 158            }
 159
 160            // OnPointerDown/OnClick and OnPointerUp should display their hover feedback at different moments
 16660161            if (lastHoveredEventList != null && lastHoveredEventList.Count > 0)
 162            {
 16660163                bool isEntityShowingHoverFeedback = false;
 164
 66642165                for (int i = 0; i < lastHoveredEventList.Count; i++)
 166                {
 16661167                    if (lastHoveredEventList[i] is IPointerInputEvent e)
 168                    {
 16653169                        bool eventButtonIsPressed = inputControllerLegacy.IsPressed(e.GetActionButton());
 170
 16653171                        bool isClick = e.GetEventType() == PointerInputEventType.CLICK;
 16653172                        bool isDown = e.GetEventType() == PointerInputEventType.DOWN;
 16653173                        bool isUp = e.GetEventType() == PointerInputEventType.UP;
 174
 16653175                        if (isUp && eventButtonIsPressed)
 176                        {
 0177                            e.SetHoverState(true);
 0178                            isEntityShowingHoverFeedback = isEntityShowingHoverFeedback || e.ShouldShowHoverFeedback();
 179                        }
 16653180                        else if ((isDown || isClick) && !eventButtonIsPressed)
 181                        {
 16651182                            e.SetHoverState(true);
 16651183                            isEntityShowingHoverFeedback = isEntityShowingHoverFeedback || e.ShouldShowHoverFeedback();
 184                        }
 2185                        else if (!isEntityShowingHoverFeedback)
 186                        {
 2187                            e.SetHoverState(false);
 188                        }
 189                    }
 190                    else
 191                    {
 8192                        lastHoveredEventList[i].SetHoverState(true);
 193                    }
 194                }
 195            }
 196
 16660197            newHoveredGO = null;
 16660198            newHoveredInputEvent = null;
 16660199        }
 200
 201        private IList<IPointerEvent> GetPointerEventList(IDCLEntity entity)
 202        {
 203            // If an event exist in the new ECS, we got that value, if not it is ECS 6, so we continue as before
 18204            if (DataStore.i.ecs7.entityEvents.TryGetValue(entity.entityId, out List<IPointerInputEvent> pointerInputEven
 205            {
 0206                return pointerInputEvent.Cast<IPointerEvent>().ToList();
 207            }
 208            else
 209            {
 18210                var lastHoveredEventList = newHoveredInputEvent.entity.gameObject.transform.Cast<Transform>()
 37211                                                               .Select(child => child.GetComponent<IPointerEvent>())
 37212                                                               .Where(pointerComponent => pointerComponent != null)
 213                                                               .ToArray();
 214
 18215                return lastHoveredEventList;
 216            }
 217        }
 218
 219        private IPointerEvent GetPointerEvent(IDCLEntity entity)
 220        {
 221            // If an event exist in the new ECS, we got that value, if not it is ECS 6, so we continue as before
 16677222            if (DataStore.i.ecs7.entityEvents.TryGetValue(entity.entityId, out List<IPointerInputEvent> pointerInputEven
 0223                return pointerInputEvent.First();
 224            else
 16677225                return entity.gameObject.GetComponentInChildren<IPointerEvent>();
 226        }
 227
 228        private IList<IPointerInputEvent> GetPointerInputEvents(IDCLEntity entity, GameObject hitGameObject)
 229        {
 230            // If an event exist in the new ECS, we got that value, if not it is ECS 6, so we continue as before
 10231            if (entity != null && DataStore.i.ecs7.entityEvents.TryGetValue(entity.entityId, out List<IPointerInputEvent
 0232                return pointerInputEvent;
 233            else
 10234                return hitGameObject.GetComponentsInChildren<IPointerInputEvent>();
 235        }
 236
 237        private bool EventObjectCanBeHovered(ColliderInfo colliderInfo, float distance)
 238        {
 16677239            return newHoveredInputEvent != null &&
 240                   newHoveredInputEvent.IsAtHoverDistance(distance) &&
 241                   newHoveredInputEvent.IsVisible() &&
 242                   AreSameEntity(newHoveredInputEvent, colliderInfo);
 243        }
 244
 245        private void ResolveGenericRaycastHandlers(IRaycastPointerHandler raycastHandlerTarget)
 246        {
 0247            if (Utils.LockedThisFrame())
 0248                return;
 249
 0250            var mouseIsDown = Input.GetMouseButtonDown(0);
 0251            var mouseIsUp = Input.GetMouseButtonUp(0);
 252
 0253            if (raycastHandlerTarget is IRaycastPointerDownHandler down)
 254            {
 0255                if (mouseIsDown)
 0256                    down.OnPointerDown();
 257            }
 258
 0259            if (raycastHandlerTarget is IRaycastPointerUpHandler up)
 260            {
 0261                if (mouseIsUp)
 0262                    up.OnPointerUp();
 263            }
 264
 0265            if (raycastHandlerTarget is IRaycastPointerClickHandler click)
 266            {
 0267                if (mouseIsDown)
 0268                    clickHandler = click;
 269
 0270                if (mouseIsUp)
 271                {
 0272                    if (clickHandler == click)
 0273                        click.OnPointerClick();
 274
 0275                    clickHandler = null;
 276                }
 277            }
 0278        }
 279
 280        void UnhoverLastHoveredObject()
 281        {
 511282            if (lastHoveredObject == null)
 283            {
 506284                if (hoverCanvas != null)
 506285                    hoverCanvas.SetHoverState(false);
 286
 506287                return;
 288            }
 289
 5290            OnPointerHoverEnds?.Invoke();
 291
 22292            for (int i = 0; i < lastHoveredEventList.Count; i++)
 293            {
 6294                if (lastHoveredEventList[i] == null)
 295                    continue;
 296
 6297                lastHoveredEventList[i].SetHoverState(false);
 298            }
 299
 5300            lastHoveredEventList = null;
 5301            lastHoveredObject = null;
 5302        }
 303
 304        public void Dispose()
 305        {
 1800306            for (int i = 0; i < Enum.GetValues(typeof(WebInterface.ACTION_BUTTON)).Length; i++)
 307            {
 840308                var buttonId = (WebInterface.ACTION_BUTTON) i;
 309
 840310                if (buttonId == WebInterface.ACTION_BUTTON.ANY)
 311                    continue;
 312
 780313                inputControllerLegacy.RemoveListener(buttonId, OnButtonEvent);
 314            }
 315
 60316            lastHoveredObject = null;
 60317            newHoveredGO = null;
 60318            newHoveredInputEvent = null;
 60319            lastHoveredEventList = null;
 320
 60321            OnPointerHoverStarts -= SetHoverCursor;
 60322            OnPointerHoverEnds -= SetNormalCursor;
 323
 60324            Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.Update, Update);
 60325            Utils.OnCursorLockChanged -= HandleCursorLockChanges;
 60326        }
 327
 328        void RetrieveCamera()
 329        {
 65330            if (charCamera == null)
 331            {
 65332                charCamera = Camera.main;
 333            }
 65334        }
 335
 17167336        public Ray GetRayFromCamera() { return charCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height /
 337
 338        void OnButtonEvent(WebInterface.ACTION_BUTTON buttonId, InputController_Legacy.EVENT evt, bool useRaycast,
 339            bool enablePointerEvent)
 340        {
 341            //TODO(Brian): We should remove this when we get a proper initialization layer
 14342            if (!EnvironmentSettings.RUNNING_TESTS)
 343            {
 0344                if (Utils.LockedThisFrame())
 0345                    return;
 346
 0347                if (!Utils.IsCursorLocked || !renderingEnabled)
 0348                    return;
 349            }
 350
 14351            if (charCamera == null)
 352            {
 0353                RetrieveCamera();
 354
 0355                if (charCamera == null)
 0356                    return;
 357            }
 358
 14359            var pointerEventLayer =
 360                PhysicsLayers.physicsCastLayerMaskWithoutCharacter; //Ensure characterController is being filtered
 361
 14362            var globalLayer = pointerEventLayer & ~PhysicsLayers.physicsCastLayerMask;
 363
 14364            if (evt == InputController_Legacy.EVENT.BUTTON_DOWN)
 365            {
 11366                ProcessButtonDown(buttonId, useRaycast, enablePointerEvent, pointerEventLayer, globalLayer);
 367            }
 3368            else if (evt == InputController_Legacy.EVENT.BUTTON_UP)
 369            {
 3370                ProcessButtonUp(buttonId, useRaycast, enablePointerEvent, pointerEventLayer, globalLayer);
 371            }
 3372        }
 373
 374        private void ProcessButtonUp(WebInterface.ACTION_BUTTON buttonId, bool useRaycast, bool enablePointerEvent,
 375            LayerMask pointerEventLayer, int globalLayer)
 376        {
 3377            IWorldState worldState = Environment.i.world.state;
 378
 3379            string currentSceneId = worldState.GetCurrentSceneId();
 3380            if (string.IsNullOrEmpty(currentSceneId))
 0381                return;
 382
 383            RaycastHitInfo raycastGlobalLayerHitInfo;
 3384            Ray ray = GetRayFromCamera();
 385
 386            // Raycast for global pointer events
 3387            worldState.TryGetScene(currentSceneId, out var loadedScene);
 388
 3389            RaycastResultInfo raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer,
 390                loadedScene);
 391
 3392            raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo;
 393
 3394            if (pointerInputUpEvent != null)
 395            {
 396                // Raycast for pointer event components
 3397                RaycastResultInfo raycastInfoPointerEventLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane,
 398                    pointerEventLayer, loadedScene);
 399
 3400                bool isOnClickComponentBlocked =
 401                    IsBlockingOnClick(raycastInfoPointerEventLayer.hitInfo, raycastGlobalLayerHitInfo);
 402
 3403                bool isSameEntityThatWasPressed = AreCollidersFromSameEntity(raycastInfoPointerEventLayer.hitInfo,
 404                    lastPointerDownEventHitInfo);
 405
 3406                if (!isOnClickComponentBlocked && isSameEntityThatWasPressed && enablePointerEvent)
 407                {
 3408                    pointerInputUpEvent.Report(buttonId, ray, raycastInfoPointerEventLayer.hitInfo.hit);
 409                }
 410
 3411                pointerInputUpEvent = null;
 412            }
 413
 3414            ReportGlobalPointerUpEvent(buttonId, useRaycast, raycastGlobalLayerHitInfo, raycastInfoGlobalLayer,
 415                currentSceneId);
 416
 417            // Raycast for global pointer events (for each PE scene)
 3418            List<string> currentPortableExperienceIds = DataStore.i.Get<DataStore_World>().portableExperienceIds.Get().T
 419
 6420            for (int i = 0; i < currentPortableExperienceIds.Count; i++)
 421            {
 0422                if (worldState.TryGetScene(currentPortableExperienceIds[i], out var portableScene))
 423                {
 0424                    raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer,
 425                        portableScene);
 426
 0427                    raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo;
 428
 0429                    ReportGlobalPointerUpEvent(buttonId, useRaycast, raycastGlobalLayerHitInfo, raycastInfoGlobalLayer,
 430                        currentPortableExperienceIds[i]);
 431                }
 432            }
 3433        }
 434
 435        private void ProcessButtonDown(WebInterface.ACTION_BUTTON buttonId, bool useRaycast, bool enablePointerEvent,
 436            LayerMask pointerEventLayer, int globalLayer)
 437        {
 11438            IWorldState worldState = Environment.i.world.state;
 439
 11440            string currentSceneId = worldState.GetCurrentSceneId();
 11441            if (string.IsNullOrEmpty(currentSceneId))
 0442                return;
 443
 444            RaycastHitInfo raycastGlobalLayerHitInfo;
 11445            Ray ray = GetRayFromCamera();
 11446            worldState.TryGetScene(currentSceneId, out var loadedScene);
 447
 448            // Raycast for pointer event components
 11449            RaycastResultInfo raycastInfoPointerEventLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, pointe
 450
 451            // Raycast for global pointer events
 11452            RaycastResultInfo raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer,
 453
 11454            raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo;
 455
 11456            bool isOnClickComponentBlocked =
 457                IsBlockingOnClick(raycastInfoPointerEventLayer.hitInfo, raycastGlobalLayerHitInfo);
 458
 11459            if (!isOnClickComponentBlocked && raycastInfoPointerEventLayer.hitInfo.hit.collider)
 460            {
 10461                Collider collider = raycastInfoPointerEventLayer.hitInfo.hit.collider;
 462
 463                GameObject hitGameObject;
 464
 10465                if (CollidersManager.i.GetColliderInfo(collider, out ColliderInfo info))
 10466                    hitGameObject = info.entity.gameObject;
 467                else
 0468                    hitGameObject = collider.gameObject;
 469
 10470                IList<IPointerInputEvent> events = GetPointerInputEvents(info.entity, hitGameObject);
 471
 36472                for (var i = 0; i < events.Count; i++)
 473                {
 8474                    IPointerInputEvent e = events[i];
 8475                    bool areSameEntity = AreSameEntity(e, info);
 476
 8477                    switch (e.GetEventType())
 478                    {
 479                        case PointerInputEventType.CLICK:
 1480                            if (areSameEntity && enablePointerEvent)
 1481                                e.Report(buttonId, ray, raycastInfoPointerEventLayer.hitInfo.hit);
 482
 1483                            break;
 484                        case PointerInputEventType.DOWN:
 4485                            if (areSameEntity && enablePointerEvent)
 4486                                e.Report(buttonId, ray, raycastInfoPointerEventLayer.hitInfo.hit);
 487
 4488                            break;
 489                        case PointerInputEventType.UP:
 3490                            if (areSameEntity && enablePointerEvent)
 3491                                pointerInputUpEvent = e;
 492                            else
 0493                                pointerInputUpEvent = null;
 494
 495                            break;
 496                    }
 497                }
 498
 10499                lastPointerDownEventHitInfo = raycastInfoPointerEventLayer.hitInfo;
 500            }
 501
 11502            ReportGlobalPointerDownEvent(buttonId, useRaycast, raycastGlobalLayerHitInfo, raycastInfoGlobalLayer, curren
 503
 504            // Raycast for global pointer events (for each PE scene)
 11505            IEnumerable<string> currentPortableExperienceIds = DataStore.i.world.portableExperienceIds.Get();
 506
 22507            foreach (var pexId in currentPortableExperienceIds)
 508            {
 0509                if (worldState.TryGetScene(pexId, out var portableScene))
 510                {
 0511                    raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer, portableS
 512
 0513                    raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo;
 514
 0515                    ReportGlobalPointerDownEvent(buttonId, useRaycast, raycastGlobalLayerHitInfo, raycastInfoGlobalLayer
 516                        pexId);
 517                }
 518
 519            }
 11520        }
 521
 522        private void ReportGlobalPointerUpEvent(
 523            WebInterface.ACTION_BUTTON buttonId,
 524            bool useRaycast,
 525            RaycastHitInfo raycastGlobalLayerHitInfo,
 526            RaycastResultInfo raycastInfoGlobalLayer,
 527            string sceneId)
 528        {
 3529            if (useRaycast && raycastGlobalLayerHitInfo.isValid)
 530            {
 3531                CollidersManager.i.GetColliderInfo(raycastGlobalLayerHitInfo.hit.collider,
 532                    out ColliderInfo colliderInfo);
 533
 3534                string entityId = SpecialEntityIdLegacyLiteral.SCENE_ROOT_ENTITY;
 535
 3536                if (colliderInfo.entity != null)
 3537                    entityId =
 538                        Environment.i.world.sceneController.entityIdHelper.GetOriginalId(colliderInfo.entity.entityId);
 539
 3540                WebInterface.ReportGlobalPointerUpEvent(
 541                    buttonId,
 542                    raycastInfoGlobalLayer.ray,
 543                    raycastGlobalLayerHitInfo.hit.point,
 544                    raycastGlobalLayerHitInfo.hit.normal,
 545                    raycastGlobalLayerHitInfo.hit.distance,
 546                    sceneId,
 547                    entityId,
 548                    colliderInfo.meshName,
 549                    isHitInfoValid: true);
 550            }
 551            else
 552            {
 0553                WebInterface.ReportGlobalPointerUpEvent(buttonId, raycastInfoGlobalLayer.ray, Vector3.zero,
 554                    Vector3.zero, 0, sceneId);
 555            }
 0556        }
 557
 558        private void ReportGlobalPointerDownEvent(
 559            WebInterface.ACTION_BUTTON buttonId,
 560            bool useRaycast,
 561            RaycastHitInfo raycastGlobalLayerHitInfo,
 562            RaycastResultInfo raycastInfoGlobalLayer,
 563            string sceneId)
 564        {
 11565            if (useRaycast && raycastGlobalLayerHitInfo.isValid)
 566            {
 10567                CollidersManager.i.GetColliderInfo(raycastGlobalLayerHitInfo.hit.collider,
 568                    out ColliderInfo colliderInfo);
 569
 10570                string entityId = SpecialEntityIdLegacyLiteral.SCENE_ROOT_ENTITY;
 571
 10572                if (colliderInfo.entity != null)
 10573                    entityId =
 574                        Environment.i.world.sceneController.entityIdHelper.GetOriginalId(colliderInfo.entity.entityId);
 575
 10576                WebInterface.ReportGlobalPointerDownEvent(
 577                    buttonId,
 578                    raycastInfoGlobalLayer.ray,
 579                    raycastGlobalLayerHitInfo.hit.point,
 580                    raycastGlobalLayerHitInfo.hit.normal,
 581                    raycastGlobalLayerHitInfo.hit.distance,
 582                    sceneId,
 583                    entityId,
 584                    colliderInfo.meshName,
 585                    isHitInfoValid: true);
 586            }
 587            else
 588            {
 1589                WebInterface.ReportGlobalPointerDownEvent(buttonId, raycastInfoGlobalLayer.ray, Vector3.zero,
 590                    Vector3.zero, 0, sceneId);
 591            }
 1592        }
 593
 594        bool AreSameEntity(IPointerEvent pointerInputEvent, ColliderInfo colliderInfo)
 595        {
 16669596            return pointerInputEvent != null && colliderInfo.entity != null &&
 597                   pointerInputEvent.entity == colliderInfo.entity;
 598        }
 599
 600        bool IsBlockingOnClick(RaycastHitInfo targetOnClickHit, RaycastHitInfo potentialBlockerHit)
 601        {
 14602            return
 603                potentialBlockerHit.hit.collider != null // Does a potential blocker hit exist?
 604                && targetOnClickHit.hit.collider != null // Was a target entity with a pointer event component hit?
 605                && potentialBlockerHit.hit.distance <=
 606                targetOnClickHit.hit.distance // Is potential blocker nearer than target entity?
 607                && !AreCollidersFromSameEntity(potentialBlockerHit,
 608                    targetOnClickHit); // Does potential blocker belong to other entity rather than target entity?
 609        }
 610
 611        bool EntityHasPointerEvent(IDCLEntity entity)
 612        {
 32613            var componentsManager = entity.scene.componentsManagerLegacy;
 614
 32615            return componentsManager.HasComponent(entity, Models.CLASS_ID_COMPONENT.UUID_CALLBACK) ||
 616                   componentsManager.HasComponent(entity, Models.CLASS_ID_COMPONENT.UUID_ON_UP) ||
 617                   componentsManager.HasComponent(entity, Models.CLASS_ID_COMPONENT.UUID_ON_DOWN) ||
 618                   componentsManager.HasComponent(entity, Models.CLASS_ID_COMPONENT.UUID_ON_CLICK);
 619        }
 620
 621        bool AreCollidersFromSameEntity(RaycastHitInfo hitInfoA, RaycastHitInfo hitInfoB)
 622        {
 16623            CollidersManager.i.GetColliderInfo(hitInfoA.hit.collider, out ColliderInfo colliderInfoA);
 16624            CollidersManager.i.GetColliderInfo(hitInfoB.hit.collider, out ColliderInfo colliderInfoB);
 625
 16626            var entityA = colliderInfoA.entity;
 16627            var entityB = colliderInfoB.entity;
 628
 16629            bool entityAHasEvent = entityA != null && EntityHasPointerEvent(entityA);
 16630            bool entityBHasEvent = entityB != null && EntityHasPointerEvent(entityB);
 631
 632            // If both entities has OnClick/PointerEvent component
 16633            if (entityAHasEvent && entityBHasEvent)
 634            {
 14635                return entityA == entityB;
 636            }
 637            // If only one of them has OnClick/PointerEvent component
 2638            else if (entityAHasEvent ^ entityBHasEvent)
 639            {
 0640                return false;
 641            }
 642            // None of them has OnClick/PointerEvent component
 643            else
 644            {
 2645                return colliderInfoA.entity == colliderInfoB.entity;
 646            }
 647        }
 648
 649        private void HandleCursorLockChanges(bool isLocked)
 650        {
 0651            HideOrShowCursor(isLocked);
 652
 0653            if (!isLocked)
 0654                UnhoverLastHoveredObject();
 0655        }
 656
 120657        private void HideOrShowCursor(bool isCursorLocked) { DataStore.i.Get<DataStore_Cursor>().cursorVisible.Set(isCur
 658
 36659        private void SetHoverCursor() { DataStore.i.Get<DataStore_Cursor>().cursorType.Set(DataStore_Cursor.CursorType.H
 660
 10661        private void SetNormalCursor() { DataStore.i.Get<DataStore_Cursor>().cursorType.Set(DataStore_Cursor.CursorType.
 662    }
 663}

Methods/Properties

renderingEnabled()
PointerEventsController(DCL.InputController_Legacy, InteractionHoverCanvasController)
Update()
GetPointerEventList(DCL.Models.IDCLEntity)
GetPointerEvent(DCL.Models.IDCLEntity)
GetPointerInputEvents(DCL.Models.IDCLEntity, UnityEngine.GameObject)
EventObjectCanBeHovered(DCL.Components.ColliderInfo, System.Single)
ResolveGenericRaycastHandlers(IRaycastPointerHandler)
UnhoverLastHoveredObject()
Dispose()
RetrieveCamera()
GetRayFromCamera()
OnButtonEvent(DCL.Interface.WebInterface/ACTION_BUTTON, DCL.InputController_Legacy/EVENT, System.Boolean, System.Boolean)
ProcessButtonUp(DCL.Interface.WebInterface/ACTION_BUTTON, System.Boolean, System.Boolean, UnityEngine.LayerMask, System.Int32)
ProcessButtonDown(DCL.Interface.WebInterface/ACTION_BUTTON, System.Boolean, System.Boolean, UnityEngine.LayerMask, System.Int32)
ReportGlobalPointerUpEvent(DCL.Interface.WebInterface/ACTION_BUTTON, System.Boolean, DCL.Helpers.RaycastHitInfo, DCL.Helpers.RaycastResultInfo, System.String)
ReportGlobalPointerDownEvent(DCL.Interface.WebInterface/ACTION_BUTTON, System.Boolean, DCL.Helpers.RaycastHitInfo, DCL.Helpers.RaycastResultInfo, System.String)
AreSameEntity(DCLPlugins.UUIDEventComponentsPlugin.UUIDComponent.Interfaces.IPointerEvent, DCL.Components.ColliderInfo)
IsBlockingOnClick(DCL.Helpers.RaycastHitInfo, DCL.Helpers.RaycastHitInfo)
EntityHasPointerEvent(DCL.Models.IDCLEntity)
AreCollidersFromSameEntity(DCL.Helpers.RaycastHitInfo, DCL.Helpers.RaycastHitInfo)
HandleCursorLockChanges(System.Boolean)
HideOrShowCursor(System.Boolean)
SetHoverCursor()
SetNormalCursor()