FabioZumbi12

DropDownSelect.cs

Jun 25th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using TMPro;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using UnityEngine.UI;
  5. using static TMPro.TMP_Dropdown;
  6.  
  7. public class DropDownSelect : MonoBehaviour
  8. {
  9.     void Update ()
  10.     {
  11.         TMP_Dropdown dropMusics = GetComponent<TMP_Dropdown>();
  12.         if (dropMusics.IsExpanded && EventSystem.current.currentSelectedGameObject != null)
  13.         {
  14.             string selected = EventSystem.current.currentSelectedGameObject.GetComponentInChildren<TextMeshProUGUI>()?.text;
  15.             Scrollbar scroll = GameObject.Find("Dropdown List").GetComponentInChildren<Scrollbar>();
  16.            
  17.             int count = 0;
  18.             foreach (OptionData pos in dropMusics.options)
  19.             {
  20.                 if (pos.text == selected)
  21.                 {
  22.                     scroll.value = 1f - ((float)count / (dropMusics.options.Count-1));                    
  23.                     break;
  24.                 }
  25.                 count++;
  26.             }
  27.         }        
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment