UnityGame/Library/PackageCache/com.unity.ai.navigation/Editor/Updater/NavMeshSceneConverter.cs

50 lines
1.7 KiB
C#
Raw Normal View History

2024-10-27 10:53:47 +03:00
using System;
using System.Collections.Generic;
using System.IO;
using Unity.AI.Navigation.Editor.Converter;
using UnityEditor;
namespace Unity.AI.Navigation.Updater
{
internal class NavMeshSceneConverter : SystemConverter
{
public override string name => "NavMesh Scene Converter";
public override string info => "Reassigns the legacy baked NavMesh to a NavMeshSurface on a game object named 'Navigation'.\nAdds a NavMeshModifier component to each game object marked as Navigation Static.";
public override Type container => typeof(BuiltInToNavMeshSurfaceConverterContainer);
List<string> m_AssetsToConvert = new List<string>();
public override void OnInitialize(InitializeConverterContext context, Action callback)
{
string[] allAssetPaths = AssetDatabase.GetAllAssetPaths();
foreach (string path in allAssetPaths)
{
if (NavMeshUpdaterUtility.IsSceneReferencingLegacyNavMesh(path))
{
ConverterItemDescriptor desc = new ConverterItemDescriptor()
{
name = Path.GetFileNameWithoutExtension(path),
info = path,
warningMessage = String.Empty,
helpLink = String.Empty
};
m_AssetsToConvert.Add(path);
context.AddAssetToConvert(desc);
}
}
callback.Invoke();
}
public override void OnRun(ref RunItemContext context)
{
bool success = NavMeshUpdaterUtility.ConvertScene(context.item.descriptor.info);
context.hasConverted = success;
}
}
}