private void Update() { // Only do raycasting if the linked commander // has been set. Also skip raycasting if the // click is active. if (LinkedCommander != null) { // Cast a ray against the scene. if (Physics.Raycast( commanderCamera.ScreenPointToRay(Mouse.current.position.ReadValue()), out RaycastHit hit, raycastDistance, layerMask)) { // Set the latest hit position. CurrentHitPosition = hit.point; // If not in the clicking state, check // for updates in the hovered objects. if (!inClick) { // Check to see if there is a focusable component. ICommanderFocusable focusable = hit.collider.GetComponent <ICommanderFocusable>(); if (focusable != null) { // Is this a new focused item? if (focusable != currentFocused) { // Update the focused states. if (currentFocused != null) { currentFocused.FocusedExit(this, LinkedCommander); } currentFocused = focusable; currentFocused.FocusedEnter(this, LinkedCommander); } } else if (currentFocused != null) { // If we are not hovering on a focusable item, // then clear any focused state. currentFocused.FocusedExit(this, LinkedCommander); currentFocused = null; } // Check to see if there is a clickable component. currentClickable = hit.collider.GetComponent <ICommanderClickable>(); } } } }
private void OnClicked() { inClick = true; // Clear any focused state. if (currentFocused != null) { currentFocused.FocusedExit(this, LinkedCommander); currentFocused = null; } // Trigger clicked enter state. if (currentClickable != null) { currentClickable.ClickEnter(this, LinkedCommander, CurrentHitPosition); } }