ReduceResolutionAndBlend.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using UnityEngine;
  3. public class ReduceResolutionAndBlend : MonoBehaviour
  4. {
  5. public Camera Camera
  6. {
  7. get
  8. {
  9. return R.Camera.Camera;
  10. }
  11. }
  12. public static void Init()
  13. {
  14. ReduceResolutionAndBlend.Instance = R.Camera.GameObject.AddComponent<ReduceResolutionAndBlend>();
  15. ReduceResolutionAndBlend.Instance.SetResolution(960, 540);
  16. }
  17. public void SetResolution(Resolution resolution)
  18. {
  19. if (this.GamePlayRenderTexture != null)
  20. {
  21. this.GamePlayRenderTexture.Release();
  22. }
  23. RenderTexture renderTexture = new RenderTexture(resolution.width, resolution.height, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Linear)
  24. {
  25. filterMode = FilterMode.Bilinear
  26. };
  27. this.Camera.targetTexture = renderTexture;
  28. this.GamePlayRenderTexture = renderTexture;
  29. }
  30. public void SetResolution(int width, int height)
  31. {
  32. this.SetResolution(new Resolution
  33. {
  34. height = height,
  35. width = width
  36. });
  37. }
  38. private void OnEnable()
  39. {
  40. if (this.GamePlayRenderTexture != null)
  41. {
  42. this.Camera.targetTexture = this.GamePlayRenderTexture;
  43. }
  44. }
  45. private void OnDisable()
  46. {
  47. this.Camera.targetTexture = null;
  48. }
  49. public RenderTexture GamePlayRenderTexture;
  50. public static ReduceResolutionAndBlend Instance;
  51. }