Created
September 30, 2018 23:13
-
-
Save nabesi777/2c197d4b49de6bda12c91c08231549a6 to your computer and use it in GitHub Desktop.
Unity デバッグ出力機能
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class DebugDisplayLog : MonoBehaviour | |
{ | |
static public List<string> displayLog = new List<string>(); | |
private void Start() | |
{ | |
this.oneSecondTime = 0f; | |
} | |
private void Update() | |
{ | |
//Transration | |
// FPS | |
if (this.oneSecondTime >= 1f) | |
{ | |
this.fps = this.fpsCounter; | |
this.fixedFps = this.fixedFpsCounter; | |
// reset | |
this.fpsCounter = 0; | |
this.fixedFpsCounter = 0; | |
this.oneSecondTime = 0f; | |
} | |
else | |
{ | |
this.fpsCounter++; | |
this.oneSecondTime += Time.deltaTime; | |
} | |
// structure debug string | |
this.debugString = ""; | |
int count = DebugDisplayLog.displayLog.Count; | |
for (int i = 0; i < DebugDisplayLog.displayLog.Count; i++) | |
{ | |
this.debugString += DebugDisplayLog.displayLog[i]; | |
this.debugString += "\n"; | |
} | |
DebugDisplayLog.displayLog.Clear(); | |
} | |
private void FixedUpdate() | |
{ | |
this.fixedFpsCounter++; | |
} | |
private void OnGUI() | |
{ | |
GUI.Label( | |
new Rect(0f, 0f, Screen.width, Screen.height), | |
"FPS: " + this.fps + " FixedUpdate: " + this.fixedFps + "\n" + this.debugString+ "Transform"+this.transform.position); | |
// Debug.Log("position: " + this.transform.position.ToString()); | |
} | |
// FPS | |
private int fps; | |
private int fpsCounter; | |
// Fixed FPS | |
private int fixedFps; | |
private int fixedFpsCounter; | |
// Debug Log | |
private string debugString; | |
// Timer | |
private float oneSecondTime; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment