资源简介

用于生成和启用一个代理类型的NavMesh表面的NavMeshSurface。 NavMeshModifier - 基于转换层次结构影响NavMesh区域类型的NavMesh生成。 NavMeshModifierVolume - 影响基于卷的NavMesh区域类型的NavMesh生成。 NavMeshLink - 为一个代理类型连接相同或者不同的NavMesh曲面。

资源截图

代码片段和文件信息

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.AI;
using NavMeshBuilder = UnityEngine.AI.NavMeshBuilder;

[CanEditMultipleobjects]
[CustomEditor(typeof(NavMeshPrefabInstance))]
class NavMeshPrefabInstanceEditor : Editor
{
    SerializedProperty m_FollowTransformProp;
    SerializedProperty m_NavMeshDataProp;

    public void OnEnable()
    {
        m_FollowTransformProp = serializedobject.FindProperty(“m_FollowTransform“);
        m_NavMeshDataProp = serializedobject.FindProperty(“m_NavMesh“);
    }

    public override void OnInspectorGUI()
    {
        var instance = (NavMeshPrefabInstance)target;
        var go = instance.gameobject;

        serializedobject.Update();

        GUI.enabled = false;
        EditorGUILayout.PropertyField(m_NavMeshDataProp);
        GUI.enabled = true;
        EditorGUILayout.PropertyField(m_FollowTransformProp);

        EditorGUILayout.Space();

        OnInspectorGUIPrefab(go);

        serializedobject.ApplyModifiedProperties();
    }

    void OnInspectorGUIPrefab(Gameobject go)
    {
        var prefab = PrefabUtility.GetPrefabobject(go);
        var path = AssetDatabase.GetAssetPath(prefab);

        if (prefab && string.IsNullOrEmpty(path))
        {
            if (GUILayout.Button(“Select the Prefab asset to bake or clear the navmesh“ Editorstyles.helpBox))
            {
                Selection.activeobject = PrefabUtility.GetPrefabParent(go);
                EditorGUIUtility.Pingobject(Selection.activeobject);
            }
        }

        if (string.IsNullOrEmpty(path))
            return;

        GUILayout.BeginHorizontal();
        GUILayout.Space(EditorGUIUtility.labelWidth);

        if (GUILayout.Button(“Clear“))
            OnClear();

        if (GUILayout.Button(“Bake“))
            OnBake();

        GUILayout.EndHorizontal();
    }

    NavMeshData Build(NavMeshPrefabInstance instance)
    {
        var root = instance.transform;
        var sources = new List();
        var markups = new List();

        NavMeshBuilder.CollectSources(root ~0 NavMeshCollectGeometry.RenderMeshes 0 markups sources);
        var settings = NavMesh.GetSettingsByID(0);
        var bounds = new Bounds(Vector3.zero 1000.0f * Vector3.one);
        var navmesh = NavMeshBuilder.BuildNavMeshData(settings sources bounds root.position root.rotation);
        navmesh.name = “Navmesh“;
        return navmesh;
    }

    void OnClear()
    {
        foreach (var tgt in targets)
        {
            var instance = (NavMeshPrefabInstance)tgt;
            var go = instance.gameobject;
            var prefab = PrefabUtility.GetPrefabobject(go);
            var path = AssetDatabase.GetAssetPath(prefab);

            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError(“Gameobject: “ + go + “ has no valid prefab path“);
                continue;
            }

            DestroyNavMeshData(path);
       

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\
     文件         120  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\.gitignore
     目录           0  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\
     文件         191  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples.meta
     目录           0  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\
     文件        3497  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Cube.prefab
     文件         179  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Cube.prefab.meta
     文件         191  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Editor.meta
     目录           0  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Editor\
     文件        4425  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Editor\NavMeshPrefabInstanceEditor.cs
     文件         262  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Editor\NavMeshPrefabInstanceEditor.cs.meta
     文件         191  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials.meta
     目录           0  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\
     文件        2867  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\brightgreen.mat
     文件         179  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\brightgreen.mat.meta
     文件        2867  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\brown.mat
     文件         179  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\brown.mat.meta
     文件        3947  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\crosshair.mat
     文件         179  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\crosshair.mat.meta
     文件        2865  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\floor.mat
     文件         179  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\floor.mat.meta
     文件        2867  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\green.mat
     文件         179  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\green.mat.meta
     文件        2863  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\grey.mat
     文件         179  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\grey.mat.meta
     文件        1036  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\modify_crosshair.png
     文件        1184  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\modify_crosshair.png.meta
     文件        2863  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\red.mat
     文件         179  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\red.mat.meta
     文件        2849  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\yellow.mat
     文件         179  2018-01-02 12:11  NavMeshComponents-2017.2.0f1\Assets\Examples\Materials\yellow.mat.meta
............此处省略193个文件信息

评论

共有 条评论