| | 1 | | using System; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Configuration; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Interface; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.UI; |
| | 8 | | using UnityEngine.EventSystems; |
| | 9 | | using System.Collections.Generic; |
| | 10 | | using System.Linq; |
| | 11 | | using DCL.Controllers; |
| | 12 | | using DCL.Models; |
| | 13 | | using DCLPlugins.UUIDEventComponentsPlugin.UUIDComponent.Interfaces; |
| | 14 | | using MainScripts.DCL.Helpers.UIHelpers; |
| | 15 | | using static DCL.Interface.WebInterface.OnGlobalPointerEventPayload; |
| | 16 | | using Ray = UnityEngine.Ray; |
| | 17 | |
|
| | 18 | | namespace DCL |
| | 19 | | { |
| | 20 | | public class PointerEventsController |
| | 21 | | { |
| 0 | 22 | | private static bool renderingEnabled => CommonScriptableObjects.rendererState.Get(); |
| | 23 | |
|
| | 24 | | private readonly PointerHoverController pointerHoverController; |
| | 25 | |
|
| 85 | 26 | | private readonly IRaycastHandler raycastHandler = new RaycastHandler(); |
| 85 | 27 | | private readonly PointerEventData uiGraphicRaycastPointerEventData = new (null); |
| 85 | 28 | | private readonly List<RaycastResult> uiGraphicRaycastResults = new (); |
| | 29 | |
|
| | 30 | | private readonly InputController_Legacy inputControllerLegacy; |
| | 31 | | private readonly MouseCatcher mouseCatcher; |
| | 32 | | private readonly BaseVariable<GraphicRaycaster> worldDataRaycaster; |
| | 33 | |
|
| 85 | 34 | | private DataStore_ECS7 dataStoreEcs7 = DataStore.i.ecs7; |
| | 35 | |
|
| | 36 | | private IPointerInputEvent pointerInputUpEvent; |
| | 37 | | private Camera charCamera; |
| | 38 | |
|
| | 39 | | private RaycastHitInfo lastPointerDownEventHitInfo; |
| | 40 | | private GraphicRaycaster uiGraphicRaycaster; |
| | 41 | | private RaycastHit hitInfo; |
| | 42 | |
|
| | 43 | | private IRaycastPointerClickHandler clickHandler; |
| | 44 | |
|
| | 45 | | private StandaloneInputModuleDCL eventSystemInputModule; |
| | 46 | |
|
| 1091 | 47 | | private StandaloneInputModuleDCL eventSystemInputModuleLazy => eventSystemInputModule ??= (StandaloneInputModule |
| | 48 | |
|
| 85 | 49 | | public PointerEventsController(InputController_Legacy inputControllerLegacy, InteractionHoverCanvasController ho |
| | 50 | | { |
| 85 | 51 | | this.worldDataRaycaster = worldDataRaycaster; |
| 85 | 52 | | this.inputControllerLegacy = inputControllerLegacy; |
| 85 | 53 | | this.mouseCatcher = mouseCatcher; |
| 85 | 54 | | pointerHoverController = new PointerHoverController(inputControllerLegacy, hoverCanvas); |
| | 55 | |
|
| 85 | 56 | | pointerHoverController.OnPointerHoverStarts += SetHoverCursor; |
| 85 | 57 | | pointerHoverController.OnPointerHoverEnds += SetNormalCursor; |
| | 58 | |
|
| 2380 | 59 | | foreach (var actionButton in WebInterface.ConcreteActionButtons) |
| 1105 | 60 | | inputControllerLegacy.AddListener(actionButton, OnButtonEvent); |
| | 61 | |
|
| 85 | 62 | | RetrieveCamera(); |
| | 63 | |
|
| 85 | 64 | | Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.Update, Update); |
| 85 | 65 | | Utils.OnCursorLockChanged += HandleCursorLockChanges; |
| | 66 | |
|
| 85 | 67 | | HideOrShowCursor(Utils.IsCursorLocked); |
| 85 | 68 | | } |
| | 69 | |
|
| | 70 | | public void Dispose() |
| | 71 | | { |
| 2380 | 72 | | foreach (var actionButton in WebInterface.ConcreteActionButtons) |
| 1105 | 73 | | inputControllerLegacy.RemoveListener(actionButton, OnButtonEvent); |
| | 74 | |
|
| 85 | 75 | | pointerHoverController.OnPointerHoverStarts -= SetHoverCursor; |
| 85 | 76 | | pointerHoverController.OnPointerHoverEnds -= SetNormalCursor; |
| | 77 | |
|
| 85 | 78 | | Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.Update, Update); |
| 85 | 79 | | Utils.OnCursorLockChanged -= HandleCursorLockChanges; |
| 85 | 80 | | } |
| | 81 | |
|
| | 82 | | private void Update() |
| | 83 | | { |
| 7849 | 84 | | if (charCamera == null) |
| 5 | 85 | | RetrieveCamera(); |
| | 86 | |
|
| 7849 | 87 | | if (!CommonScriptableObjects.rendererState.Get() || charCamera == null) |
| 0 | 88 | | return; |
| | 89 | |
|
| 7849 | 90 | | if (NeedToUnhoverWhileCursorUnlocked()) |
| | 91 | | { |
| | 92 | | // New interaction model |
| 1091 | 93 | | UnhoverLastHoveredObject(); |
| 1091 | 94 | | return; |
| | 95 | | } |
| | 96 | |
|
| | 97 | | // We use Physics.Raycast() instead of our raycastHandler.Raycast() as that one is slower, sometimes 2x, bec |
| 6758 | 98 | | Ray ray = Utils.IsCursorLocked ? GetRayFromCamera() : GetRayFromMouse(); |
| | 99 | |
|
| 6758 | 100 | | bool didHit = Physics.Raycast(ray, out hitInfo, Mathf.Infinity, PhysicsLayers.physicsCastLayerMaskWithoutCha |
| | 101 | |
|
| 6758 | 102 | | if (dataStoreEcs7.isEcs7Enabled) |
| 0 | 103 | | dataStoreEcs7.lastPointerRayHit.UpdateByHitInfo(hitInfo, didHit, ray); |
| | 104 | |
|
| 6758 | 105 | | var uiIsBlocking = false; |
| | 106 | |
|
| | 107 | | // NOTE: in case of a single scene loaded (preview or builder) sceneId is set to null when stepping outside |
| 6758 | 108 | | if (didHit && IsValidCurrentScene()) |
| | 109 | | { |
| 6523 | 110 | | GraphicRaycaster raycaster = worldDataRaycaster.Get(); |
| | 111 | |
|
| 6523 | 112 | | if (raycaster != null) |
| | 113 | | { |
| 6 | 114 | | uiGraphicRaycastPointerEventData.position = Utils.IsCursorLocked ? new Vector2(Screen.width / 2, Scr |
| 6 | 115 | | uiGraphicRaycastResults.Clear(); |
| 6 | 116 | | raycaster.Raycast(uiGraphicRaycastPointerEventData, uiGraphicRaycastResults); |
| 6 | 117 | | uiIsBlocking = uiGraphicRaycastResults.Count > 0; |
| | 118 | | } |
| | 119 | | } |
| | 120 | |
|
| 6758 | 121 | | if (!didHit || uiIsBlocking) |
| | 122 | | { |
| 237 | 123 | | clickHandler = null; |
| 237 | 124 | | UnhoverLastHoveredObject(); |
| | 125 | |
|
| 237 | 126 | | return; |
| | 127 | | } |
| | 128 | |
|
| 6521 | 129 | | var raycastHandlerTarget = hitInfo.collider.GetComponent<IRaycastPointerHandler>(); |
| | 130 | |
|
| 6521 | 131 | | if (raycastHandlerTarget != null) |
| | 132 | | { |
| 0 | 133 | | ResolveGenericRaycastHandlers(raycastHandlerTarget); |
| 0 | 134 | | UnhoverLastHoveredObject(); |
| | 135 | |
|
| 0 | 136 | | return; |
| | 137 | | } |
| | 138 | |
|
| 6521 | 139 | | var target = CollidersManager.i.GetColliderInfo(hitInfo.collider, out var colliderInfo) |
| | 140 | | ? colliderInfo.entity.gameObject |
| | 141 | | : hitInfo.collider.gameObject; |
| | 142 | |
|
| 6521 | 143 | | clickHandler = null; |
| | 144 | |
|
| 6521 | 145 | | Type typeToUse = Utils.IsCursorLocked ? typeof(IPointerEvent) : typeof(IUnlockedCursorInputEvent); |
| 6521 | 146 | | pointerHoverController.OnRaycastHit(hitInfo, colliderInfo, target, typeToUse); |
| 6521 | 147 | | } |
| | 148 | |
|
| | 149 | | private static bool IsValidCurrentScene() |
| | 150 | | { |
| 6523 | 151 | | IWorldState worldState = Environment.i.world.state; |
| 6523 | 152 | | int currentSceneNumber = worldState.GetCurrentSceneNumber(); |
| 6523 | 153 | | return currentSceneNumber > 0 && worldState.ContainsScene(currentSceneNumber); |
| | 154 | | } |
| | 155 | |
|
| | 156 | | private static IList<IPointerInputEvent> GetPointerInputEvents(GameObject hitGameObject) |
| | 157 | | { |
| 10 | 158 | | if (!Utils.IsCursorLocked || Utils.LockedThisFrame()) |
| 0 | 159 | | return hitGameObject.GetComponentsInChildren<IAvatarOnPointerDown>(); |
| | 160 | |
|
| 10 | 161 | | return hitGameObject.GetComponentsInChildren<IPointerInputEvent>(); |
| | 162 | | } |
| | 163 | |
|
| | 164 | | private void ResolveGenericRaycastHandlers(IRaycastPointerHandler raycastHandlerTarget) |
| | 165 | | { |
| 0 | 166 | | if (Utils.LockedThisFrame()) |
| 0 | 167 | | return; |
| | 168 | |
|
| 0 | 169 | | bool mouseIsDown = Input.GetMouseButtonDown(0); |
| 0 | 170 | | bool mouseIsUp = Input.GetMouseButtonUp(0); |
| | 171 | |
|
| | 172 | | switch (raycastHandlerTarget) |
| | 173 | | { |
| | 174 | | case IRaycastPointerDownHandler down: |
| | 175 | | { |
| 0 | 176 | | if (mouseIsDown) |
| 0 | 177 | | down.OnPointerDown(); |
| | 178 | |
|
| 0 | 179 | | break; |
| | 180 | | } |
| | 181 | | case IRaycastPointerUpHandler up: |
| | 182 | | { |
| 0 | 183 | | if (mouseIsUp) |
| 0 | 184 | | up.OnPointerUp(); |
| | 185 | |
|
| 0 | 186 | | break; |
| | 187 | | } |
| | 188 | | case IRaycastPointerClickHandler click: |
| | 189 | | { |
| 0 | 190 | | if (mouseIsDown) |
| 0 | 191 | | clickHandler = click; |
| | 192 | |
|
| 0 | 193 | | if (mouseIsUp) |
| | 194 | | { |
| 0 | 195 | | if (clickHandler == click) |
| 0 | 196 | | click.OnPointerClick(); |
| | 197 | |
|
| 0 | 198 | | clickHandler = null; |
| | 199 | | } |
| | 200 | |
|
| | 201 | | break; |
| | 202 | | } |
| | 203 | | } |
| 0 | 204 | | } |
| | 205 | |
|
| | 206 | | private void UnhoverLastHoveredObject() => |
| 1328 | 207 | | pointerHoverController.ResetHoveredObject(); |
| | 208 | |
|
| | 209 | | private void RetrieveCamera() |
| | 210 | | { |
| 90 | 211 | | if (charCamera == null) |
| 90 | 212 | | charCamera = Camera.main; |
| 90 | 213 | | } |
| | 214 | |
|
| | 215 | | private Ray GetRayFromCamera() => |
| 6772 | 216 | | charCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)); |
| | 217 | |
|
| | 218 | | private Ray GetRayFromMouse() => |
| 0 | 219 | | charCamera.ScreenPointToRay(Input.mousePosition); |
| | 220 | |
|
| | 221 | | private bool NeedToUnhoverWhileCursorUnlocked() => |
| 7849 | 222 | | (!Utils.IsCursorLocked || Utils.LockedThisFrame()) && |
| | 223 | | (!CanRaycastWhileUnlocked() || !DataStore.i.featureFlags.flags.Get().IsFeatureEnabled("avatar_outliner")); |
| | 224 | |
|
| | 225 | | void OnButtonEvent(WebInterface.ACTION_BUTTON buttonId, InputController_Legacy.EVENT evt, bool useRaycast, bool |
| | 226 | | { |
| | 227 | | // TODO(Brian): We should remove this when we get a proper initialization layer |
| | 228 | |
|
| 14 | 229 | | if (!EnvironmentSettings.RUNNING_TESTS) |
| | 230 | | { |
| 0 | 231 | | if (!renderingEnabled) |
| 0 | 232 | | return; |
| | 233 | |
|
| 0 | 234 | | if (NeedToUnhoverWhileCursorUnlocked()) |
| | 235 | | { |
| | 236 | | // New interaction model |
| 0 | 237 | | UnhoverLastHoveredObject(); |
| 0 | 238 | | return; |
| | 239 | | } |
| | 240 | | } |
| | 241 | |
|
| 14 | 242 | | if (DataStore.i.HUDs.chatInputVisible.Get()) |
| 0 | 243 | | return; |
| | 244 | |
|
| 14 | 245 | | if (charCamera == null) |
| | 246 | | { |
| 0 | 247 | | RetrieveCamera(); |
| | 248 | |
|
| 0 | 249 | | if (charCamera == null) |
| 0 | 250 | | return; |
| | 251 | | } |
| | 252 | |
|
| 14 | 253 | | var pointerEventLayer = PhysicsLayers.physicsCastLayerMaskWithoutCharacter; // Ensure characterController is |
| 14 | 254 | | int globalLayer = pointerEventLayer & ~PhysicsLayers.physicsCastLayerMask; |
| | 255 | |
|
| 25 | 256 | | if (evt == InputController_Legacy.EVENT.BUTTON_DOWN) ProcessButtonDown(buttonId, useRaycast, enablePointerEv |
| 6 | 257 | | else if (evt == InputController_Legacy.EVENT.BUTTON_UP) ProcessButtonUp(buttonId, useRaycast, enablePointerE |
| | 258 | |
|
| 14 | 259 | | if (dataStoreEcs7.isEcs7Enabled && IsValidButtonId(buttonId)) |
| 0 | 260 | | dataStoreEcs7.inputActionState[(int)buttonId] = evt == InputController_Legacy.EVENT.BUTTON_DOWN; |
| 14 | 261 | | } |
| | 262 | |
|
| | 263 | | private bool IsValidButtonId(WebInterface.ACTION_BUTTON buttonId) => |
| 0 | 264 | | buttonId >= 0 && (int)buttonId < dataStoreEcs7.inputActionState.Length; |
| | 265 | |
|
| | 266 | | private void ProcessButtonUp(WebInterface.ACTION_BUTTON buttonId, bool useRaycast, bool enablePointerEvent, |
| | 267 | | LayerMask pointerEventLayer, int globalLayer) |
| | 268 | | { |
| 3 | 269 | | IWorldState worldState = Environment.i.world.state; |
| | 270 | |
|
| 3 | 271 | | int currentSceneNumber = worldState.GetCurrentSceneNumber(); |
| | 272 | |
|
| 3 | 273 | | if (currentSceneNumber <= 0) |
| 0 | 274 | | return; |
| | 275 | |
|
| | 276 | | RaycastHitInfo raycastGlobalLayerHitInfo; |
| 3 | 277 | | Ray ray = !Utils.IsCursorLocked || Utils.LockedThisFrame() ? GetRayFromMouse() : GetRayFromCamera(); |
| | 278 | |
|
| | 279 | | // Raycast for global pointer events |
| 3 | 280 | | worldState.TryGetScene(currentSceneNumber, out var loadedScene); |
| | 281 | |
|
| 3 | 282 | | RaycastResultInfo raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer, |
| | 283 | | loadedScene); |
| | 284 | |
|
| 3 | 285 | | raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo; |
| | 286 | |
|
| 3 | 287 | | RaycastResultInfo raycastInfoPointerEventLayer = null; |
| | 288 | |
|
| 3 | 289 | | if (pointerInputUpEvent != null || dataStoreEcs7.isEcs7Enabled) |
| | 290 | | { |
| | 291 | | // Raycast for pointer event components |
| 3 | 292 | | raycastInfoPointerEventLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, pointerEventLayer, l |
| | 293 | | } |
| | 294 | |
|
| 3 | 295 | | if (pointerInputUpEvent != null && raycastInfoPointerEventLayer != null) |
| | 296 | | { |
| 3 | 297 | | bool isOnClickComponentBlocked = |
| | 298 | | IsBlockingOnClick(raycastInfoPointerEventLayer.hitInfo, raycastGlobalLayerHitInfo); |
| | 299 | |
|
| 3 | 300 | | bool isSameEntityThatWasPressed = AreCollidersFromSameEntity(raycastInfoPointerEventLayer.hitInfo, |
| | 301 | | lastPointerDownEventHitInfo); |
| | 302 | |
|
| 6 | 303 | | if (!isOnClickComponentBlocked && isSameEntityThatWasPressed && enablePointerEvent) { pointerInputUpEven |
| | 304 | |
|
| 3 | 305 | | pointerInputUpEvent = null; |
| | 306 | | } |
| | 307 | |
|
| 3 | 308 | | ReportGlobalPointerEvent(InputEventType.UP, buttonId, useRaycast, raycastGlobalLayerHitInfo, raycastInfoGlob |
| | 309 | |
|
| | 310 | | // Raycast for global pointer events (for each PE scene) |
| 6 | 311 | | foreach (string pexId in DataStore.i.Get<DataStore_World>().portableExperienceIds.Get()) |
| | 312 | | { |
| 0 | 313 | | IParcelScene pexScene = worldState.GetPortableExperienceScene(pexId); |
| 0 | 314 | | if (pexScene != null) |
| | 315 | | { |
| 0 | 316 | | raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer, pexScene) |
| 0 | 317 | | raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo; |
| | 318 | |
|
| 0 | 319 | | ReportGlobalPointerEvent(InputEventType.UP, buttonId, useRaycast, raycastGlobalLayerHitInfo, raycast |
| | 320 | | } |
| | 321 | | } |
| 3 | 322 | | } |
| | 323 | |
|
| | 324 | | private void ProcessButtonDown(WebInterface.ACTION_BUTTON buttonId, bool useRaycast, bool enablePointerEvent, |
| | 325 | | LayerMask pointerEventLayer, int globalLayer) |
| | 326 | | { |
| 11 | 327 | | IWorldState worldState = Environment.i.world.state; |
| | 328 | |
|
| 11 | 329 | | int currentSceneNumber = worldState.GetCurrentSceneNumber(); |
| | 330 | |
|
| 11 | 331 | | if (currentSceneNumber <= 0) |
| 0 | 332 | | return; |
| | 333 | |
|
| 11 | 334 | | Ray ray = !Utils.IsCursorLocked || Utils.LockedThisFrame() ? GetRayFromMouse() : GetRayFromCamera(); |
| 11 | 335 | | worldState.TryGetScene(currentSceneNumber, out var loadedScene); |
| | 336 | |
|
| | 337 | | // Raycast for pointer event components |
| 11 | 338 | | RaycastResultInfo raycastInfoPointerEventLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, pointe |
| | 339 | |
|
| | 340 | | // Raycast for global pointer events |
| 11 | 341 | | RaycastResultInfo raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer, |
| 11 | 342 | | RaycastHitInfo raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo; |
| | 343 | |
|
| 11 | 344 | | bool isOnClickComponentBlocked = |
| | 345 | | IsBlockingOnClick(raycastInfoPointerEventLayer.hitInfo, raycastGlobalLayerHitInfo); |
| | 346 | |
|
| 11 | 347 | | if (!isOnClickComponentBlocked && raycastInfoPointerEventLayer.hitInfo.hit.collider) |
| | 348 | | { |
| 10 | 349 | | Collider collider = raycastInfoPointerEventLayer.hitInfo.hit.collider; |
| | 350 | |
|
| | 351 | | GameObject hitGameObject; |
| | 352 | |
|
| 10 | 353 | | if (CollidersManager.i.GetColliderInfo(collider, out ColliderInfo info)) |
| 10 | 354 | | hitGameObject = info.entity.gameObject; |
| | 355 | | else |
| 0 | 356 | | hitGameObject = collider.gameObject; |
| | 357 | |
|
| 10 | 358 | | IList<IPointerInputEvent> events = GetPointerInputEvents(hitGameObject); |
| | 359 | |
|
| 36 | 360 | | for (var i = 0; i < events.Count; i++) |
| | 361 | | { |
| 8 | 362 | | IPointerInputEvent e = events[i]; |
| 8 | 363 | | bool areSameEntity = AreSameEntity(e, info); |
| | 364 | |
|
| 8 | 365 | | switch (e.GetEventType()) |
| | 366 | | { |
| | 367 | | case PointerInputEventType.CLICK: |
| 1 | 368 | | if (areSameEntity && enablePointerEvent) |
| 1 | 369 | | e.Report(buttonId, ray, raycastInfoPointerEventLayer.hitInfo.hit); |
| | 370 | |
|
| 1 | 371 | | break; |
| | 372 | | case PointerInputEventType.DOWN: |
| 4 | 373 | | if (areSameEntity && enablePointerEvent) |
| 4 | 374 | | e.Report(buttonId, ray, raycastInfoPointerEventLayer.hitInfo.hit); |
| | 375 | |
|
| 4 | 376 | | break; |
| | 377 | | case PointerInputEventType.UP: |
| 3 | 378 | | if (areSameEntity && enablePointerEvent) |
| 3 | 379 | | pointerInputUpEvent = e; |
| | 380 | | else |
| 0 | 381 | | pointerInputUpEvent = null; |
| | 382 | |
|
| | 383 | | break; |
| | 384 | | } |
| | 385 | | } |
| | 386 | |
|
| 10 | 387 | | lastPointerDownEventHitInfo = raycastInfoPointerEventLayer.hitInfo; |
| | 388 | | } |
| | 389 | |
|
| 11 | 390 | | ReportGlobalPointerEvent(InputEventType.DOWN, buttonId, useRaycast, raycastGlobalLayerHitInfo, raycastInfoGl |
| | 391 | |
|
| | 392 | | // Raycast for global pointer events (for each PE scene) |
| 11 | 393 | | IEnumerable<string> currentPortableExperienceSceneIds = DataStore.i.world.portableExperienceIds.Get(); |
| | 394 | |
|
| 22 | 395 | | foreach (var pexSceneId in currentPortableExperienceSceneIds) |
| | 396 | | { |
| 0 | 397 | | IParcelScene pexSene = worldState.GetPortableExperienceScene(pexSceneId); |
| | 398 | |
|
| 0 | 399 | | if (pexSene != null) |
| | 400 | | { |
| 0 | 401 | | raycastInfoGlobalLayer = raycastHandler.Raycast(ray, charCamera.farClipPlane, globalLayer, pexSene); |
| | 402 | |
|
| 0 | 403 | | raycastGlobalLayerHitInfo = raycastInfoGlobalLayer.hitInfo; |
| | 404 | |
|
| 0 | 405 | | ReportGlobalPointerEvent(InputEventType.DOWN, buttonId, useRaycast, raycastGlobalLayerHitInfo, rayca |
| | 406 | | } |
| | 407 | | } |
| 11 | 408 | | } |
| | 409 | |
|
| | 410 | | private static void ReportGlobalPointerEvent(InputEventType eventType, WebInterface.ACTION_BUTTON buttonId, bool |
| | 411 | | RaycastResultInfo raycastInfoGlobalLayer, int sceneNumber) |
| | 412 | | { |
| 14 | 413 | | if (useRaycast && raycastGlobalLayerHitInfo.isValid) |
| | 414 | | { |
| 13 | 415 | | CollidersManager.i.GetColliderInfo(raycastGlobalLayerHitInfo.hit.collider, out ColliderInfo colliderInfo |
| | 416 | |
|
| 13 | 417 | | string entityId = colliderInfo.entity != null |
| | 418 | | ? Environment.i.world.sceneController.entityIdHelper.GetOriginalId(colliderInfo.entity.entityId) |
| | 419 | | : SpecialEntityIdLegacyLiteral.SCENE_ROOT_ENTITY; |
| | 420 | |
|
| 13 | 421 | | WebInterface.ReportGlobalPointerEvent(eventType ,buttonId, raycastInfoGlobalLayer.ray, raycastGlobalLaye |
| | 422 | | raycastGlobalLayerHitInfo.hit.distance, sceneNumber, entityId, colliderInfo.meshName, isHitInfoValid |
| | 423 | | } |
| | 424 | | else |
| 1 | 425 | | WebInterface.ReportGlobalPointerEvent(eventType, buttonId, raycastInfoGlobalLayer.ray, Vector3.zero, Vec |
| 1 | 426 | | } |
| | 427 | |
|
| | 428 | | private static bool AreSameEntity(IPointerEvent pointerInputEvent, ColliderInfo colliderInfo) |
| | 429 | | { |
| 8 | 430 | | if (pointerInputEvent == null) return false; |
| 8 | 431 | | if (pointerInputEvent.entity == null && colliderInfo.entity == null) return true; |
| 8 | 432 | | return pointerInputEvent.entity == colliderInfo.entity; |
| | 433 | | } |
| | 434 | |
|
| | 435 | | private bool IsBlockingOnClick(RaycastHitInfo targetOnClickHit, RaycastHitInfo potentialBlockerHit) => |
| 14 | 436 | | potentialBlockerHit.hit.collider != null // Does a potential blocker hit exist? |
| | 437 | | && targetOnClickHit.hit.collider != null // Was a target entity with a pointer event component hit? |
| | 438 | | && potentialBlockerHit.hit.distance <= targetOnClickHit.hit.distance // Is potential blocker nearer than tar |
| | 439 | | && !AreCollidersFromSameEntity(potentialBlockerHit, targetOnClickHit); // Does potential blocker belong to o |
| | 440 | |
|
| | 441 | | private static bool EntityHasPointerEvent(IDCLEntity entity) |
| | 442 | | { |
| 32 | 443 | | var componentsManager = entity.scene.componentsManagerLegacy; |
| | 444 | |
|
| 32 | 445 | | return componentsManager.HasComponent(entity, CLASS_ID_COMPONENT.UUID_CALLBACK) || |
| | 446 | | componentsManager.HasComponent(entity, CLASS_ID_COMPONENT.UUID_ON_UP) || |
| | 447 | | componentsManager.HasComponent(entity, CLASS_ID_COMPONENT.UUID_ON_DOWN) || |
| | 448 | | componentsManager.HasComponent(entity, CLASS_ID_COMPONENT.UUID_ON_CLICK); |
| | 449 | | } |
| | 450 | |
|
| | 451 | | private bool AreCollidersFromSameEntity(RaycastHitInfo hitInfoA, RaycastHitInfo hitInfoB) |
| | 452 | | { |
| 16 | 453 | | CollidersManager.i.GetColliderInfo(hitInfoA.hit.collider, out ColliderInfo colliderInfoA); |
| 16 | 454 | | CollidersManager.i.GetColliderInfo(hitInfoB.hit.collider, out ColliderInfo colliderInfoB); |
| | 455 | |
|
| 16 | 456 | | var entityA = colliderInfoA.entity; |
| 16 | 457 | | var entityB = colliderInfoB.entity; |
| | 458 | |
|
| 16 | 459 | | bool entityAHasEvent = entityA != null && EntityHasPointerEvent(entityA); |
| 16 | 460 | | bool entityBHasEvent = entityB != null && EntityHasPointerEvent(entityB); |
| | 461 | |
|
| | 462 | | // If both entities has OnClick/PointerEvent component |
| 16 | 463 | | if (entityAHasEvent && entityBHasEvent) |
| 14 | 464 | | return entityA == entityB; |
| | 465 | |
|
| | 466 | | // If only one of them has OnClick/PointerEvent component |
| 2 | 467 | | if (entityAHasEvent ^ entityBHasEvent) |
| 0 | 468 | | return false; |
| | 469 | |
|
| | 470 | | // None of them has OnClick/PointerEvent component |
| 2 | 471 | | return colliderInfoA.entity == colliderInfoB.entity; |
| | 472 | | } |
| | 473 | |
|
| | 474 | | private void HandleCursorLockChanges(bool isLocked) |
| | 475 | | { |
| 0 | 476 | | HideOrShowCursor(isLocked); |
| | 477 | |
|
| 0 | 478 | | if (!isLocked) |
| 0 | 479 | | UnhoverLastHoveredObject(); |
| 0 | 480 | | } |
| | 481 | |
|
| | 482 | | private static void HideOrShowCursor(bool isCursorLocked) => |
| 85 | 483 | | DataStore.i.Get<DataStore_Cursor>().cursorVisible.Set(isCursorLocked); |
| | 484 | |
|
| | 485 | | private static void SetHoverCursor() => |
| 18 | 486 | | DataStore.i.Get<DataStore_Cursor>().cursorType.Set(DataStore_Cursor.CursorType.HOVER); |
| | 487 | |
|
| | 488 | | private static void SetNormalCursor() => |
| 5 | 489 | | DataStore.i.Get<DataStore_Cursor>().cursorType.Set(DataStore_Cursor.CursorType.NORMAL); |
| | 490 | |
|
| | 491 | | private bool CanRaycastWhileUnlocked() |
| | 492 | | { |
| 1091 | 493 | | if (eventSystemInputModuleLazy == null) |
| 1091 | 494 | | return true; |
| | 495 | |
|
| 0 | 496 | | return mouseCatcher.IsEqualsToRaycastTarget( |
| | 497 | | eventSystemInputModuleLazy.GetPointerData().pointerCurrentRaycast.gameObject); |
| | 498 | | } |
| | 499 | | } |
| | 500 | | } |