Exemple #1
0
 /// <summary>
 /// 地形更新处理
 /// </summary>
 public void HandleForUpdateNavMesh()
 {
     if (navMeshIsUpdating)
     {
         if (navMeshUpdateOperation.isDone)
         {
             if (navMeshInstance.valid)
             {
                 NavMesh.RemoveNavMeshData(navMeshInstance);
             }
             navMeshInstance   = NavMesh.AddNavMeshData(navMeshData);
             navMeshIsUpdating = false;
         }
     }
     else if (navMeshHasNewData)
     {
         try
         {
             navMeshUpdateOperation = NavMeshBuilder.UpdateNavMeshDataAsync(navMeshData, navMeshBuildSettings, navMeshSources.Values.ToList(), worldBounds);
             navMeshIsUpdating      = true;
         }
         catch
         {
         }
         navMeshHasNewData = false;
     }
 }
    void Awake()
    {
        nvData = new NavMeshData();
        foreach (var obj in notWalkable)
        {
            NavMeshBuildMarkup navMeshBuildMarkup = new NavMeshBuildMarkup();
            navMeshBuildMarkup.area         = NavMesh.GetAreaFromName("Not Walkable");
            navMeshBuildMarkup.overrideArea = true;
            navMeshBuildMarkup.root         = obj.transform;
            objectsNotTreated.Add(navMeshBuildMarkup);
        }
        NavMesh.AddNavMeshData(nvData);
        NavMeshBuilder.CollectSources(
            new Bounds(gameObject.transform.position, new Vector3(bounds, bounds, bounds)),
            mask.value,
            NavMeshCollectGeometry.PhysicsColliders,
            0,
            objectsNotTreated,
            watchedSources);

        status = NavMeshBuilder.UpdateNavMeshDataAsync(
            nvData,
            NavMesh.GetSettingsByID(0),
            watchedSources,
            new Bounds(gameObject.transform.position, new Vector3(bounds, bounds, bounds)));
    }
Exemple #3
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 #4
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 #5
0
    public void RebuildNavmesh(bool async)
    {
        if (async && buildOperation != null && !buildOperation.isDone)
        {
            return;
        }

        buildOperation = null;

        var totalBounds = new Bounds();

        NavMeshSourceTag2D.Collect(ref buildSources, ref totalBounds);
        var buildSettings       = NavMesh.GetSettingsByID(0);
        var totalBoundsReversed = new Bounds(Plane2DRotationInverse * totalBounds.center, Plane2DRotationInverse * totalBounds.size); // We need to reverse the rotation that's going to be used for baking to get proper bounds
        var buildBounds         = new Bounds(Vector3.zero, Vector3.one * float.MaxValue);                                             //Using enclosing and empty bounds is bugged at the moment - use arbitrarily big one

        if (!data)
        {
            data = NavMeshBuilder.BuildNavMeshData(buildSettings, buildSources, buildBounds, totalBounds.center, Plane2DRotation);
        }
        else
        {
            if (async)
            {
                buildOperation = NavMeshBuilder.UpdateNavMeshDataAsync(data, buildSettings, buildSources, buildBounds);
            }
            else
            {
                NavMeshBuilder.UpdateNavMeshData(data, buildSettings, buildSources, buildBounds);
            }
        }

        dataInstance.Remove();
        dataInstance = NavMesh.AddNavMeshData(data);
    }
        public IEnumerator UpdateNavMeshData()
        {
            var defaultBuildSettings = NavMesh.GetSettingsByID(0);
            var sources   = navMeshTargets.Select(x => x.NavMeshTargetData.NavMeshBuildSource).ToList();
            var operation = NavMeshBuilder.UpdateNavMeshDataAsync(navMeshData, defaultBuildSettings, sources, QuantizedBounds());

            yield return(operation);
        }
