wangguan
2020-12-29 452c75675679c44cc39b04bdb7d330d7c5c14d5c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
 
namespace MoreMountains.NiceVibrations
{
    /// <summary>
    /// Add this component to any object and it'll set the target frame rate and vsync count. Note that vsync count must be 0 for the target FPS to work.
    /// </summary>
    public class MMFPSUnlock : MonoBehaviour
    {
        /// the target FPS you want the game to run at
        public int TargetFPS;
        [Range(0,2)]
        /// whether vsync should be enabled or not (on a 60Hz screen, 1 : 60fps, 2 : 30fps, 0 : don't wait for vsync)
        public int VSyncCount = 0;
 
        /// <summary>
        /// On start we change our target fps and vsync settings
        /// </summary>
        protected virtual void Start()
        {
            UpdateSettings();
        }    
        
        /// <summary>
        /// When a value gets changed in the editor, we update our settings
        /// </summary>
        protected virtual void OnValidate()
        {
            UpdateSettings();
        }
 
        /// <summary>
        /// Updates the target frame rate value and vsync count setting
        /// </summary>
        protected virtual void UpdateSettings()
        {
            QualitySettings.vSyncCount = VSyncCount;
            Application.targetFrameRate = TargetFPS;
        }
    }
}