Global FPS
This commit is contained in:
@@ -24,9 +24,7 @@ public class CustomGamePlayer : MonoBehaviour
|
||||
public GameObject pausePanel;
|
||||
public Rigidbody2D rb;
|
||||
public AudioSource backgroundMusic;
|
||||
public TMP_Text fpsCounter;
|
||||
private float nextUpdate;
|
||||
private float fps;
|
||||
public SpriteRenderer overlayRender;
|
||||
private float lastMoveTime;
|
||||
public GameObject berryParent;
|
||||
@@ -417,12 +415,6 @@ public class CustomGamePlayer : MonoBehaviour
|
||||
{
|
||||
audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
|
||||
}
|
||||
if (BazookaManager.Instance.GetSettingShowFPS() && Time.time > nextUpdate)
|
||||
{
|
||||
fps = 1f / Time.deltaTime;
|
||||
fpsCounter.text = "FPS: " + Mathf.Round(fps);
|
||||
nextUpdate = Time.time + 0.25f;
|
||||
}
|
||||
if (screenWidth != Camera.main.orthographicSize * 2f * Camera.main.aspect)
|
||||
{
|
||||
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
|
||||
@@ -37,9 +37,7 @@ public class GamePlayer : MonoBehaviour
|
||||
public GameObject pausePanel;
|
||||
public Rigidbody2D rb;
|
||||
public AudioSource backgroundMusic;
|
||||
public TMP_Text fpsCounter;
|
||||
private float nextUpdate;
|
||||
private float fps;
|
||||
public SpriteRenderer overlayRender;
|
||||
private float lastMoveTime;
|
||||
public GameObject berryParent;
|
||||
@@ -398,12 +396,6 @@ public class GamePlayer : MonoBehaviour
|
||||
{
|
||||
audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
|
||||
}
|
||||
if (BazookaManager.Instance.GetSettingShowFPS() && Time.time > nextUpdate)
|
||||
{
|
||||
fps = 1f / Time.deltaTime;
|
||||
fpsCounter.text = "FPS: " + Mathf.Round(fps);
|
||||
nextUpdate = Time.time + 0.25f;
|
||||
}
|
||||
if (screenWidth != Camera.main.orthographicSize * 2f * Camera.main.aspect)
|
||||
{
|
||||
screenWidth = Camera.main.orthographicSize * 2f * Camera.main.aspect;
|
||||
|
||||
36
Assets/Scripts/GlobalFPSText.cs
Normal file
36
Assets/Scripts/GlobalFPSText.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(TMP_Text))]
|
||||
public class GlobalFPSText : MonoBehaviour
|
||||
{
|
||||
private TMP_Text text;
|
||||
private float timer;
|
||||
private int frames;
|
||||
private float fps;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (FindObjectsByType<GlobalFPSText>(FindObjectsSortMode.None).Length > 1)
|
||||
{
|
||||
Destroy(gameObject.transform.parent.gameObject);
|
||||
return;
|
||||
}
|
||||
DontDestroyOnLoad(transform.parent.gameObject);
|
||||
text = GetComponent<TMP_Text>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!BazookaManager.Instance.GetSettingShowFPS() && text.text != "") text.text = "";
|
||||
frames++;
|
||||
timer += Time.unscaledDeltaTime;
|
||||
if (timer >= 0.25f)
|
||||
{
|
||||
fps = frames / timer;
|
||||
text.text = "FPS: " + Mathf.RoundToInt(fps);
|
||||
frames = 0;
|
||||
timer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/GlobalFPSText.cs.meta
Normal file
2
Assets/Scripts/GlobalFPSText.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 703a7c60af3394e688f2e2bdec342176
|
||||
Reference in New Issue
Block a user