unity3d:动态寻路NavMesh(NavMeshComponents不需要烘焙场景,实时烘焙)

静态烘焙:
动态障碍物,大小要和包围盒大小一致
unity3d:动态寻路NavMesh(NavMeshComponents不需要烘焙场景,实时烘焙)_第1张图片

动态烘焙:
官方最新的 https://github.com/luoyikun/NavMeshComponents
1.可以实现烘焙信息跟随预制体
unity3d:动态寻路NavMesh(NavMeshComponents不需要烘焙场景,实时烘焙)_第2张图片
2.动态烘焙:以玩家为中心,走哪烘哪
管理器上挂载
unity3d:动态寻路NavMesh(NavMeshComponents不需要烘焙场景,实时烘焙)_第3张图片
tracked为玩家

动态烘焙中的障碍物
unity3d:动态寻路NavMesh(NavMeshComponents不需要烘焙场景,实时烘焙)_第4张图片
要挂载在mesh上

[MenuItem("HomeTool/AddNavTag")]
    public static void AddNavTag()
    {
        GameObject obj = Selection.activeGameObject;
        foreach (var item in obj.transform.GetComponentsInChildren())
        {
            if (item.GetComponent() == null)
            {
                item.gameObject.AddComponent();
            }
        }
    }

显示寻路路径在scene视图中

    void OnDrawGizmos()
    {
        var path = m_agent.path;
        // color depends on status
        Color c = Color.white;
        switch (path.status)
        {
            case UnityEngine.AI.NavMeshPathStatus.PathComplete: c = Color.white; break;
            case UnityEngine.AI.NavMeshPathStatus.PathInvalid: c = Color.red; break;
            case UnityEngine.AI.NavMeshPathStatus.PathPartial: c = Color.yellow; break;
        }
        // draw the path
        for (int i = 1; i < path.corners.Length; ++i)
            Debug.DrawLine(path.corners[i - 1], path.corners[i], c);
    }

你可能感兴趣的:(Unity3D实用技术笔记)