/// <summary> /// Remove the character at the given index. /// </summary> /// <param name="index">The index.</param> public void RemoveCharacter(int index) { if (this.m_Slots.Count == 0) { return; } // Get the slot Transform slotTrans = this.m_Slots[index]; if (slotTrans == null) { return; } // Get the character script Demo_CharacterSelectSlot slot = slotTrans.gameObject.GetComponent <Demo_CharacterSelectSlot>(); // Invoke the on character delete event if (this.m_OnCharacterDelete != null && slot.info != null) { this.m_OnCharacterDelete.Invoke(slot.info); } // Unset the character info if (slot != null) { slot.info = null; } // Deselect if (slot != null) { slot.OnDeselected(); } // Remove the child objects foreach (Transform child in slotTrans) { Destroy(child.gameObject); } // Unset the character info texts if (index == this.m_SelectedIndex) { if (this.m_InfoContainer != null) { this.m_InfoContainer.SetActive(false); } if (this.m_NameText != null) { this.m_NameText.text = ""; } if (this.m_LevelText != null) { this.m_LevelText.text = ""; } if (this.m_RaceText != null) { this.m_RaceText.text = ""; } if (this.m_ClassText != null) { this.m_ClassText.text = ""; } this.SelectFirstAvailable(); } }
/// <summary> /// Selects the character slot. /// </summary> /// <param name="slot">The character slot component.</param> public void SelectCharacter(Demo_CharacterSelectSlot slot) { // Check if already selected if (this.m_SelectedIndex == slot.index) { return; } // Deselect if (this.m_SelectedIndex > -1) { // Get the slot Transform selectedSlotTrans = this.m_Slots[this.m_SelectedIndex]; if (selectedSlotTrans != null) { // Get the character script Demo_CharacterSelectSlot selectedSlot = selectedSlotTrans.gameObject.GetComponent <Demo_CharacterSelectSlot>(); // Deselect if (selectedSlot != null) { selectedSlot.OnDeselected(); } } } // Set the selected this.m_SelectedIndex = slot.index; this.m_SelectedTransform = slot.transform; if (slot.info != null) { if (this.m_InfoContainer != null) { this.m_InfoContainer.SetActive(true); } if (this.m_NameText != null) { this.m_NameText.text = slot.info.name.ToUpper(); } if (this.m_LevelText != null) { this.m_LevelText.text = slot.info.level.ToString(); } if (this.m_RaceText != null) { this.m_RaceText.text = slot.info.raceString; } if (this.m_ClassText != null) { this.m_ClassText.text = slot.info.classString; } // Invoke the on character selected event if (this.m_OnCharacterSelected != null) { this.m_OnCharacterSelected.Invoke(slot.info); } } else { if (this.m_InfoContainer != null) { this.m_InfoContainer.SetActive(false); } if (this.m_NameText != null) { this.m_NameText.text = ""; } if (this.m_LevelText != null) { this.m_LevelText.text = ""; } if (this.m_RaceText != null) { this.m_RaceText.text = ""; } if (this.m_ClassText != null) { this.m_ClassText.text = ""; } } slot.OnSelected(); }