Exemple #7
0
    // Token: 0x06000B4C RID: 2892 RVA: 0x000516E0 File Offset: 0x0004F8E0
    private void BuildTile(Pathfinding.NavMeshTile tile)
    {
        DateTime now = DateTime.Now;
        List <NavMeshBuildSource> list    = new List <NavMeshBuildSource>();
        List <NavMeshBuildMarkup> markups = new List <NavMeshBuildMarkup>();

        Pathfinding.AgentType     z        = (Pathfinding.AgentType)tile.m_tile.z;
        Pathfinding.AgentSettings settings = this.GetSettings(z);
        Bounds includedWorldBounds         = new Bounds(tile.m_center, new Vector3(this.m_tileSize, 6000f, this.m_tileSize));
        Bounds localBounds = new Bounds(Vector3.zero, new Vector3(this.m_tileSize, 6000f, this.m_tileSize));
        int    defaultArea = settings.m_canWalk ? 0 : 1;

        NavMeshBuilder.CollectSources(includedWorldBounds, this.m_layers.value, NavMeshCollectGeometry.PhysicsColliders, defaultArea, markups, list);
        if (settings.m_avoidWater)
        {
            List <NavMeshBuildSource> list2 = new List <NavMeshBuildSource>();
            NavMeshBuilder.CollectSources(includedWorldBounds, this.m_waterLayers.value, NavMeshCollectGeometry.PhysicsColliders, 1, markups, list2);
            using (List <NavMeshBuildSource> .Enumerator enumerator = list2.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    NavMeshBuildSource item = enumerator.Current;
                    item.transform *= Matrix4x4.Translate(Vector3.down * 0.2f);
                    list.Add(item);
                }
                goto IL_1AE;
            }
        }
        if (settings.m_canSwim)
        {
            List <NavMeshBuildSource> list3 = new List <NavMeshBuildSource>();
            NavMeshBuilder.CollectSources(includedWorldBounds, this.m_waterLayers.value, NavMeshCollectGeometry.PhysicsColliders, 3, markups, list3);
            if (settings.m_swimDepth != 0f)
            {
                using (List <NavMeshBuildSource> .Enumerator enumerator = list3.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        NavMeshBuildSource item2 = enumerator.Current;
                        item2.transform *= Matrix4x4.Translate(Vector3.down * settings.m_swimDepth);
                        list.Add(item2);
                    }
                    goto IL_1AE;
                }
            }
            list.AddRange(list3);
        }
IL_1AE:
        if (tile.m_data == null)
        {
            tile.m_data          = new NavMeshData();
            tile.m_data.position = tile.m_center;
        }
        this.m_buildOperation = NavMeshBuilder.UpdateNavMeshDataAsync(tile.m_data, settings.m_build, list, localBounds);
        this.m_buildTile      = tile;
    }
        public AsyncOperation UpdateNavMesh(NavMeshData data)
        {
            var sources = CollectSources();

            // Use unscaled bounds - this differs in behaviour from e.g. collider components.
            // But is similar to reflection probe - and since navmesh data has no scaling support - it is the right choice here.
            var sourcesBounds = new Bounds(m_Center, Abs(m_Size));

            sourcesBounds = CalculateWorldBounds(sources);

            return(NavMeshBuilder.UpdateNavMeshDataAsync(data, GetBuildSettings(), sources, sourcesBounds));
        }
Exemple #9
0
    IEnumerator UpdateNavmeshDataAsync()
    {
        AsyncOperation op = NavMeshBuilder.UpdateNavMeshDataAsync(
            NavMeshData,
            NavMesh.GetSettingsByID(0),
            GetBuildSources(BuildMask),
            new Bounds(BoundsCenter, BoundsSize));

        yield return(op);

        AddNavMeshData();
        Debug.Log("Update finished " + Time.realtimeSinceStartup.ToString());
    }
Exemple #10
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 #12
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;
    }
    public void RebuildNavMesh()
    {
        NavMeshBuilder.CollectSources(
            new Bounds(gameObject.transform.position, new Vector3(bounds, bounds, bounds)),
            mask.value, // LayerMask.GetMask("MovingNavMesh"),
            NavMeshCollectGeometry.PhysicsColliders,
            0,
            objectsNotTreated,
            watchedSources);

        status = NavMeshBuilder.UpdateNavMeshDataAsync(
            nvData,
            NavMesh.GetSettingsByID(0),
            watchedSources,
            new Bounds(gameObject.transform.position, new Vector3(bounds, bounds, bounds)));
    }
