private void CheckClosestTouchable() { float closestDistance = float.MaxValue; Vector2 bodyCenter2D = new Vector2(m_head.position.x, m_head.position.z); DHUI_Touchable closestTouchable = null; foreach (DHUI_Touchable touchable in registeredTouchables) { // Skip Disabled and Inactive Touchables if (!touchable.isActiveAndEnabled || !touchable.IsEnabled) { continue; } // Skip Touchables to close to the user's body. Vector2 touchableCenter2D = new Vector2(touchable.CenterPoint.x, touchable.CenterPoint.z); if (Vector2.Distance(bodyCenter2D, touchableCenter2D) <= _bodyDangerRadius && touchable != ActiveTouchable) { continue; } // Get closest Touchable to the InteractionPoint float distance = Vector3.Distance(m_physicalInteractionPoint.position, touchable.CenterPoint); if (distance < closestDistance) { closestDistance = distance; closestTouchable = touchable; } } if (closestDistance <= _maxReachableDistance) { ActiveTouchable = closestTouchable; } else { ActiveTouchable = null; } }
public void DeregisterTouchable(DHUI_Touchable _touchable) { registeredTouchables.Remove(_touchable); }
public void RegisterTouchable(DHUI_Touchable _touchable) { registeredTouchables.Add(_touchable); }