InheritColour.cs 749 B

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