public void ClearAll() { for (int index = 0; index < m_PlayerSlots.Count; ++index) { tnUILocalPlayerSlot playerSlot = m_PlayerSlots[index]; if (playerSlot != null) { playerSlot.Clear(); } } }
public void SetPlayerName(int i_Index, string i_PlayerName, int i_GuestIndex) { tnUILocalPlayerSlot playerSlot = GetLocalPlayerSlot(i_Index); if (playerSlot == null) { return; } playerSlot.SetPlayerName(i_PlayerName, i_GuestIndex); }
// BUSINESS LOGIC public void SetPlayerSlot(int i_Index, int i_PlayerId) { tnUILocalPlayerSlot playerSlot = GetLocalPlayerSlot(i_Index); if (playerSlot == null) { return; } playerSlot.Bind(i_PlayerId); // Play sfx. SfxPlayer.PlayMain(m_PlayerJoinedSfx); }
public void FreePlayerSlot(int i_Index) { tnUILocalPlayerSlot playerSlot = GetLocalPlayerSlot(i_Index); if (playerSlot == null) { return; } playerSlot.Clear(); // Play sfx. SfxPlayer.PlayMain(m_PlayerLeftSfx); }
// INTERNALS private void SpawnSlots() { if (m_PanelSlots == null || m_SlotControllerEntry == null) { return; } // Create new slots int rows = m_SlotCount / m_Columns + ((m_SlotCount % m_Columns != 0) ? 1 : 0); int columns = Mathf.Max(1, m_Columns); float slotWidth = 1f / columns; float slotHeight = 1f / rows; float contentWidth = m_PanelSlots.rect.width; float contentHeight = m_PanelSlots.rect.height; float spacingWidth = (contentWidth > 0f) ? (m_CellSpacing / contentWidth) : 0f; float spacingHeight = (contentHeight > 0f) ? (m_CellSpacing / contentHeight) : 0f; for (int rowIndex = 0; rowIndex < rows; ++rowIndex) { for (int columnIndex = 0; columnIndex < columns; ++columnIndex) { if (m_PlayerSlots.Count >= m_SlotCount) { continue; } tnUILocalPlayerSlot slotEntry = tnUILocalPlayerSlot.Instantiate <tnUILocalPlayerSlot>(m_SlotControllerEntry); slotEntry.name = m_PlayerSlots.Count.ToString(); slotEntry.Clear(); slotEntry.transform.SetParent(m_PanelSlots, false); RectTransform slotRectTransform = slotEntry.GetComponent <RectTransform>(); if (slotRectTransform != null) { float anchorMinX = (columnIndex * slotWidth); float anchorMaxX = anchorMinX + slotWidth; float anchorMaxY = (1f - rowIndex * slotHeight); float anchorMinY = (anchorMaxY - slotHeight); anchorMinX += spacingWidth / 2f; anchorMaxX -= spacingWidth / 2f; anchorMinY += spacingHeight / 2f; anchorMaxY -= spacingHeight / 2f; if (rowIndex == 0) { anchorMaxY -= spacingHeight / 2f; } if (rowIndex == rows - 1) { anchorMinY += spacingHeight / 2f; } if (columnIndex == 0) { anchorMinX += spacingWidth / 2f; } if (columnIndex == columns - 1) { anchorMaxX -= spacingWidth / 2f; } slotRectTransform.SetAnchor(anchorMinX, anchorMinY, anchorMaxX, anchorMaxY); slotRectTransform.sizeDelta = Vector2.zero; m_PlayerSlots.Add(slotEntry); } } } }