ColorDropdownController.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6. using System.Threading.Tasks;
  7. public class ColorDropdownController : MonoBehaviour
  8. {
  9. [SerializeField] Dropdown _colorDropdown;
  10. public void OnColorDropdownChanged(int value)
  11. {
  12. if (_colorDropdown == null) return;
  13. if (_colorDropdown.captionText == null) return;
  14. _colorDropdown.captionText.color = Color.white;
  15. int colorIndex = value - 1;
  16. if (colorIndex < 0) return;
  17. if (_colorDropdown.options.Count - 1 < colorIndex) return;
  18. if (Enum.GetValues(typeof(CardColor)).Length - 1 < colorIndex) return;
  19. CardColor cardColor = (CardColor)Enum.ToObject(typeof(CardColor), colorIndex);
  20. if (cardColor == CardColor.Yellow || cardColor == CardColor.White)
  21. {
  22. _colorDropdown.captionText.color = Color.black;
  23. }
  24. }
  25. public async void OnClickColorDropdown()
  26. {
  27. await Task.Delay(TimeSpan.FromSeconds(Time.deltaTime));
  28. SetBlackItemLabelColor(GameObject.Find("Item 3: Y"));
  29. SetBlackItemLabelColor(GameObject.Find("Item 5: W"));
  30. static void SetBlackItemLabelColor(GameObject item)
  31. {
  32. if (item != null)
  33. {
  34. if (item.transform.childCount >= 3)
  35. {
  36. Transform child = item.transform.GetChild(2);
  37. if (child != null)
  38. {
  39. Text text = child.GetComponent<Text>();
  40. if (text != null)
  41. {
  42. text.color = Color.black;
  43. }
  44. }
  45. }
  46. }
  47. }
  48. }
  49. }