修复编译错误

This commit is contained in:
2026-05-12 21:50:49 +08:00
parent 2b2a74da42
commit 458f344e83
28 changed files with 122 additions and 54 deletions

View File

@@ -1,3 +1,4 @@
using System.Reflection;
using UnityEditor;
using UnityEngine;
using PathBerserker2d;
@@ -11,6 +12,12 @@ namespace BaseGames.Editor
/// </summary>
public static class NavSurfaceBakeShortcut
{
// NavSurface.StartBakeJob() 和 NavSurface.BakeJob 均为 internal通过反射访问。
private static readonly MethodInfo s_startBakeJobMethod =
typeof(NavSurface).GetMethod("StartBakeJob", BindingFlags.NonPublic | BindingFlags.Instance);
private static readonly PropertyInfo s_bakeJobProp =
typeof(NavSurface).GetProperty("BakeJob", BindingFlags.NonPublic | BindingFlags.Instance);
[MenuItem("BaseGames/Tools/Bake All NavSurfaces %#b", priority = 100)]
public static void BakeAll()
{
@@ -26,7 +33,7 @@ namespace BaseGames.Editor
{
if (surface == null) continue;
surface.StartBakeJob();
s_startBakeJobMethod?.Invoke(surface, null);
EditorApplication.update -= MakeWatcher(surface);
EditorApplication.update += MakeWatcher(surface);
count++;
@@ -49,16 +56,28 @@ namespace BaseGames.Editor
EditorApplication.CallbackFunction watcher = null;
watcher = () =>
{
if (surface == null || surface.BakeJob == null)
if (surface == null)
{
EditorApplication.update -= watcher;
return;
}
if (surface.BakeJob.IsFinished)
var bakeJob = s_bakeJobProp?.GetValue(surface);
if (bakeJob == null)
{
EditorApplication.update -= watcher;
return;
}
bool isFinished = (bool)bakeJob.GetType()
.GetProperty("IsFinished")!.GetValue(bakeJob);
if (isFinished)
{
EditorApplication.update -= watcher;
EditorUtility.SetDirty(surface);
Debug.Log($"[NavSurfaceBake] ✓ {surface.name} 烘焙完成({surface.BakeJob.TotalBakeTime} ms");
float totalTime = (float)bakeJob.GetType()
.GetProperty("TotalBakeTime")!.GetValue(bakeJob);
Debug.Log($"[NavSurfaceBake] ✓ {surface.name} 烘焙完成({totalTime} ms");
}
};
return watcher;