fork download
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [ExecuteInEditMode]
  5. public class RatioFix : MonoBehaviour
  6. {
  7.  
  8. Resolution[] resolutions;
  9.  
  10. void Awake()
  11. {
  12. //StartCoroutine("Do");
  13. Do();
  14. }
  15.  
  16. void Do()
  17. {
  18. //yield return new WaitForFixedUpdate();
  19.  
  20. resolutions = Screen.resolutions;
  21.  
  22. float targetaspect = 16.0f / 9.0f;
  23. float windowaspect = (float) resolutions[resolutions.Length - 1].width / (float)resolutions[resolutions.Length - 1].height;
  24. //float windowaspect = Screen.width / Screen.height;
  25. float scaleheight = windowaspect / targetaspect;
  26.  
  27. Camera[] camArray = FindObjectsOfType(typeof(Camera)) as Camera[];
  28.  
  29. foreach (Camera camera in camArray)
  30. {
  31. if (camera.gameObject.layer != 10 && camera.gameObject.layer != 13)
  32. {
  33.  
  34. if (scaleheight < 1.0f)
  35. {
  36. Rect rect = camera.rect;
  37. rect.width = 1.0f;
  38. rect.height = scaleheight;
  39. rect.x = 0;
  40. rect.y = (1.0f - scaleheight) / 2.0f;
  41. camera.rect = rect;
  42. }
  43.  
  44. else
  45. {
  46. float scalewidth = 1.0f / scaleheight;
  47. Rect rect = camera.rect;
  48. rect.width = scalewidth;
  49. rect.height = 1.0f;
  50. rect.x = (1.0f - scalewidth) / 2.0f;
  51. rect.y = 0;
  52. camera.rect = rect;
  53. }
  54. }
  55. }
  56. }
  57. }
  58.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(1,7): error CS0246: The type or namespace name `UnityEngine' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(8,5): error CS0246: The type or namespace name `Resolution' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty