以下核心代码主要针对模型点数、面数、渲染批次等设计,初始化调用一次,每次模型加载的时候调用即可。
string str = "";
private List<float> pri = new List<float>();
IEnumerator StartStars()
{
//为了获得比较准确的数据延迟0.5s
yield return new WaitForSeconds(0.5f);
var _list = new List<float>();
_list.Add(UnityStats.frameTime);
_list.Add(UnityStats.renderTime);
_list.Add(UnityStats.batches);
_list.Add(UnityStats.triangles);
_list.Add(UnityStats.vertices);
if (pri.Count == 0)
{
foreach (var idx in _list)
pri.Add(idx);
str += "(Win)渲染时间,(Win)FPS时间,渲染批次Batches,顶点数Tris,面数Verts\n";
}
else
{
for (var _i=0;_i< _list.Count;_i++)
{
var _f = _list[_i] - pri[_i];
_f = (int)(_f * 10) / 10f;//只保留小数点后1位
str += _f + ",";
}
str += "\n";
Debug.Log(str);
}
}
void SaveStats()
{
AssetDatabase.Refresh();
Directory.CreateDirectory("Assets/TablesOther");
using (StreamWriter writer = File.CreateText("Assets/TablesOther/表格.csv"))
writer.Write(str);
AssetDatabase.Refresh();
Debug.Log(gameObject.name + "转表完毕");
}
引用的类库为:
using UnityEditor;
using System.IO;