Пример #1
0
    public IEnumerator UpdateNavMeshAndWait()
    {
        MonumentNavMesh vector3 = null;

        if (vector3.HasBuildOperationStarted)
        {
            yield break;
        }
        if (AiManager.nav_disable || !AI.npc_enable)
        {
            yield break;
        }
        vector3.HasBuildOperationStarted = false;
        vector3.Bounds.center            = vector3.transform.position;
        if (!vector3.overrideAutoBounds)
        {
            vector3.Bounds.size = new Vector3((float)(vector3.CellSize * vector3.CellCount), (float)vector3.Height, (float)(vector3.CellSize * vector3.CellCount));
        }
        if (!AiManager.nav_wait)
        {
            vector3.StartCoroutine(vector3.CollectSourcesAsync(new Action(vector3.UpdateNavMeshAsync)));
        }
        else
        {
            yield return(vector3.CollectSourcesAsync(new Action(vector3.UpdateNavMeshAsync)));
        }
        if (!AiManager.nav_wait)
        {
            UnityEngine.Debug.Log("nav_wait is false, so we're not waiting for the navmesh to finish generating. This might cause your server to sputter while it's generating.");
            yield break;
        }
        int num = 0;

        while (!vector3.HasBuildOperationStarted)
        {
            Thread.Sleep(250);
            yield return(null);
        }
        while (vector3.BuildingOperation != null)
        {
            int buildingOperation = (int)(vector3.BuildingOperation.progress * 100f);
            if (num != buildingOperation)
            {
                UnityEngine.Debug.LogFormat("{0}%", new object[] { buildingOperation });
                num = buildingOperation;
            }
            Thread.Sleep(250);
            vector3.FinishBuildingNavmesh();
            yield return(null);
        }
    }
Пример #2
0
    public IEnumerator UpdateNavMeshAndWait()
    {
        MonumentNavMesh monumentNavMesh = this;

        if (!monumentNavMesh.HasBuildOperationStarted && !AiManager.nav_disable && ConVar.AI.npc_enable)
        {
            monumentNavMesh.HasBuildOperationStarted = false;
            ((Bounds) ref monumentNavMesh.Bounds).set_center(((Component)monumentNavMesh).get_transform().get_position());
            ((Bounds) ref monumentNavMesh.Bounds).set_size(new Vector3((float)(monumentNavMesh.CellSize * monumentNavMesh.CellCount), (float)monumentNavMesh.Height, (float)(monumentNavMesh.CellSize * monumentNavMesh.CellCount)));
            if (AiManager.nav_wait)
            {
                yield return((object)monumentNavMesh.CollectSourcesAsync(new Action(monumentNavMesh.UpdateNavMeshAsync)));
            }
            else
            {
                ((MonoBehaviour)monumentNavMesh).StartCoroutine(monumentNavMesh.CollectSourcesAsync(new Action(monumentNavMesh.UpdateNavMeshAsync)));
            }
            if (!AiManager.nav_wait)
            {
                Debug.Log((object)"nav_wait is false, so we're not waiting for the navmesh to finish generating. This might cause your server to sputter while it's generating.");
            }
            else
            {
                int lastPct = 0;
                while (!monumentNavMesh.HasBuildOperationStarted)
                {
                    Thread.Sleep(250);
                    yield return((object)null);
                }
                while (monumentNavMesh.BuildingOperation != null)
                {
                    int num = (int)((double)monumentNavMesh.BuildingOperation.get_progress() * 100.0);
                    if (lastPct != num)
                    {
                        Debug.LogFormat("{0}%", new object[1]
                        {
                            (object)num
                        });
                        lastPct = num;
                    }
                    Thread.Sleep(250);
                    monumentNavMesh.FinishBuildingNavmesh();
                    yield return((object)null);
                }
            }
        }
    }
Пример #3
0
    private IEnumerator CollectSourcesAsync(Action callback)
    {
        MonumentNavMesh monumentNavMesh = null;
        float           single          = UnityEngine.Time.realtimeSinceStartup;

        UnityEngine.Debug.Log("Starting Navmesh Source Collecting.");
        List <NavMeshBuildMarkup> navMeshBuildMarkups = new List <NavMeshBuildMarkup>();

        NavMeshBuilder.CollectSources(monumentNavMesh.Bounds, monumentNavMesh.LayerMask, monumentNavMesh.NavMeshCollectGeometry, monumentNavMesh.defaultArea, navMeshBuildMarkups, monumentNavMesh.sources);
        if (TerrainMeta.HeightMap != null)
        {
            for (float i = -monumentNavMesh.Bounds.extents.x; i < monumentNavMesh.Bounds.extents.x; i += (float)monumentNavMesh.CellSize)
            {
                for (float j = -monumentNavMesh.Bounds.extents.z; j < monumentNavMesh.Bounds.extents.z; j += (float)monumentNavMesh.CellSize)
                {
                    AsyncTerrainNavMeshBake asyncTerrainNavMeshBake = new AsyncTerrainNavMeshBake(monumentNavMesh.Bounds.center + new Vector3(i, 0f, j), monumentNavMesh.CellSize, monumentNavMesh.Height, false, true);
                    yield return(asyncTerrainNavMeshBake);

                    monumentNavMesh.terrainBakes.Add(asyncTerrainNavMeshBake);
                    NavMeshBuildSource navMeshBuildSource = asyncTerrainNavMeshBake.CreateNavMeshBuildSource(true);
                    navMeshBuildSource.area = monumentNavMesh.defaultArea;
                    monumentNavMesh.sources.Add(navMeshBuildSource);
                    asyncTerrainNavMeshBake = null;
                }
            }
        }
        monumentNavMesh.AppendModifierVolumes(ref monumentNavMesh.sources);
        float single1 = UnityEngine.Time.realtimeSinceStartup - single;

        if (single1 > 0.1f)
        {
            UnityEngine.Debug.LogWarning(string.Concat("Calling CollectSourcesAsync took ", single1));
        }
        if (callback != null)
        {
            callback();
        }
    }