public void Capture() { for (int i = 0; i < Bindings.Keys.Length; i++) { Binding key = Bindings.Keys[i]; bool keyPressed = Input.GetKey(key.Code); if (keyPressed == key.State) { continue; } Bindings.Keys[i].State = keyPressed; if (!keyPressed && !Release.Contains(key.InteractionSubscription)) { continue; } if (keyPressed && !Press.Contains(key.InteractionSubscription)) { continue; } Interaction interaction = keyPressed ? Interaction.Pressed : Interaction.Released; switch (key.Type) { case InputType.Key: OnKeyEvent?.Invoke(new KeyEvent(interaction, key.Action)); break; case InputType.Mouse: OnPointerEvent?.Invoke(new PointerEvent(interaction, key.Action, Input.mousePosition)); break; default: throw new System.Exception("Unhandled input binding type: " + key.Type); } } }
private OnPointerEvent <T> Get(PointerEventType eventType) { if (!events.ContainsKey(eventType)) { events[eventType] = new OnPointerEvent <T>(); } return(events[eventType]); }
public void Cleanup() { InputController_Legacy.i.RemoveListener(WebInterface.ACTION_BUTTON.POINTER, OnButtonEvent); InputController_Legacy.i.RemoveListener(WebInterface.ACTION_BUTTON.PRIMARY, OnButtonEvent); InputController_Legacy.i.RemoveListener(WebInterface.ACTION_BUTTON.SECONDARY, OnButtonEvent); lastHoveredObject = null; newHoveredObject = null; newHoveredEvent = null; lastHoveredEventList = null; }
public void Cleanup() { InputController_Legacy.i.RemoveListener(WebInterface.ACTION_BUTTON.POINTER, OnButtonEvent); InputController_Legacy.i.RemoveListener(WebInterface.ACTION_BUTTON.PRIMARY, OnButtonEvent); InputController_Legacy.i.RemoveListener(WebInterface.ACTION_BUTTON.SECONDARY, OnButtonEvent); lastHoveredObject = null; newHoveredObject = null; newHoveredEvent = null; lastHoveredEventList = null; if (CursorController.i != null) { OnPointerHoverStarts -= CursorController.i.SetHoverCursor; OnPointerHoverEnds -= CursorController.i.SetNormalCursor; } }
static void Assign(jQuery element, string eventName, OnPointerEvent pointerEvent) { element.On(eventName, pointerEvent); }
/// <summary> /// THe pointer has clicked the element /// </summary> /// <param name="eventData"></param> public void OnPointerClick(PointerEventData eventData) { OnPointerEvent?.Invoke(EPointerEvent.Click); OnClickEvent?.Invoke(); }
/// <summary> /// IPointerUpHandler function /// </summary> /// <param name="eventData"></param> public void OnPointerUp(PointerEventData eventData) => OnPointerEvent?.Invoke(EPointerEvent.Up);
/// <summary> /// IPointerExitHandler function /// </summary> /// <param name="eventData"></param> public void OnPointerExit(PointerEventData eventData) => OnPointerEvent?.Invoke(EPointerEvent.Exit);
/// <summary> /// IPointerEnterHandler function /// </summary> /// <param name="eventData"></param> public void OnPointerEnter(PointerEventData eventData) => OnPointerEvent?.Invoke(EPointerEvent.Enter);
/// <summary> /// IPointerDownHandler function /// </summary> /// <param name="eventData"></param> public void OnPointerDown(PointerEventData eventData) => OnPointerEvent?.Invoke(EPointerEvent.Down);
void Update() { if (!CommonScriptableObjects.rendererState.Get() || charCamera == null) { return; } // We use Physics.Raycast() instead of our raycastHandler.Raycast() as that one is slower, sometimes 2x, because it fetches info we don't need here if (!Physics.Raycast(GetRayFromCamera(), out hitInfo, Mathf.Infinity, PhysicsLayers.physicsCastLayerMaskWithoutCharacter)) { clickHandler = null; UnhoverLastHoveredObject(); return; } var raycastHandlerTarget = hitInfo.collider.GetComponent <IRaycastPointerHandler>(); if (raycastHandlerTarget != null) { ResolveGenericRaycastHandlers(raycastHandlerTarget); UnhoverLastHoveredObject(); return; } if (CollidersManager.i.GetColliderInfo(hitInfo.collider, out ColliderInfo info)) { newHoveredEvent = info.entity.gameObject.GetComponentInChildren <OnPointerEvent>(); } else { newHoveredEvent = hitInfo.collider.GetComponentInChildren <OnPointerEvent>(); } clickHandler = null; if (!EventObjectCanBeHovered(newHoveredEvent, info)) { UnhoverLastHoveredObject(); return; } newHoveredObject = newHoveredEvent.gameObject; if (newHoveredObject != lastHoveredObject) { UnhoverLastHoveredObject(); lastHoveredObject = newHoveredObject; lastHoveredEventList = newHoveredObject.GetComponents <OnPointerEvent>(); OnPointerHoverStarts?.Invoke(); } // OnPointerDown/OnClick and OnPointerUp should display their hover feedback at different moments if (lastHoveredEventList != null && lastHoveredEventList.Length > 0) { for (int i = 0; i < lastHoveredEventList.Length; i++) { OnPointerEvent e = lastHoveredEventList[i]; bool eventButtonIsPressed = InputController_Legacy.i.IsPressed(e.GetActionButton()); if (e is OnPointerUp && eventButtonIsPressed) { e.SetHoverState(true); } else if ((e is OnPointerDown || e is OnClick) && !eventButtonIsPressed) { e.SetHoverState(true); } else { e.SetHoverState(false); } } } newHoveredObject = null; newHoveredEvent = null; }
bool AreSameEntity(OnPointerEvent pointerEvent, ColliderInfo colliderInfo) { return(pointerEvent != null && colliderInfo.entity != null && pointerEvent.entity == colliderInfo.entity); }
bool IsAvatarPointerEvent(OnPointerEvent targetPointerEvent) { return(targetPointerEvent != null && targetPointerEvent is AvatarOnPointerDown); }
private bool EventObjectCanBeHovered(OnPointerEvent targetEvent, ColliderInfo colliderInfo) { return(newHoveredEvent != null && newHoveredEvent.IsAtHoverDistance(DCLCharacterController.i.transform) && (IsAvatarPointerEvent(newHoveredEvent) || (newHoveredEvent.IsVisible() && AreSameEntity(newHoveredEvent, colliderInfo)))); }
public void Update() { if (!CommonScriptableObjects.rendererState.Get() || charCamera == null) { return; } IWorldState worldState = Environment.i.world.state; // We use Physics.Raycast() instead of our raycastHandler.Raycast() as that one is slower, sometimes 2x, because it fetches info we don't need here bool didHit = Physics.Raycast(GetRayFromCamera(), out hitInfo, Mathf.Infinity, PhysicsLayers.physicsCastLayerMaskWithoutCharacter); bool uiIsBlocking = false; string currentSceneId = worldState.currentSceneId; bool validCurrentSceneId = !string.IsNullOrEmpty(currentSceneId); bool validCurrentScene = validCurrentSceneId && worldState.loadedScenes.ContainsKey(currentSceneId); // NOTE: in case of a single scene loaded (preview or builder) sceneId is set to null when stepping outside if (didHit && validCurrentSceneId && validCurrentScene) { GraphicRaycaster raycaster = worldState.loadedScenes[currentSceneId].uiScreenSpace?.graphicRaycaster; if (raycaster) { uiGraphicRaycastPointerEventData.position = new Vector2(Screen.width / 2, Screen.height / 2); uiGraphicRaycastResults.Clear(); raycaster.Raycast(uiGraphicRaycastPointerEventData, uiGraphicRaycastResults); uiIsBlocking = uiGraphicRaycastResults.Count > 0; } } if (!didHit || uiIsBlocking) { clickHandler = null; UnhoverLastHoveredObject(hoverController); return; } var raycastHandlerTarget = hitInfo.collider.GetComponent <IRaycastPointerHandler>(); if (raycastHandlerTarget != null) { ResolveGenericRaycastHandlers(raycastHandlerTarget); UnhoverLastHoveredObject(hoverController); return; } if (CollidersManager.i.GetColliderInfo(hitInfo.collider, out ColliderInfo info)) { newHoveredEvent = info.entity.gameObject.GetComponentInChildren <OnPointerEvent>(); } else { newHoveredEvent = hitInfo.collider.GetComponentInChildren <OnPointerEvent>(); } clickHandler = null; if (!EventObjectCanBeHovered(newHoveredEvent, info, hitInfo.distance)) { UnhoverLastHoveredObject(hoverController); return; } newHoveredObject = newHoveredEvent.gameObject; if (newHoveredObject != lastHoveredObject) { UnhoverLastHoveredObject(hoverController); lastHoveredObject = newHoveredObject; lastHoveredEventList = newHoveredObject.GetComponents <OnPointerEvent>(); OnPointerHoverStarts?.Invoke(); } // OnPointerDown/OnClick and OnPointerUp should display their hover feedback at different moments if (lastHoveredEventList != null && lastHoveredEventList.Length > 0) { for (int i = 0; i < lastHoveredEventList.Length; i++) { OnPointerEvent e = lastHoveredEventList[i]; bool eventButtonIsPressed = InputController_Legacy.i.IsPressed(e.GetActionButton()); if (e is OnPointerUp && eventButtonIsPressed) { e.SetHoverState(true); } else if ((e is OnPointerDown || e is OnClick) && !eventButtonIsPressed) { e.SetHoverState(true); } else { e.SetHoverState(false); } } } newHoveredObject = null; newHoveredEvent = null; }
private bool EventObjectCanBeHovered(OnPointerEvent targetEvent, ColliderInfo colliderInfo, float distance) { return(newHoveredEvent != null && newHoveredEvent.IsAtHoverDistance(distance) && (IsAvatarPointerEvent(newHoveredEvent) || (newHoveredEvent.IsVisible() && AreSameEntity(newHoveredEvent, colliderInfo)))); }