From 854bcb3d6f80421cd7e08586decf1d9c783d8eeb Mon Sep 17 00:00:00 2001 From: Joywayer Date: Thu, 23 Jul 2026 15:24:22 +0800 Subject: [PATCH] =?UTF-8?q?perf(enemy):=20=E6=84=9F=E7=9F=A5=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=20Inspector=20=E9=99=90=E9=A2=91=E9=87=8D=E7=BB=98,?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=89=E4=B8=AD=E6=95=8C=E4=BA=BA=E6=8E=89?= =?UTF-8?q?=E5=B8=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../Enemies/PhysicsPerceptionSystemEditor.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Assets/_Game/Scripts/Editor/Enemies/PhysicsPerceptionSystemEditor.cs b/Assets/_Game/Scripts/Editor/Enemies/PhysicsPerceptionSystemEditor.cs index f92fad8f..c13bf005 100644 --- a/Assets/_Game/Scripts/Editor/Enemies/PhysicsPerceptionSystemEditor.cs +++ b/Assets/_Game/Scripts/Editor/Enemies/PhysicsPerceptionSystemEditor.cs @@ -15,10 +15,28 @@ namespace BaseGames.Editor private SerializedProperty _slotsProp; private readonly List _foldouts = new List(); + // 运行时检测结果刷新限频:定频请求重绘(~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 满帧重绘)。 } ///