/// public bool IsConstrainedToContainer(UAP_AccessibilityManager.ESDirection direction) { switch (direction) { case UAP_AccessibilityManager.ESDirection.ELeft: return(m_ConstrainToContainerLeft); case UAP_AccessibilityManager.ESDirection.EUp: return(m_ConstrainToContainerUp); case UAP_AccessibilityManager.ESDirection.ERight: return(m_ConstrainToContainerRight); case UAP_AccessibilityManager.ESDirection.EDown: return(m_ConstrainToContainerDown); } return(false); }
public bool MoveFocus2D(UAP_AccessibilityManager.ESDirection direction) { // Select the closest item in the direction (quarter) // that's also active. //Debug.Log("[Container] Moving focus " + direction); Vector2 activeItemPos = m_AllElements[m_CurrentItemIndex].m_Pos; // Go through all items (skip current one) Vector2 deltaPos; int nextElementIndex = -1; float closestDistanceSquared = -1.0f; for (int i = 0; i < m_AllElements.Count; ++i) { if (i == m_CurrentItemIndex) { continue; } if (!m_AllElements[i].m_Object.IsElementActive()) { continue; } deltaPos = m_AllElements[i].m_Pos - activeItemPos; // Add in a delta scale by which one axis must be larger than the other // to avoid going diagonal at the edges of grids with uneven numbers of elements // in a row or column (think of a diamond shaped grid - the focus should not jump // up or down a row when the edge is hit and the user tries to keep going. float deltaScale = 1.1f; // this means the axis needs to be 10% larger // Check if the position of the item is in the right quarter bool isInQuarter = false; switch (direction) { case UAP_AccessibilityManager.ESDirection.ELeft: if (deltaPos.x < 0 && (-deltaPos.x) > Mathf.Abs(deltaPos.y) * deltaScale) { isInQuarter = true; } break; case UAP_AccessibilityManager.ESDirection.ERight: if (deltaPos.x > 0 && deltaPos.x > Mathf.Abs(deltaPos.y) * deltaScale) { isInQuarter = true; } break; case UAP_AccessibilityManager.ESDirection.EUp: if (deltaPos.y > 0 && deltaPos.y > Mathf.Abs(deltaPos.x) * deltaScale) { isInQuarter = true; } break; case UAP_AccessibilityManager.ESDirection.EDown: if (deltaPos.y < 0 && (-deltaPos.y) > Mathf.Abs(deltaPos.x) * deltaScale) { isInQuarter = true; } break; } if (!isInQuarter) { continue; } // Check distance (squared) if larger then current smallest, continue float squaredDistance = deltaPos.SqrMagnitude(); if (nextElementIndex < 0 || squaredDistance < closestDistanceSquared) { nextElementIndex = i; closestDistanceSquared = squaredDistance; } } // Did the element change? if (nextElementIndex < 0) { //Debug.Log("[Container] Found no element to go to."); return(false); } //Debug.Log("[Container] Found a new element"); m_CurrentItemIndex = nextElementIndex; return(true); }