Exemplo n.º 1
0
        public void OnEnable()
        {
            _recastConfig = GameObject.FindObjectOfType <RecastConfig>();
            _tileCache    = new TileCache(navmeshData, _recastConfig);

            IntPtr h = createCrowd(MaxAgents, AgentMaxRadius, _tileCache.NavMeshHandle.Handle);

            _crowd = new HandleRef(this, h);

            ushort k       = 0;
            var    filters = _recastConfig.Filters.ToList();

            filters.Reverse();
            foreach (var filter in filters)
            {
                ushort include = 0;
                ushort exclude = 0;

                foreach (var incl in filter.Include)
                {
                    include |= _recastConfig.Areas[incl.Name];
                }

                foreach (var excl in filter.Exclude)
                {
                    exclude |= _recastConfig.Areas[excl.Name];
                }

                setFilter(_crowd.Handle, k, include, exclude);
                ++k;
            }

            randomSample = new float[3];
            positions    = new float[MaxAgents * 3];
            velocities   = new float[MaxAgents * 3];
            targetStates = new byte[MaxAgents];
            states       = new byte[MaxAgents];
            partial      = new bool[MaxAgents];

            Instance = this;

            if (RenderInGame)
            {
                mesh.Clear();

                switch (Mode)
                {
                case RenderMode.POLYS:
                    Assert.IsTrue(polymesh != null);

                    RecastDebug.ShowRecastNavmesh(mesh, polymesh.PolyMesh, polymesh.config);
                    break;

                case RenderMode.DETAIL_POLYS:
                    Assert.IsTrue(polymesh != null);

                    RecastDebug.ShowRecastDetailMesh(mesh, polymesh.PolyDetailMesh);
                    break;

                case RenderMode.TILE_POLYS:
                    for (int i = 0; i < navmeshData.header.numTiles; ++i)
                    {
                        RecastDebug.ShowTilePolyDetails(mesh, _tileCache.NavMeshHandle.Handle, i);
                    }
                    break;
                }

                //RecastDebug.RenderObstacles(_tileCache.TileCacheHandle.Handle);

                mesh.CreateGameObjects("RecastRenderer", material);
                mesh.Rebuild();
            }
        }