Exemple #14
0
        IEnumerator UpdateNavMeshAsync()
        {
            while (true)
            {
                if (_planeVizs.Count < 1)
                {
                    yield return(new AsyncOperation());
                }
                var navMeshBuildSources = _planeVizs.Select(planeViz => (NavMeshBuildSource)planeViz.NavMeshSource).ToList();
                var navMeshBuildBounds  = CalcNavMeshBuildBounds();
                yield return(NavMeshBuilder.UpdateNavMeshDataAsync(_navMesh, _defaultBuildSettings, navMeshBuildSources, navMeshBuildBounds));

                print("NavMeshBuilder updated");
                print(_navMesh.sourceBounds.center);
            }
        }
Exemple #15
0
    private void UpdateNavMesh(UnityTile tile)
    {
        if (buildSources.ContainsKey(tile))
        {
            buildSources.Remove(tile);
        }

        buildSources.Add(tile, new NavMeshBuildSource()
        {
            shape        = NavMeshBuildSourceShape.Mesh,
            sourceObject = tile.MeshFilter.mesh,
            transform    = tile.transform.localToWorldMatrix,
            area         = 0
        });

        NavMeshBuilder.UpdateNavMeshDataAsync(navMeshData, settings, new List <NavMeshBuildSource>(buildSources.Values),
                                              new Bounds(tile.transform.position, Vector3.one * 100000));
    }
        private void UpdateNavMesh(bool asyync = false)
        {
            _navMesh     = new NavMeshData( );
            _navInstance = NavMesh.AddNavMeshData(_navMesh);
            var settings = NavMesh.GetSettingsByID(0);

            NavMeshSourceTag.Collect(ref _sources);
            var bounds = BoundsHelper.QauntizeBounds(_center, size, factor);

            if (asyync)
            {
                _operation = NavMeshBuilder.UpdateNavMeshDataAsync(_navMesh, settings, _sources, bounds);
            }
            else
            {
                NavMeshBuilder.UpdateNavMeshData(_navMesh, settings, _sources, bounds);
            }
        }
Exemple #17
0
        private void BuildNavMesh()
        {
            queriedNavMeshBuilds--;
            Debug.Log("Starting NavMesh build with:\nbounds: min=" + navMeshBounds.min + " max=" + navMeshBounds.max);
            navMeshWatch.Start();
            List <NavMeshBuildSource> sources = new List <NavMeshBuildSource>();

            foreach (Chunk chk in chunks.Values)
            {
                sources.Add(CreateNavMeshBuildSource(chk.Get3DSize(), chk.GetMesh(), chk.transform.localToWorldMatrix, NavMesh.GetAreaFromName("Walkable")));
            }
            navMeshOperation           = new AsyncOperationCallback(NavMeshBuilder.UpdateNavMeshDataAsync(navMeshData, buildSettings, sources, navMeshBounds));
            navMeshOperation.callback += OnNavMeshBuildFinished;
            if (navMeshData == null)
            {
                Debug.Log("NavMeshBulding error");
            }
            NavMesh.AddNavMeshData(navMeshData);
        }
Exemple #18
0
 public void UpdateNavMeshAsync()
 {
     if (!HasBuildOperationStarted && !AiManager.nav_disable)
     {
         float realtimeSinceStartup = Time.realtimeSinceStartup;
         UnityEngine.Debug.Log("Starting Navmesh Build with " + sources.Count + " sources");
         NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(NavMeshAgentTypeIndex);
         settingsByIndex.overrideVoxelSize = true;
         settingsByIndex.voxelSize        *= 2f;
         BuildingOperation = NavMeshBuilder.UpdateNavMeshDataAsync(NavMeshData, settingsByIndex, sources, Bounds);
         BuildTimer.Reset();
         BuildTimer.Start();
         HasBuildOperationStarted = true;
         float num = Time.realtimeSinceStartup - realtimeSinceStartup;
         if (num > 0.1f)
         {
             UnityEngine.Debug.LogWarning("Calling UpdateNavMesh took " + num);
         }
     }
 }
        /// <summary>
        /// 创建/更新指定AgentType的指定范围的的Navmesh
        /// </summary>
        /// <param name="_agentType">AgentTypeID</param>
        /// <param name="_bounds">区域</param>
        /// <param name="_async">是否异步</param>
        private void UpdateNavmesh(int _agentType, Bounds _bounds, bool _async)
        {
            //如果不存在,则添加
            if (!navmeshTracker.ContainsKey(_agentType))
            {
                var data     = new NavMeshData(_agentType);
                var instance = NavMesh.AddNavMeshData(data);

                navmeshTracker.Add(_agentType, new NavmeshDataPair()
                {
                    data            = data,
                    settings        = settings.ContainsKey(_agentType) ? settings[_agentType] : NavMesh.GetSettingsByID(_agentType),
                    instance        = instance,
                    updateOperation = null
                });

                _async = false; //第一次必须非异步
            }

            var pair = navmeshTracker[_agentType];

            if (_async)
            {
                if (pair.updateOperation == null || pair.updateOperation.isDone)
                {
                    pair.updateOperation = null;
                    pair.updateOperation = NavMeshBuilder.UpdateNavMeshDataAsync(pair.data, pair.settings, sources, _bounds);
                }
            }
            else
            {
                if (pair.updateOperation != null && !pair.updateOperation.isDone)
                {
                    NavMeshBuilder.Cancel(pair.data);
                }

                pair.updateOperation = null;
                NavMeshBuilder.UpdateNavMeshData(pair.data, pair.settings, sources, _bounds);
            }
        }
Exemple #20
0
    private IEnumerator UpdateNavMeshDataAsync()
    {
        _updatingNavMesh = true;
        yield return(0);

        NavMeshBuildSettings settings = NavMesh.GetSettingsByIndex(0);

        var bounds = new Bounds(Vector3.zero, 1000.0f * Vector3.one);

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

        foreach (var chunk in chunks)
        {
            var source = new NavMeshBuildSource();
            //source.component = chunk.terrain.meshCollider;
            source.sourceObject = chunk.terrain.hexMesh;
            source.shape        = NavMeshBuildSourceShape.Mesh;
            source.transform    = chunk.terrain.transform.localToWorldMatrix;
            source.area         = 0;
            sources.Add(source);
        }

        AsyncOperation op = NavMeshBuilder.UpdateNavMeshDataAsync(navMeshData, settings, sources, bounds);

        yield return(op);

        if (navMeshData != null)
        {
            if (navMeshDataInstance.valid)
            {
                NavMesh.RemoveNavMeshData(navMeshDataInstance);
            }
            navMeshDataInstance       = NavMesh.AddNavMeshData(navMeshData);
            navMeshDataInstance.owner = this;
        }

        Debug.Log("NavMesh Updated");

        _updatingNavMesh = false;
    }
Exemple #21
0
    private void UpdateNavMesh(bool async)
    {
        // Navmesh settings
        NavMeshBuildSettings settings = NavMesh.GetSettingsByID(0);

        settings.minRegionArea = 0;

        // Bounds set to be enormous to ensure all areas are covered
        Bounds bounds = new Bounds(Vector3.zero, 1000 * Vector3.one);

        // Build!
        if (async)
        {
            // Build navmesh asynchronously from sources
            m_navMeshOperation = NavMeshBuilder.UpdateNavMeshDataAsync(m_navMeshData, settings, m_navMeshSources, bounds);
        }
        else
        {
            // Blocking call used only for initial empty NavMesh
            NavMeshBuilder.UpdateNavMeshData(m_navMeshData, settings, m_navMeshSources, bounds);
        }
    }
Exemple #22
0
        AsyncOperation UpdateNavMesh(bool asyncOperation = false)
        {
            if (!NavMeshSourceTag.MakeUnchanged())
            {
                return(null);
            }

            NavMeshSourceTag.Collect(ref sources);
            var setting = NavMesh.GetSettingsByID(0);
            var bounds  = new Bounds(Quantizer.Quantize(transform.position, 0.1f * size), size);

            Debug.Log("Update NavMesh");

            if (asyncOperation)
            {
                return(NavMeshBuilder.UpdateNavMeshDataAsync(navMesh, setting, sources, bounds));
            }
            else
            {
                NavMeshBuilder.UpdateNavMeshData(navMesh, setting, sources, bounds);
                return(null);
            }
        }
Exemple #23
0
 private void UpdateNavMesh()
 {
     _asyncOperation            = NavMeshBuilder.UpdateNavMeshDataAsync(_navMeshData, NavMesh.GetSettingsByID(0), _sources, _bounds);
     _asyncOperation.completed += _asyncOperation_completed;
 }