Когда я пытаюсь очистить/удалить Navmesh через скрипт, я получаю это предупреждение:
не может удалить активы. не является действительным путем.
unity.ai.navigation.editor.navmeshassetmanager:updateasyncbuildoperations () (at ./Library/packagecache/com.unity.ai.navigation@eb5635ad590d/editor/navmeshassetmanager.cs:158)
unityEditor.editorapplication:Internal_callupdatefunction ()
evitor script i exected the stective the stermited the stermited the stermited the stertied NAVMESH. < /p>
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(MazeGenerator))]
public class MazeGeneratorEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
MazeGenerator mazeGen = (MazeGenerator)target;
if (GUILayout.Button("Generate New Maze"))
{
mazeGen.GenerateAndBuildMaze();
// Mark the scene dirty for editor persistence
if (!Application.isPlaying)
{
EditorUtility.SetDirty(mazeGen);
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(mazeGen.gameObject.scene);
}
}
if (GUILayout.Button("Clear Maze"))
{
mazeGen.ClearMaze();
if (!Application.isPlaying)
{
EditorUtility.SetDirty(mazeGen);
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(mazeGen.gameObject.scene);
}
}
}
}
< /code>
, а затем в моно -скрипте я строю лабиринт и выпекаю поверхность Navmesh, а затем добавил метод Clearmaze, который также удаляет Navmesh: < /p>
using UnityEngine;
using Unity.AI.Navigation;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
[ExecuteAlways]
public class MazeGenerator : MonoBehaviour
{
[Header("Maze Size")]
public int width = 30;
public int height = 30;
[Header("Prefabs")]
public GameObject wallPrefab;
public GameObject floorPrefab;
public GameObject entranceMarkerPrefab;
public GameObject exitMarkerPrefab;
public GameObject deadEndMarkerPrefab;
[Header("Options")]
public bool generateEntranceAndExit = true;
public bool markDeadEnds = true;
private bool[,] maze;
private int[] directions = { 0, 1, 2, 3 };
private NavMeshSurface navMeshSurface;
private Vector2Int entrancePos;
private Vector2Int exitPos;
private void Awake()
{
navMeshSurface = GetComponent();
}
public void GenerateAndBuildMaze()
{
#if UNITY_EDITOR
// Record undo for editor
Undo.RegisterFullObjectHierarchyUndo(gameObject, "Generate Maze");
#endif
ClearMaze();
ValidateMazeDimensions();
GenerateMaze();
BuildMaze();
if (navMeshSurface != null)
navMeshSurface.BuildNavMesh();
}
public void ClearMaze()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
if (navMeshSurface != null)
{
// Only try to remove if data exists
if (navMeshSurface.navMeshData != null)
navMeshSurface.RemoveData();
}
List toDestroy = new List();
foreach (Transform child in transform)
toDestroy.Add(child.gameObject);
foreach (GameObject go in toDestroy)
Object.DestroyImmediate(go);
return;
}
#endif
// Runtime: normal removal
if (navMeshSurface != null && navMeshSurface.navMeshData != null)
navMeshSurface.RemoveData();
foreach (Transform child in transform)
Destroy(child.gameObject);
}
< /code>
Скриншот предупреждения: < /p>
Подробнее здесь: https://stackoverflow.com/questions/797 ... -a-navmesh