ÇÁ·¹ÀÓ·¹ÀÌÆ®¸¦ ÆÄÀÏ·Î ÀúÀåÇØ º¸ÀÚ. NumberString¿¡ ½Ã°£À» ÀúÀåÈÄ¿¡ SaveStringÀ¸ ÆÄÀÏÀ» ÀúÀåÇÑ´Ù. NumberString Ŭ·¡½º´Â GetString( )¿¡ ÀÇÇØ ¹®ÀÚ¿·Î ³Ñ°ÜÁØ´Ù. SaveStringÀº ¹®ÀÚ¿À» ÆÄÀÏ·Î ÀúÀåÇÑ´Ù. NumberString<float> downloadNumStr = new NumberString<float>();
downloadNumStr.Add (Time.deltaTime); SaveString.Save(downloadNumStr.GetString(), "fps.txt"); NumberString.cs ¼Ò½º using UnityEngine;
using System.Collections; using System.Collections.Generic; using System.Text; public class NumberString<T> { List<T> list = new List<T>(); public void Reset() { list.Clear (); } public void Add(T data) { list.Add (data); } public string GetString() { StringBuilder sb = new StringBuilder(); for (int n = 0; n < list.Count; ++n) { //sb.Append(list[n]).Append("\r\n"); sb.Append(list[n]).AppendLine(); } return sb.ToString(); } } SaveString.cs ¼Ò½º using UnityEngine; using System.Collections; using System.IO; public class SaveString { public static void Save( string str, string filename ) { string path = GetDocumentPath( filename ); FileStream file = new FileStream (path, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter( file ); sw.WriteLine( str ); sw.Close(); file.Close(); } public static string Load( string filename) { string path = GetDocumentPath( filename ); if (File.Exists(path)) { FileStream file = new FileStream (path, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader( file ); string str = null; str = sr.ReadLine (); sr.Close(); file.Close(); return str; } else { return null; } } public static string GetDocumentPath( string filename ) { if (Application.platform == RuntimePlatform.IPhonePlayer) { string dataPath = Application.dataPath; string path = dataPath.Substring( 0, dataPath.Length - 5 ); path = path.Substring( 0, path.LastIndexOf( '/' ) ); return Path.Combine( Path.Combine( path, "Documents" ), filename ); } else if(Application.platform == RuntimePlatform.Android) { string path = Application.persistentDataPath; path = path.Substring(0, path.LastIndexOf( '/' ) ); return Path.Combine (path, filename); } else { string path = Application.dataPath; path = path.Substring(0, path.LastIndexOf( '/' ) ); return Path.Combine (path, filename); } } } TextFPSCounter.cs ¼Ò½º (Peter Koch´Ô°Í) using UnityEngine;
using UnityEngine.UI; // Display FPS on a Unity UGUI Text Panel // To use: Drag onto a game object with Text component // Press 'F' key to toggle show/hide public class TextFPSCounter : MonoBehaviour { public Text text; public bool show; private const int targetFPS = #if UNITY_ANDROID // GEARVR 60; #else 75; #endif private const float updateInterval = 0.5f; private int framesCount; private float framesTime; void Start() { //only test #if false QualitySettings.vSyncCount = 0; #if UNITY_EDITOR Application.targetFrameRate = 1000; #endif #endif // no text object set? see if our gameobject has one to use if (text == null) { text = GetComponent<Text>(); } } void Update() { if (Input.GetKeyDown(KeyCode.F)) { show = !show; } // monitoring frame counter and the total time framesCount++; framesTime += Time.unscaledDeltaTime; // measuring interval ended, so calculate FPS and display on Text if (framesTime > updateInterval) { if (text != null) { if (show) { float fps = framesCount/framesTime; text.text = System.String.Format("{0:F2} FPS", fps); text.color = (fps > (targetFPS-5) ? Color.green : (fps > (targetFPS-30) ? Color.yellow : Color.red)); } else { text.text = ""; } } // reset for the next interval to measure framesCount = 0; framesTime = 0; } } } ¼Ò½º) NumberString.cs SaveString.cs TextFPSCounter.cs ÂüÁ¶) http://blueasa.tistory.com/937 TextFPSAccounter.cs ¼Ò½º Æß http://talesfromtherift.com/vr-fps-counter/ |