Project_WL/AgentScripts/WL785_Budget.cs

60 lines
2.8 KiB
C#

// WL785_Budget.cs — #785 리본/스파크의 모바일 예산 증분 실측 (Play 전용 · 읽기 전용 토글)
// unity command run_script --file AgentScripts/WL785_Budget.cs --entry WL785_Budget.AB --args '[3.0]'
// 같은 전투를 리본 ON / OFF 로 각각 n 초 돌려 UnityStats 최대·평균을 비교한다.
// drawRibbon 만 메모리에서 토글하고 끝나면 반드시 원래 값으로 되돌린다.
using System.Collections;
using System.Linq;
using System.Text;
using UnityEngine;
public static class WL785_Budget
{
public static object AB(float seconds)
{
if (!Application.isPlaying) return "not playing";
if (GameObject.Find("__wl785budget") != null) return "already running";
var go = new GameObject("__wl785budget").AddComponent<H>();
go.StartCoroutine(go.Co(seconds));
return "started " + seconds + "s x2";
}
public static string Result = "(not run)";
class H : MonoBehaviour
{
public IEnumerator Co(float sec)
{
var s = WL.Combat.SlashTrailSettings.Instance;
bool orig = s != null && s.drawRibbon;
var sb = new StringBuilder();
for (int pass = 0; pass < 2; pass++)
{
bool on = pass == 0;
if (s != null) s.drawRibbon = on;
yield return new WaitForSeconds(0.3f); // 안정화
int mSet = 0, mBat = 0, mDraw = 0, mTri = 0, n = 0;
long aSet = 0, aBat = 0, aDraw = 0, aTri = 0;
float t0 = Time.time;
while (Time.time - t0 < sec)
{
yield return new WaitForEndOfFrame();
int sp = UnityEditor.UnityStats.setPassCalls, b = UnityEditor.UnityStats.batches;
int d = UnityEditor.UnityStats.drawCalls, tr = UnityEditor.UnityStats.triangles;
mSet = Mathf.Max(mSet, sp); mBat = Mathf.Max(mBat, b);
mDraw = Mathf.Max(mDraw, d); mTri = Mathf.Max(mTri, tr);
aSet += sp; aBat += b; aDraw += d; aTri += tr; n++;
yield return null;
}
sb.AppendLine((on ? "리본 ON " : "리본 OFF") +
" max setPass=" + mSet + " batches=" + mBat + " draw=" + mDraw + " tris=" + mTri +
" | avg setPass=" + (n > 0 ? aSet / n : 0) + " batches=" + (n > 0 ? aBat / n : 0) +
" draw=" + (n > 0 ? aDraw / n : 0) + " tris=" + (n > 0 ? aTri / n : 0) + " frames=" + n);
}
if (s != null) s.drawRibbon = orig;
sb.AppendLine("drawRibbon 원복 = " + (s != null ? s.drawRibbon.ToString() : "?"));
Result = sb.ToString();
Debug.Log("[WL785 예산]\n" + Result);
Destroy(gameObject);
}
}
}