BetterTextMeshProDropdown.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using TMPro;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. namespace TheraBytes.BetterUi
  9. {
  10. [AddComponentMenu("Better UI/TextMeshPro/Better TextMeshPro - Dropdown", 30)]
  11. public class BetterTextMeshProDropdown : TMP_Dropdown, IBetterTransitionUiElement
  12. {
  13. public List<Transitions> BetterTransitions { get { return betterTransitions; } }
  14. public List<Transitions> ShowHideTransitions { get { return showHideTransitions; } }
  15. [SerializeField]
  16. List<Transitions> betterTransitions = new List<Transitions>();
  17. [SerializeField]
  18. List<Transitions> showHideTransitions = new List<Transitions>();
  19. protected override void DoStateTransition(SelectionState state, bool instant)
  20. {
  21. base.DoStateTransition(state, instant);
  22. if (!(base.gameObject.activeInHierarchy))
  23. return;
  24. foreach (var info in betterTransitions)
  25. {
  26. info.SetState(state.ToString(), instant);
  27. }
  28. }
  29. protected override GameObject CreateDropdownList(GameObject template)
  30. {
  31. foreach (var tr in showHideTransitions)
  32. {
  33. tr.SetState("Show", false);
  34. }
  35. return base.CreateDropdownList(template);
  36. }
  37. protected override void DestroyDropdownList(GameObject dropdownList)
  38. {
  39. foreach (var tr in showHideTransitions)
  40. {
  41. tr.SetState("Hide", false);
  42. }
  43. base.DestroyDropdownList(dropdownList);
  44. }
  45. }
  46. }