InheritColour.cs 943 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. namespace SRF.UI
  2. {
  3. using Internal;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. [RequireComponent(typeof (Graphic))]
  7. [ExecuteInEditMode]
  8. [AddComponentMenu(ComponentMenuPaths.InheritColour)]
  9. public class InheritColour : SRMonoBehaviour
  10. {
  11. private Graphic _graphic;
  12. public Graphic From;
  13. private Graphic Graphic
  14. {
  15. get
  16. {
  17. if (_graphic == null)
  18. {
  19. _graphic = GetComponent<Graphic>();
  20. }
  21. return _graphic;
  22. }
  23. }
  24. private void Refresh()
  25. {
  26. if (From == null)
  27. {
  28. return;
  29. }
  30. Graphic.color = From.canvasRenderer.GetColor();
  31. }
  32. private void Update()
  33. {
  34. Refresh();
  35. }
  36. private void Start()
  37. {
  38. Refresh();
  39. }
  40. }
  41. }