/// <summary> /// Create and Initialise a Level select button based on item /// </summary> /// <param name="item"> /// The level data /// </param> /// <returns> /// The initialised button /// </returns> protected LevelSelectButton CreateButton(LevelItem item) { LevelSelectButton button = Instantiate(selectionPrefab); button.Initialize(item, mouseScroll); return(button); }
/// <summary> /// Called when a button inside the scroll is selected /// </summary> /// <param name="levelSelectButton">Selected child</param> public void SelectChild(LevelSelectButton levelSelectButton) { // minus one if buffer int childCount = levelSelectButton.transform.parent.childCount - (m_HasRightBuffer ? 1 : 0); if (childCount > 1) { float normalized = (float)levelSelectButton.transform.GetSiblingIndex() / (childCount - 1); m_ScrollRect.normalizedPosition = new Vector2(normalized, 0); } }
/// <summary> /// Instantiate the buttons /// </summary> protected virtual void Start() { if (GameManager.instance == null) { return; } m_LevelList = GameManager.instance.levelList; if (layout == null || selectionPrefab == null || m_LevelList == null) { return; } int amount = m_LevelList.Count; for (int i = 0; i < amount; i++) { LevelSelectButton button = CreateButton(m_LevelList[i]); button.transform.SetParent(layout.transform); button.transform.localScale = Vector3.one; m_Buttons.Add(button.GetComponent <Button>()); } if (rightBuffer != null) { rightBuffer.SetAsLastSibling(); } for (int index = 1; index < m_Buttons.Count - 1; index++) { Button button = m_Buttons[index]; SetUpNavigation(button, m_Buttons[index - 1], m_Buttons[index + 1]); } SetUpNavigation(m_Buttons[0], backButton, m_Buttons[1]); SetUpNavigation(m_Buttons[m_Buttons.Count - 1], m_Buttons[m_Buttons.Count - 2], null); mouseScroll.SetHasRightBuffer(rightBuffer != null); }