Advertisement
Guest User

VSync_Setting

a guest
Feb 17th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. using System;
  2. using Sirenix.OdinInspector;
  3. using UnityEngine;
  4.  
  5. namespace Managers
  6. {
  7. public class GraphicSettings : MonoBehaviour
  8. {
  9. #region Values
  10.  
  11. #endregion
  12.  
  13. #region MonoBehaviour Callbacks
  14.  
  15. private void Start()
  16. {
  17. SelectVSync();
  18. }
  19.  
  20. #endregion
  21.  
  22. #region Core
  23. #region VSync
  24. [InfoBox("SetVsync1 - Use ONLY when your game can maintain 60 fps. If not, use SetVsync0_60FPS or SetVsync0_120FPS, because your game will drop less frames then.\n" +
  25. "SetVsync2 - Use if you barely get 40 fps. It feels definitely better to have 30 consistent evenly spaced frames than 40 frames with varying delays between them.\n" +
  26. "SetVsync0_Default - Does whatever the platform does\n" +
  27. "SetVsync0_60FPS - Try this if you don't reach 60fps, it will look better than SetVsync1\n" +
  28. "SetVsync0_120FPS - Try this if you don't reach 60fps, it might look even better than SetVsync0_60FPS. It looks like less frames are dropped, i have no explanation, just try it yourself.\n" +
  29. "(Tested on Samsung phones, A3 2017, S6 edge+)\n")]
  30. [TabGroup("Values"), SerializeField] private VSyncMode vSync;
  31. private void SelectVSync()
  32. {
  33. switch (vSync)
  34. {
  35. case VSyncMode.VSync1:
  36. SetVsync1();
  37. break;
  38. case VSyncMode.VSync2:
  39. SetVsync2();
  40. break;
  41. case VSyncMode.VSync_Default:
  42. SetVsync0_Default();
  43. break;
  44. case VSyncMode.VSync0_60FPS:
  45. SetVsync0_60FPS();
  46. break;
  47. case VSyncMode.VSync0_120FPS:
  48. SetVsync0_120FPS();
  49. break;
  50. }
  51. }
  52. public void SetVsync1() { QualitySettings.vSyncCount = 1; Application.targetFrameRate = -1; }
  53. public void SetVsync2() { QualitySettings.vSyncCount = 2; Application.targetFrameRate = -1; }
  54. public void SetVsync0_Default() { QualitySettings.vSyncCount = 0; Application.targetFrameRate = -1; }
  55. public void SetVsync0_60FPS() { QualitySettings.vSyncCount = 0; Application.targetFrameRate = 60; }
  56. public void SetVsync0_120FPS() { QualitySettings.vSyncCount = 0; Application.targetFrameRate = 120; }
  57. public enum VSyncMode
  58. {
  59. VSync1,
  60. VSync2,
  61. VSync_Default,
  62. VSync0_60FPS,
  63. VSync0_120FPS
  64.  
  65. }
  66. #endregion
  67.  
  68. #endregion
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement