Exemple #1
0
        public void BuildNavMesh()
        {
            Awake();

            // remove existing navMeshSurfaces
            foreach (NavMeshSurface navMeshSurface in navMeshRoot.GetComponents <NavMeshSurface>())
            {
                Destroy(navMeshSurface);
            }

            int agentTypeCount = UnityEngine.AI.NavMesh.GetSettingsCount();

            if (agentTypeCount < 1)
            {
                return;
            }
            for (int i = 0; i < agentTypeCount; ++i)
            {
                NavMeshBuildSettings settings       = UnityEngine.AI.NavMesh.GetSettingsByIndex(i);
                NavMeshSurface       navMeshSurface = navMeshRoot.AddComponent <NavMeshSurface>();
                navMeshSurface.agentTypeID = settings.agentTypeID;

                NavMeshBuildSettings actualSettings = navMeshSurface.GetBuildSettings();
                navMeshSurface.useGeometry = NavMeshCollectGeometry.RenderMeshes; // or you can use RenderMeshes
                //navMeshSurface.layerMask = true;

                // remove existing agents from the navmesh layermask
                navMeshSurface.layerMask -= LayerMask.GetMask("Agents");
                navMeshSurface.layerMask -= LayerMask.GetMask("Ignore Raycast");

                navMeshSurface.BuildNavMesh();
            }

            this.navMeshInitialized = true;
        }
Exemple #2
0
    // Use this for initialization
    void Start()
    {
        // add 20 random big cuboids into the level.
        // The prefab has been tagged as StaticBatchingUtility Navigation in The Navigation editor
        for (int i = 0; i < 20; i++)
        {
            GameObject go = Instantiate(prefab, new Vector3(Random.Range(-25, 25), Random.Range(0, 1), Random.Range(-25, 25)), Quaternion.AngleAxis(Random.Range(-180, 180), Vector3.up));
            go.transform.parent = transform;
        }

        // Use the standard settings from the editor (I think)
        NavMeshBuildSettings settings = NavMesh.GetSettingsByID(0);

        // gather all the physics colliders which are children of this transform (or you can do this by volume)
        List <NavMeshBuildSource> results = new List <NavMeshBuildSource>();

        NavMeshBuilder.CollectSources(transform, 255, NavMeshCollectGeometry.PhysicsColliders, 0, new List <NavMeshBuildMarkup>(), results);

        // make a 100m box around the origin
        Bounds bounds = new Bounds(Vector3.zero, 100 * Vector3.one);

        // Build the actual navmesh
        NavMeshData data = NavMeshBuilder.BuildNavMeshData(settings, results, bounds, Vector3.zero, Quaternion.identity);

        NavMesh.AddNavMeshData(data);
        success = NavMeshBuilder.UpdateNavMeshData(data, settings, results, bounds);
    }
Exemple #3
0
    public void UpdateNavMeshAsync()
    {
        if (this.HasBuildOperationStarted)
        {
            return;
        }
        if (AiManager.nav_disable || !AI.npc_enable)
        {
            return;
        }
        float single = UnityEngine.Time.realtimeSinceStartup;

        UnityEngine.Debug.Log(string.Concat("Starting Monument Navmesh Build with ", this.sources.Count, " sources"));
        NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(this.NavMeshAgentTypeIndex);

        settingsByIndex.overrideVoxelSize = true;
        settingsByIndex.voxelSize         = settingsByIndex.voxelSize * this.NavmeshResolutionModifier;
        this.BuildingOperation            = NavMeshBuilder.UpdateNavMeshDataAsync(this.NavMeshData, settingsByIndex, this.sources, this.Bounds);
        this.BuildTimer.Reset();
        this.BuildTimer.Start();
        this.HasBuildOperationStarted = true;
        float single1 = UnityEngine.Time.realtimeSinceStartup - single;

        if (single1 > 0.1f)
        {
            UnityEngine.Debug.LogWarning(string.Concat("Calling UpdateNavMesh took ", single1));
        }
    }
Exemple #4
0
    protected override void OnUpdate()
    {
        var commandBuffer = new EntityCommandBuffer(Allocator.TempJob);
        var chunks        = hybridQuery.CreateArchetypeChunkArray(Allocator.TempJob);

        var entityType       = GetArchetypeChunkEntityType();
        var translationType  = GetArchetypeChunkComponentType <Translation>(true);
        var matrixType       = GetArchetypeChunkComponentType <CellSystem.MatrixComponent>(true);
        var localToWorldType = GetArchetypeChunkComponentType <LocalToWorld>(true);
        var meshType         = GetArchetypeChunkSharedComponentType <RenderMesh>();

        for (int c = 0; c < chunks.Length; c++)
        {
            var chunk = chunks[c];

            var entities               = chunk.GetNativeArray(entityType);
            var translations           = chunk.GetNativeArray(translationType);
            var matrixComponents       = chunk.GetNativeArray(matrixType);
            var localToWorldComponents = chunk.GetNativeArray(localToWorldType);

            for (int e = 0; e < entities.Length; e++)
            {
                Entity entity   = entities[e];
                float3 position = translations[e].Value;
                CellSystem.MatrixComponent matrix = matrixComponents[e];
                float4x4 localToWorld             = localToWorldComponents[e].Value;
                Mesh     mesh = chunk.GetSharedComponentData <RenderMesh>(meshType, entityManager).mesh;

                GameObject sectorGameObject = GameObject.Instantiate(sectorPrefab, position, Quaternion.identity);
                sectorGameObject.GetComponent <MeshCollider>().sharedMesh = mesh;
                NavMeshSurface navMeshComponent = sectorGameObject.GetComponent <NavMeshSurface>();

                NavMeshBuildSettings      settings = NavMesh.GetSettingsByID(0);
                List <NavMeshBuildSource> sources  = CreateNavMeshSource(matrix.width, navMeshComponent, mesh, localToWorld);
                Bounds      bounds = CalculateWorldBounds(sources, position);
                NavMeshData data   = NavMeshBuilder.BuildNavMeshData(settings, sources, bounds, position, Quaternion.identity);

                if (data != null)
                {
                    data.name = sectorGameObject.name;
                    navMeshComponent.RemoveData();
                    navMeshComponent.navMeshData = data;
                    if (navMeshComponent.isActiveAndEnabled)
                    {
                        navMeshComponent.AddData();
                    }
                }

                commandBuffer.AddComponent <Tags.HybridGameObjectCreated>(entity, new Tags.HybridGameObjectCreated());
                commandBuffer.AddSharedComponent <GameObjectComponent>(entity, new GameObjectComponent {
                    gameObject = sectorGameObject
                });
            }
        }

        commandBuffer.Playback(entityManager);
        commandBuffer.Dispose();

        chunks.Dispose();
    }
Exemple #5
0
 static void MeshToObjFile(NavMeshTriangulation tgn, NavMeshBuildSettings settings, string filename)
 {
     using (StreamWriter sw = new StreamWriter(filename))
     {
         sw.Write(MeshToObjString(tgn, settings));
     }
 }
        public void SetBuildSettings(int _agentTypeID, int _tileSize = 50, float _voxelSize = 0.3f,
                                     float _agentRadium = 0.5f, float _agentHeight          = 2f, float _agentSlope = 40f, float _agentStep = 0.65f)
        {
            NavMeshBuildSettings setting = new NavMeshBuildSettings();

            setting.agentTypeID       = _agentTypeID;
            setting.overrideTileSize  = true;
            setting.tileSize          = _tileSize;
            setting.overrideVoxelSize = true;
            setting.voxelSize         = _voxelSize;
            setting.agentRadius       = _agentRadium;
            setting.agentHeight       = _agentHeight;
            setting.agentSlope        = _agentSlope;
            setting.agentClimb        = _agentStep;

            if (settings.ContainsKey(_agentTypeID))
            {
                settings[_agentTypeID] = setting;
            }
            else
            {
                settings.Add(_agentTypeID, setting);
            }

            if (navmeshTracker.ContainsKey(_agentTypeID))
            {
                var pair = navmeshTracker[_agentTypeID];
                pair.settings = setting;
                navmeshTracker[_agentTypeID] = pair;
            }
        }
Exemple #7
0
        public static void Build(List <GameObject> gameObjects)
        {
            List <NavMeshBuildSource> buildSources = new List <NavMeshBuildSource>();

            for (int i = 0; i < gameObjects.Count; i++)
            {
                NavMeshBuildSource navMeshSource = new NavMeshBuildSource();
                navMeshSource.shape        = NavMeshBuildSourceShape.Mesh;
                navMeshSource.sourceObject = gameObjects[i].GetComponent <MeshFilter>().sharedMesh;
                navMeshSource.transform    = gameObjects[i].transform.localToWorldMatrix;
                navMeshSource.area         = 0;
                buildSources.Add(navMeshSource);
            }

            NavMeshBuildSettings navSetting = new NavMeshBuildSettings();

            navSetting.agentRadius = 0.4f;

            NavMeshData navData = UnityEngine.AI.NavMeshBuilder.BuildNavMeshData(
                navSetting,
                buildSources,
                new Bounds(Vector3.zero, new Vector3(10000, 10000, 10000)),
                Vector3.zero,
                Quaternion.identity
                );

            navMeshDataInstance.Remove();
            navMeshDataInstance = NavMesh.AddNavMeshData(navData);
        }
Exemple #8
0
    public void UpdateNavMeshAsync()
    {
        if (this.HasBuildOperationStarted || AiManager.nav_disable || !ConVar.AI.npc_enable)
        {
            return;
        }
        float realtimeSinceStartup = Time.get_realtimeSinceStartup();

        Debug.Log((object)("Starting Monument Navmesh Build with " + (object)this.sources.Count + " sources"));
        NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(this.NavMeshAgentTypeIndex);

        ((NavMeshBuildSettings) ref settingsByIndex).set_overrideVoxelSize(true);
        ((NavMeshBuildSettings) ref settingsByIndex).set_voxelSize(((NavMeshBuildSettings) ref settingsByIndex).get_voxelSize() * this.NavmeshResolutionModifier);
        this.BuildingOperation = NavMeshBuilder.UpdateNavMeshDataAsync(this.NavMeshData, settingsByIndex, this.sources, this.Bounds);
        this.BuildTimer.Reset();
        this.BuildTimer.Start();
        this.HasBuildOperationStarted = true;
        float num = Time.get_realtimeSinceStartup() - realtimeSinceStartup;

        if ((double)num <= 0.100000001490116)
        {
            return;
        }
        Debug.LogWarning((object)("Calling UpdateNavMesh took " + (object)num));
    }
Exemple #9
0
    public AsyncOperation ResetNavMesh(AI_TYPE InType)
    {
        NavMeshDataInstance dataInstance;

        if (Map_MeshInstance.TryGetValue(InType, out dataInstance))
        {
            NavMesh.RemoveNavMeshData(dataInstance);
            Map_MeshInstance.Remove(InType);
        }

        NavMeshData meshData = new NavMeshData();

        dataInstance = NavMesh.AddNavMeshData(meshData);
        Map_MeshInstance.Add(InType, dataInstance);

        int agentIndex = (int)InType;

        List <NavMeshBuildSource> sources = new List <NavMeshBuildSource>();

        NavMeshSourceTag.Collect(ref sources, GetArea(agentIndex), InType);

        NavMeshBuildSettings defaultBuildSettings = NavMesh.GetSettingsByIndex(agentIndex);

        //print(agentIndex + "," + defaultBuildSettings.agentRadius);

        var bounds = QuantizedBounds();

        return(NavMeshBuilder.UpdateNavMeshDataAsync(meshData, defaultBuildSettings, sources, bounds));
    }
Exemple #10
0
    private static void BuildNavmeshForScene(string sceneName)
    {
        EditorSceneManager.OpenScene(sceneName);
        SetNavMeshNotWalkable(GameObject.Find("Objects"));
        SetNavMeshNotWalkable(GameObject.Find("Structure"));
        var agentController = FindObjectOfType <PhysicsRemoteFPSAgentController>();
        var capsuleCollider = agentController.GetComponent <CapsuleCollider>();
        var navmeshAgent    = agentController.GetComponent <NavMeshAgent>();

        navmeshAgent.enabled = true;
        // The Editor bake interface does not take with parameters and could not be modified as of 2018.3
        var buildSettings = new NavMeshBuildSettings()
        {
            agentTypeID       = navmeshAgent.agentTypeID,
            agentRadius       = navmeshAgent.radius,
            agentHeight       = navmeshAgent.height,
            agentSlope        = 10,
            agentClimb        = 0.5f,
            minRegionArea     = 0.05f,
            overrideVoxelSize = false,
            overrideTileSize  = false
        };

        int bs = NavMesh.GetSettingsCount();

        UnityEditor.AI.NavMeshBuilder.BuildNavMesh();
        EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
    }
Exemple #11
0
    void UpdateNavMesh()
    {
        NavMeshSourceTag.Collect(ref m_Sources, transform);
        NavMeshBuildSettings defaultBuildSettings = NavMesh.GetSettingsByID(0);

        defaultBuildSettings.agentClimb       *= transform.lossyScale.x;
        defaultBuildSettings.agentHeight      *= transform.lossyScale.x;
        defaultBuildSettings.agentRadius      *= transform.lossyScale.x;
        defaultBuildSettings.minRegionArea    *= transform.lossyScale.x;
        defaultBuildSettings.overrideVoxelSize = true;
        defaultBuildSettings.voxelSize         = defaultBuildSettings.agentRadius / 3f;
        Bounds bounds = new Bounds(Vector3.zero, Vector3.Scale(new Vector3(3f, 3f, 3f), transform.lossyScale));

        NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);

        /*
         * navMeshVis.transform.SetParent(null, false);
         * NavMeshTriangulation triangulation = NavMesh.CalculateTriangulation();
         * Mesh mesh = navMeshVis.mesh;
         * mesh.Clear();
         * mesh.vertices = triangulation.vertices;
         * mesh.triangles = triangulation.indices;
         * mesh.RecalculateNormals();
         */
        for (int i = 0; i < placedInArea.Count; i++)
        {
            if (placedInArea[i].GetComponent <NavMeshSourceTag>() == null)
            {
                placedInArea[i].transform.position = PlacementManager.Instance.GetNavPos(placedInArea[i].transform.position);
                MoveInArea(placedInArea[i]);
            }
        }
    }
 void InitNavMesh()
 {
     navMeshBuildSettings            = NavMesh.GetSettingsByIndex(0);
     navMeshBuildSettings.agentClimb = 1f;
     navMeshBuildSettings.agentSlope = 60;
     navMeshSources  = GetList <NavMeshBuildSource> (2048);
     navMeshData     = new NavMeshData();
     navMeshInstance = NavMesh.AddNavMeshData(navMeshData);
     worldBounds     = new Bounds();
 }
Exemple #13
0
    // Start is called before the first frame update
    void Awake()
    {
        Map     = Instantiate(ObjectsToPlace[2], new Vector3(10, 0, 10), Quaternion.identity);
        sources = new List <NavMeshBuildSource>();

        buildSettings = new NavMeshBuildSettings();

        source = BoxSource();
        sources.Add(source);
    }
Exemple #14
0
    // void UpdateNavMesh(bool asyncUpdate = false)
    // {
    //  // TileChunk.Collect(ref m_Sources);
    //     var m_autoTileMap = AutoTileMap_Editor.Instance;
    //     if( m_autoTileMap != null && m_autoTileMap.IsInitialized && m_autoTileMap.IsPlayMode && m_autoTileMap.m_tileChunkPoolNode != null)
    //  {
    //         m_autoTileMap.m_tileChunkPoolNode.BuildNavByMesh(ref m_Sources);
    //         var defaultBuildSettings = NavMesh.GetSettingsByID(0);
    //         var bounds = QuantizedBounds();
    //         if (asyncUpdate)
    //             m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
    //         else
    //             NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
    //     }
    // }

    public void UpdateNavMesh(List <NavMeshBuildSource> sources)
    {
        Debug.Log("UpdateNavMesh");
        NavMeshBuildSettings defaultBuildSettings = NavMesh.GetSettingsByID(0);

        defaultBuildSettings.overrideTileSize = true;
        defaultBuildSettings.tileSize         = 16;
        var bounds = QuantizedBounds();

        NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, sources, bounds);
    }
Exemple #15
0
        public void BuildTiles()
        {
            NavMeshBuildSettings buildSettings = NavMeshBuildSettings.Default();
            NavAgentSettings     agentSettings = NavAgentSettings.Default();
            NavMeshBuilder       builder       = new NavMeshBuilder(buildSettings, agentSettings);

            NavMeshTestData data = NavMeshTestData.Load();

            data.GetInputData(out float3[] vertices, out int[] indices);

            NavMeshInputBuilder input = new NavMeshInputBuilder(default);
Exemple #16
0
    /// <summary>
    /// Updates the NavMesh. Should be called after adding or removing sources
    /// </summary>
    public void UpdateMesh()
    {
        NavMeshBuildSettings defualtBuildSettings = NavMesh.GetSettingsByID(0);

        if (bounds == null)
        {
            bounds = MapValuesDict.Instance.Map.GetComponent <Renderer>().bounds;
        }

        NavMeshBuilder.UpdateNavMeshData(navMeshData, defualtBuildSettings, sources, bounds.Value);
    }
Exemple #17
0
    private void OnEnable()
    {
        NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(this.NavMeshAgentTypeIndex);

        this.agentTypeId  = ((NavMeshBuildSettings) ref settingsByIndex).get_agentTypeID();
        this.NavMeshData  = new NavMeshData(this.agentTypeId);
        this.sources      = new List <NavMeshBuildSource>();
        this.terrainBakes = new List <AsyncTerrainNavMeshBake>();
        this.defaultArea  = NavMesh.GetAreaFromName(this.DefaultAreaName);
        this.InvokeRepeating(new Action(this.FinishBuildingNavmesh), 0.0f, 1f);
    }
Exemple #18
0
        public void Start()
        {
            _searchingForPlaneUI.SetActive(true);
            _defaultBuildSettings = NavMesh.GetSettingsByID(0);

            _firstPlaneGeneratedEvents.AddListener((DetectedPlane dp) => {
                _searchingForPlaneUI.SetActive(false);
            });
            _firstPlaneGeneratedEvents.AddListener((DetectedPlane dp) => {
                StartCoroutine("UpdateNavMeshAsync");
            });
        }
Exemple #19
0
        public void BuildTiles()
        {
            NavMeshBuildSettings buildSettings = NavMeshBuildSettings.Default();
            NavAgentSettings     agentSettings = NavAgentSettings.Default();
            NavMeshBuilder       builder       = new NavMeshBuilder(buildSettings, agentSettings);

            NavMeshTestData data = NavMeshTestData.Load();

            data.GetInputData(out float3[] vertices, out int[] indices);
            GameLogger.Log("BuildTiles Inputs Vertices:{0} Triangles{1}", vertices.Length, indices.Length);

            NavMeshInputBuilder input = new NavMeshInputBuilder(default);
    public void GeanerateNavMeshData()
    {
        List <NavMeshBuildSource> sourceList = new List <NavMeshBuildSource>();
        List <NavMeshBuildMarkup> markups    = new List <NavMeshBuildMarkup>();

        NavMeshBuilder.CollectSources(new Bounds(Vector3.zero, Vector3.one * 1000), 0 | (1 << 9), NavMeshCollectGeometry.RenderMeshes, 0, markups, sourceList);
        NavMeshBuildSettings nmbs = NavMesh.CreateSettings();

        nmbs.agentTypeID = Spawner.nma[0].agentTypeID;
        NavMeshData nmd = NavMeshBuilder.BuildNavMeshData(nmbs, sourceList, new Bounds(transform.position, Vector3.one * 1000), Vector3.zero, Quaternion.identity);

        currentNavMeshs.Add(NavMesh.AddNavMeshData(nmd));
    }
    public NavMeshBuildSettings ToBuildSettings()
    {
        var navMeshBuildSettings = new NavMeshBuildSettings
        {
            agentClimb  = agentClimb,
            agentHeight = agentHeight,
            agentRadius = agentRadius,
            agentSlope  = agentSlope,
            agentTypeID = agentTypeID
        };

        return(navMeshBuildSettings);
    }
Exemple #22
0
    // create the NavMesh at run time after map is generated
    void bakeNavMesh()
    {
        // lots of BS about the scene that will need editing at some point I'm sure
        Bounds b = new Bounds(mapCenter, mapCenter + new Vector3(0f, 10f, 0f));
        List <NavMeshBuildSource> sources = new List <NavMeshBuildSource>();
        List <NavMeshBuildMarkup> markups = new List <NavMeshBuildMarkup>();

        NavMeshBuilder.CollectSources(b, 0, NavMeshCollectGeometry.RenderMeshes, 0, markups, sources);
        NavMeshBuildSettings settings = NavMesh.CreateSettings();

        // here's the actual important line
        NavMeshBuilder.BuildNavMeshData(settings, sources, b, mapCenter, Quaternion.identity);
    }
Exemple #23
0
    // Use this for initialization
    void Start()
    {
        List <NavMeshBuildMarkup> markups = new List <NavMeshBuildMarkup>();
        List <NavMeshBuildSource> builds  = new List <NavMeshBuildSource>();

        NavMeshBuilder.CollectSources(transform, LayerMask.NameToLayer("Default"), NavMeshCollectGeometry.RenderMeshes, 0, markups, builds);
        NavMeshBuildSettings buildSettings = new NavMeshBuildSettings();
        Bounds localBounds = new Bounds();

        localBounds.size = new Vector3(100f, 100f, 100f);

        NavMeshBuilder.BuildNavMeshData(buildSettings, builds, localBounds, Vector3.zero, Quaternion.identity);
    }
Exemple #24
0
    /// <summary>
    /// 初始化寻路数据
    /// </summary>
    public void InitNavMesh()
    {
        navMeshSources = new Dictionary <Vector3Int, NavMeshBuildSource>();

        navMeshData = new NavMeshData();

        navMeshBuildSettings             = NavMesh.GetSettingsByIndex(0);
        navMeshBuildSettings.agentClimb  = 1.5f;
        navMeshBuildSettings.agentSlope  = 60;
        navMeshBuildSettings.agentHeight = 1.8f;

        navMeshInstance = NavMesh.AddNavMeshData(navMeshData);
        worldBounds     = new Bounds();
    }
Exemple #25
0
    private void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.Collect(ref this.m_Sources, 0);
        NavMeshBuildSettings settingsById = NavMesh.GetSettingsByID(0);
        Bounds bounds = this.QuantizedBounds();

        if (asyncUpdate)
        {
            this.m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(this.m_NavMesh, settingsById, this.m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(this.m_NavMesh, settingsById, this.m_Sources, bounds);
        }
    }
    private void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.Collect(ref m_Sources);
        NavMeshBuildSettings defaultBuildSettings = NavMesh.GetSettingsByID(0);
        Bounds bounds = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }
Exemple #27
0
    IEnumerator updateNavMesh()
    {
        isReady = false;

        navMeshBuildSourceList.Clear();

        foreach (GameObject gobj in targetMeshes)
        {
            MeshFilter         mf  = gobj.GetComponent <MeshFilter>();
            NavMeshBuildSource nbs = new NavMeshBuildSource();

            if (mf.sharedMesh == null)
            {
                yield return(null);
            }

            nbs.shape = NavMeshBuildSourceShape.Mesh;

            Mesh mesh = mf.sharedMesh;
            if ((mesh == null) || (mesh.subMeshCount == 0))
            {
                continue;
            }

            nbs.sourceObject = mf.sharedMesh;
            nbs.transform    = mf.transform.localToWorldMatrix;
            nbs.area         = 0;

            navMeshBuildSourceList.Add(nbs);
        }

        Bounds bounds = new Bounds(Vector3.zero, new Vector3(50, 20, 50));
        NavMeshBuildSettings settings = NavMesh.GetSettingsByID(0);
        AsyncOperation       op;

        op = NavMeshBuilder.UpdateNavMeshDataAsync(navMeshData, settings, navMeshBuildSourceList, bounds);
        while (true)
        {
            if (op.isDone)
            {
                break;
            }
            yield return(null);
        }

        Debug.Log("ナビメッシュ作成完了");
        isReady = true;
    }
 void InitNavMesh()
 {
     if (!enableNavMesh)
     {
         return;
     }
     navMeshBuildSettings             = NavMesh.GetSettingsByIndex(0);
     navMeshBuildSettings.agentClimb  = 18f;
     navMeshBuildSettings.agentSlope  = 80;
     navMeshBuildSettings.agentHeight = 18;
     navMeshBuildSettings.agentRadius = 8;
     navMeshSources  = Misc.GetList <NavMeshBuildSource> (lowMemoryMode, 2048);
     navMeshData     = new NavMeshData();
     navMeshInstance = NavMesh.AddNavMeshData(navMeshData);
     worldBounds     = new Bounds();
 }
Exemple #29
0
        public void GenerateNavMesh()
        {
            NavMeshBuildSettings navSettings = new NavMeshBuildSettings();

            navSettings.agentClimb  = NAV_STEP;
            navSettings.agentHeight = NAV_HEIGHT;
            navSettings.agentRadius = NAV_RADIUS;
            navSettings.agentSlope  = NAV_SLOPE;
            NavMeshBuildSource src = new NavMeshBuildSource();

            src.sourceObject = mapRoot;
            src.shape        = NavMeshBuildSourceShape.Mesh;
            List <NavMeshBuildSource> srcs = new List <NavMeshBuildSource>();

            NavMeshBuilder.BuildNavMeshData(navSettings, srcs, new Bounds(), Vector3.zero, Quaternion.identity);
        }
Exemple #30
0
        protected override YAMLMappingNode ExportYAMLRoot(IAssetsExporter exporter)
        {
#warning TODO: values acording to read version (current 2017.3.0f3)
            YAMLMappingNode node = base.ExportYAMLRoot(exporter);
            node.InsertSerializedVersion(GetSerializedVersion(exporter.Version));
            node.Add("m_NavMeshTiles", NavMeshTiles.ExportYAML(exporter));
            node.Add("m_NavMeshBuildSettings", NavMeshBuildSettings.ExportYAML(exporter));
            node.Add("m_Heightmaps", Heightmaps.ExportYAML(exporter));
            node.Add("m_HeightMeshes", HeightMeshes.ExportYAML(exporter));
            node.Add("m_OffMeshLinks", OffMeshLinks.ExportYAML(exporter));
            node.Add("m_SourceBounds", SourceBounds.ExportYAML(exporter));
            node.Add("m_Rotation", Rotation.ExportYAML(exporter));
            node.Add("m_Position", Position.ExportYAML(exporter));
            node.Add("m_AgentTypeID", AgentTypeID);
            return(node);
        }