ApplyToTextureWidgetNGUI.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using UnityEngine;
  3. namespace RenderHeads.Media.AVProVideo
  4. {
  5. [AddComponentMenu("AVPro Video/Display NGUI")]
  6. public class ApplyToTextureWidgetNGUI : MonoBehaviour
  7. {
  8. private void Update()
  9. {
  10. if (this._mediaPlayer != null)
  11. {
  12. if (this._mediaPlayer.TextureProducer != null)
  13. {
  14. Texture texture = this._mediaPlayer.TextureProducer.GetTexture(0);
  15. if (texture != null)
  16. {
  17. if (this._mediaPlayer.TextureProducer.RequiresVerticalFlip())
  18. {
  19. this._uiTexture.flip = UIBasicSprite.Flip.Vertically;
  20. }
  21. this._uiTexture.mainTexture = texture;
  22. }
  23. }
  24. }
  25. else
  26. {
  27. this._uiTexture.mainTexture = this._defaultTexture;
  28. }
  29. if (this._makePixelPerfect)
  30. {
  31. this._uiTexture.MakePixelPerfect();
  32. }
  33. }
  34. public void OnDisable()
  35. {
  36. }
  37. private void OnDestroy()
  38. {
  39. this._uiTexture.mainTexture = this._defaultTexture;
  40. }
  41. public UITexture _uiTexture;
  42. public MediaPlayer _mediaPlayer;
  43. public Texture2D _defaultTexture;
  44. [SerializeField]
  45. private bool _makePixelPerfect;
  46. }
  47. }