/// <summary> /// Removes focus on the focused item, if there is one. /// </summary> private void RemoveFocus(bool lerpToNewState) { if (m_focusedItem != null) { m_focusedItem.SetFocus(false, lerpToNewState); m_focusedItem = null; } }
/// <summary> /// Sets the specified character in character select as "used" by the player. /// </summary> /// <param name="character">The character.</param> public void SetUsed(CharacterType character) { CharacterSelectItem item = m_charSelectItemList[(int)character]; if (item != null && !item.IsUsed) { item.SetUsed(); // Increment used character count m_usedCharCount++; } }
/// <summary> /// Initializes the character scroll panel. /// </summary> private void InitializeCharacterScrollPanel(GameSceneMaster sceneMaster) { // Initialize scroll panel m_characterSelectPanel.Initialize(false, false); // Populate character list GameObject[] prefabs = m_characterResource.GetCharacterPrefabs(); for (int index = 0; index < prefabs.Length; ++index) { // Instantiate character Character character = m_characterResource.CreateCharacter((CharacterType)index); // Create scroll item UIScrollItem newItem = m_characterSelectPanel.CreateScrollItem(); // Child character under scroll item character.transform.parent = newItem.transform; // Position character "behind" the scroll item character.transform.localPosition = new Vector3(0.0f, 0.0f, m_normalCharLocalPosZ); // Set initial rotation character.transform.eulerAngles = m_initialRotation; // Set normal scale character.transform.localScale = Vector3.one * m_normalCharScale; // Add scroll item to scroll panel m_characterSelectPanel.AddScrollItem(newItem); // Set the character layer and sorting layer to UI character.ModelRenderer.gameObject.layer = LayerMask.NameToLayer(m_scrollItemLayer); character.ModelRenderer.sortingLayerName = m_scrollItemSortingLayer; character.ModelRenderer.sortingOrder = m_scrollItemSortingOrder; // Attach a CharacterSelectItem component to allow handling from CharacterSelectUI CharacterSelectItem charSelectItem = newItem.gameObject.AddComponentNoDupe <CharacterSelectItem>(); bool isUsed = sceneMaster.IsUsed((CharacterType)index); bool isOwned = sceneMaster.IsOwned((CharacterType)index); charSelectItem.Initialize(this, newItem, character, isUsed, isOwned, m_ownedCharRotSpeed, m_normalCharScale, m_focusCharScale, m_focusCharAnimTime, m_focusCharPosition, m_newCharWinAnim, m_newCharAnimReference); if (!m_charSelectItemList.Contains(charSelectItem)) { m_charSelectItemList.Add(charSelectItem); } // Update the number of used characters (those that have been equipped by the player at least once) if (isUsed) { m_usedCharCount++; } // Update the number of owned characters if (isOwned) { m_ownedCharCount++; } } }
/// <summary> /// Detects and sets focus on the character currently in the center of the screen. /// </summary> private void UpdateFocusedCharacter() { // If character select is hidden, do not do any focusing if (!m_characterSelectRoot.activeInHierarchy) { return; } Vector3 focusAreaCenter = m_characterSelectPanel.ScrollBounds.center; UIScrollItem nearestScrollItem = m_characterSelectPanel.GetItemNearestToPosition(focusAreaCenter); if (nearestScrollItem == null) { return; } // Scroll item should be within slot-size distance of the focus area // If character panel is scrolled out too far from the focus area, // do not focus on any character if (Mathf.Abs(nearestScrollItem.transform.position.x - focusAreaCenter.x) > m_characterSelectPanel.SlotSize.x) { // If there was a focused item, remove focus if (m_focusedItem != null) { m_focusedItem.SetFocus(false); m_focusedItem = null; UpdateFocusAreaFields(); } } else { // If new focused item, unfocus the old one and focus on the new one CharacterSelectItem nearestItem = nearestScrollItem.GetComponent <CharacterSelectItem>(); if (m_focusedItem != nearestItem) { RemoveFocus(true); nearestItem.SetFocus(true); m_focusedItem = nearestItem; UpdateFocusAreaFields(); // Play the character select sound Locator.GetSoundManager().PlayOneShot(SoundInfo.SFXID.CharacterSelect); } } }
// Update is called once per frame void Update() { CharacterSelectItem selectedItem = SelectItemChildren[selectedIndex]; if (selectedItem != null) { //SelectionRectangle.transform.SetPositionAndRotation(selectedItem.transform.position, selectedItem.transform.rotation); SelectionRectangle.transform.position = Vector3.Lerp(SelectionRectangle.transform.position, selectedItem.gameObject.transform.position, Speed * Time.deltaTime); SelectionRectangle.transform.localScale = Vector3.Lerp(SelectionRectangle.transform.localScale, selectedItem.gameObject.transform.localScale, Speed * Time.deltaTime); SelectedText.GetComponent <TextMesh>().text = selectedItem.Name; } if (Input.anyKeyDown) { selectedIndex = (selectedIndex + 1) % SelectItemChildren.Length; } transform.rotation = initialRotation * Quaternion.Euler(20 * new Vector3(Input.GetAxis("Vertical"), 0, Input.GetAxis("Horizontal"))); }
public void InitCharacterScrollList() { foreach (PlayerSO player in GamePlay.instance.PlayersList) { Debug.Log("Test from init characters"); GameObject tmp = Instantiate(SelectCharacterItemPrefab, SelectionContainer); CharacterSelectItem item = tmp.GetComponent <CharacterSelectItem>(); item.InitializeItem(player); if (player.isAvaliable) { item.button.interactable = true; item.button.onClick.AddListener(() => SelectCharacter(player)); item.button.onClick.AddListener(() => SoundManager.instance.PlayVFX("ClickBuble")); } else { item.button.interactable = false; } } SelectionContainer.GetChild(0).transform.GetComponent <CharacterSelectItem>().button.onClick.Invoke(); SoundManager.instance.PlayVFX("PlayerOneChoose"); }