void UpdateRoll() { // prepare data float[] origins = new float[3]; GetPositions(ref origins); float offset = origins[1] - origins[0]; float speed = offset * 0.25f; // compute new position float newY = m_MiddleLabel.Widget.GetRectInScreenCoords().center.y - speed; float[] pos = new float[3]; if (CanSwapLabels(newY, origins[0] + offset * 0.5f) == true) { pos[0] = newY; pos[1] = pos[0] + offset; pos[2] = pos[1] + offset; SetCurrentSelection(m_PendingSelection); m_IsDirty = true; } else if (CanRollLabels(newY, origins[1]) == true) { pos[0] = newY - offset; pos[1] = newY; pos[2] = newY + offset; m_IsDirty = true; } else { pos[0] = origins[0]; pos[1] = origins[1]; pos[2] = origins[2]; } // set new position SetPositions(ref pos); // update direction state if (m_IsDirty == false) { m_RollDirection = E_RollDirection.None; } }
public void SelectNext() { if (m_Items.Length <= 1) { return; } int idx = Selection + 1; if (idx >= m_Items.Length) { idx = 0; } Selection = idx; m_RollDirection = E_RollDirection.Down; }
public void SelectPrevious() { if (m_Items.Length <= 1) { return; } int idx = Selection - 1; if (idx < 0) { idx = Mathf.Max(0, m_Items.Length - 1); } Selection = idx; m_RollDirection = E_RollDirection.Up; }
// PUBLIC METHODS public void SetSelection(int value, bool immediate = false) { m_PendingSelection = Mathf.Clamp(value, 0, m_Items.Length - 1); if (m_CurrentSelection == m_PendingSelection) { return; } if (immediate == true) { m_CurrentSelection = m_PendingSelection; UpdateTexts(); } else { m_RollDirection = m_CurrentSelection > m_PendingSelection ? E_RollDirection.Down : E_RollDirection.Up; m_IsDirty = true; } }