FadeInAndFadeOutOnGUI.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using UnityEngine;
  3. public class FadeInAndFadeOutOnGUI : MonoBehaviour
  4. {
  5. public void Awake()
  6. {
  7. if (this.tex_ == null)
  8. {
  9. this.tex_ = new Texture2D(32, 32, TextureFormat.ARGB32, false);
  10. for (int i = 0; i < 32; i++)
  11. {
  12. for (int j = 0; j < 32; j++)
  13. {
  14. this.tex_.SetPixel(i, j, Color.white);
  15. }
  16. }
  17. this.tex_.Apply();
  18. }
  19. this.Update();
  20. }
  21. public void OnDestroy()
  22. {
  23. if (this.tex_ != null)
  24. {
  25. UnityEngine.Object.DestroyImmediate(this.tex_);
  26. }
  27. }
  28. public void Update()
  29. {
  30. }
  31. public void OnGUI()
  32. {
  33. if (this.tex_ != null && this.intensity < 1f)
  34. {
  35. Color color = GUI.color;
  36. GUI.color = new Color(this.color.r, this.color.g, this.color.b, 1f - this.intensity);
  37. GUI.DrawTexture(this.render_rect_, this.tex_);
  38. GUI.color = color;
  39. }
  40. }
  41. public bool UpdateRenderRect()
  42. {
  43. if (this.window_size_.x != (float)Screen.width || this.window_size_.y != (float)Screen.height)
  44. {
  45. this.window_size_.x = (float)Screen.width;
  46. this.window_size_.y = (float)Screen.height;
  47. return true;
  48. }
  49. return false;
  50. }
  51. public float intensity = 1f;
  52. public Color color = Color.black;
  53. private Texture2D tex_;
  54. private Rect render_rect_ = new Rect(0f, 0f, 8192f, 8192f);
  55. private Vector2 window_size_ = Vector2.zero;
  56. }