SetColorOnSelection.cs 923 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using UnityEngine;
  3. [ExecuteInEditMode]
  4. [RequireComponent(typeof(UIWidget))]
  5. [AddComponentMenu("NGUI/Examples/Set Color on Selection")]
  6. public class SetColorOnSelection : MonoBehaviour
  7. {
  8. public void SetSpriteBySelection()
  9. {
  10. if (UIPopupList.current == null)
  11. {
  12. return;
  13. }
  14. if (this.mWidget == null)
  15. {
  16. this.mWidget = base.GetComponent<UIWidget>();
  17. }
  18. string value = UIPopupList.current.value;
  19. switch (value)
  20. {
  21. case "White":
  22. this.mWidget.color = Color.white;
  23. break;
  24. case "Red":
  25. this.mWidget.color = Color.red;
  26. break;
  27. case "Green":
  28. this.mWidget.color = Color.green;
  29. break;
  30. case "Blue":
  31. this.mWidget.color = Color.blue;
  32. break;
  33. case "Yellow":
  34. this.mWidget.color = Color.yellow;
  35. break;
  36. case "Cyan":
  37. this.mWidget.color = Color.cyan;
  38. break;
  39. case "Magenta":
  40. this.mWidget.color = Color.magenta;
  41. break;
  42. }
  43. }
  44. private UIWidget mWidget;
  45. }