如果项目使用了 AI/导航网格 (NavMesh) 功能,在将项目从 Unity 4 升级到 Unity 5 时需要注意以下注意事项。
由于更改了分区,导航网格轮廓可能看起来不同(在狭窄的走廊/门道或类似情况下),这可能导致连接差异。通过调整导航网格构建的体素大小可解决此问题。
在调用“Stop”后设置导航网格代理 (NavMeshAgent) 的目标不会恢复代理 - 应显式调用“Resume”来恢复代理。
NavMeshAgent.updatePosition:当 updatePosition 为 false 并移动代理变换组件时,代理位置不会更改。以前,代理位置将重置为变换位置 - 约束到附近的导航网格。
NavMeshObstacle 组件:新创建的 NavMeshObstacle 组件的默认形状是一个盒体。选择的形状(盒体或胶囊体)现在适用于雕刻和避障。
不支持使用早期版本的 Unity 构建的导航网格。必须使用 Unity 5 重新构建。可使用以下脚本作为示例,了解如何为所有场景重新构建导航网格数据。
# if UNITY_EDITOR
using System.Collections.Generic;
using System.Collections;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.AI;
public class RebakeAllScenesEditorScript
{
[MenuItem ("Upgrade helper/Bake All Scenes")]
public static void Bake()
{
List<string> sceneNames = SearchFiles (Application.dataPath, "*.unity");
foreach (string f in sceneNames)
{
EditorApplication.OpenScene(f);
// 重新烘焙导航网格数据
NavMeshBuilder.BuildNavMesh ();
EditorApplication.SaveScene ();
}
}
static List<string> SearchFiles(string dir, string pattern)
{
List <string> sceneNames = new List <string>();
foreach (string f in Directory.GetFiles(dir, pattern, SearchOption.AllDirectories))
{
sceneNames.Add (f);
}
return sceneNames;
}
}
# endif
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.