perf(enemy): 感知系统 Inspector 限频重绘,修复选中敌人掉帧
PhysicsPerceptionSystemEditor.OnInspectorGUI 尾部每帧 Repaint(),选中敌人时强制整个多组件 Inspector(本编辑器逐槽位 IMGUI + 同物体其它自定义编辑器)以游戏帧率(100+fps)重绘,单帧多耗 ~18ms → 帧率从 140 掉到 40。 改为与 EnemyLocomotionEditor 同款:走 EditorApplication.update 定频(~5Hz)请求重绘,与游戏 帧率解耦,移除每帧 Repaint。感知 Gizmo 本就 NonSelected|Selected 都画(在基线内,非选中新增成本)。 实测(平均帧):选中开销从 ~18ms/帧 降到 ~4.3ms/帧(未选中~106fps / 选中~73fps,原为 140→40)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,10 +15,28 @@ namespace BaseGames.Editor
|
||||
private SerializedProperty _slotsProp;
|
||||
private readonly List<bool> _foldouts = new List<bool>();
|
||||
|
||||
// 运行时检测结果刷新限频:定频请求重绘(~5Hz),与游戏帧率解耦。
|
||||
// 否则 OnInspectorGUI 尾部每帧 Repaint 会强制整个多组件 Inspector 以游戏帧率(100+fps)
|
||||
// 重绘 IMGUI(本编辑器逐槽位属性 + 同物体其它自定义编辑器),选中敌人即掉帧。
|
||||
private const double RepaintInterval = 0.2;
|
||||
private double _nextRepaintTime;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_slotsProp = serializedObject.FindProperty("_slots");
|
||||
SyncFoldouts();
|
||||
EditorApplication.update += ThrottledRepaint;
|
||||
}
|
||||
|
||||
private void OnDisable() => EditorApplication.update -= ThrottledRepaint;
|
||||
|
||||
private void ThrottledRepaint()
|
||||
{
|
||||
if (!Application.isPlaying || target == null) return;
|
||||
double t = EditorApplication.timeSinceStartup;
|
||||
if (t < _nextRepaintTime) return;
|
||||
_nextRepaintTime = t + RepaintInterval;
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void SyncFoldouts()
|
||||
@@ -477,7 +495,7 @@ namespace BaseGames.Editor
|
||||
}
|
||||
EditorGUILayout.LabelField(kvp.Key, kvp.Value.Count > 0 ? sb.ToString() : "—");
|
||||
}
|
||||
Repaint();
|
||||
// 重绘由 ThrottledRepaint 定频驱动,这里不再每帧 Repaint(否则强制整个 Inspector 满帧重绘)。
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user