AppCoreControl.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. This script controls the base functionality for the program.
  3. Email :: thomas.ir.rasor@gmail.com
  4. */
  5. using UnityEngine;
  6. public class AppCoreControl : MonoBehaviour
  7. {
  8. public int frameRateLimit = 90;
  9. public bool showFps = false;
  10. public bool enableVsync = false;
  11. public int maxQueuedFrames = 2;
  12. public bool pauseOnFocusLoss = false;
  13. public enum AASetting { None , x2 , x4 , x8 }
  14. public AASetting antialiasing = AASetting.x4;
  15. [ContextMenu("Update Settings Now")]
  16. void Start ()
  17. {
  18. Application.runInBackground = !pauseOnFocusLoss;
  19. Application.targetFrameRate = frameRateLimit;
  20. if ( enableVsync )
  21. QualitySettings.vSyncCount = 1;
  22. else
  23. QualitySettings.vSyncCount = 0;
  24. QualitySettings.maxQueuedFrames = maxQueuedFrames;
  25. QualitySettings.antiAliasing = (int)antialiasing;
  26. }
  27. void Update ()
  28. {
  29. if (Input.GetKeyDown (KeyCode.Escape))
  30. Application.Quit ();
  31. }
  32. void OnGUI ()
  33. {
  34. if ( !showFps ) return;
  35. GUILayout.BeginArea( new Rect( 0f , 0f , Screen.width , Screen.height ) );
  36. GUILayout.Label( "~" + Mathf.RoundToInt( 1f / Time.smoothDeltaTime ) + " fps" );
  37. GUILayout.EndArea();
  38. }
  39. }