void OnDrawGizmos()
 {
     VolumeCellRaster.Draw(_cells);
     foreach (var cell in cellList)
     {
         VolumeCellRaster.Draw(cell);
     }
 }
예제 #2
0
        private bool AutoComputeVolumeCells(string Name)
        {
            Scene curScene = SceneManager.GetSceneByName(Name);

            GameObject[] objs = curScene.GetRootGameObjects();

            var bounds       = new Bounds();
            var colliderList = new List <Collider>();

            for (int i = 0; i < curScene.rootCount; i++)
            {
                GameObject obj = objs[i];

                var colliders = obj.GetComponentsInChildren <Collider>();
                foreach (var collider in colliders)
                {
                    if (IsStandableCollider(collider))
                    {
                        colliderList.Add(collider);

                        bounds.Encapsulate(collider.bounds);
                    }
                }
            }
            bounds.Expand(new Vector3(5.0f, 5.0f, 5.0f));


            Debug.LogFormat("Total Raster Collider Count {0}", colliderList.Count);

            var success = true;

            {
                var raster = new VolumeCellRaster(new RasterSettings(Config.CellSize, Config.MinPlayAreaHeight, Config.MaxPlayAreaHeight));
                raster.AddVolume(bounds.min, bounds.max);
                var cells = raster.ComputeVolumeCells(colliderList, Util.Progress);

                if (cells != null && cells.Count > 0)
                {
                    cells = ProprocessCells(cells, Config.CellSize);
                    var visVolume = new VisVolume(this);
                    visVolume.CellSize = Config.CellSize;
                    visVolume.aabb     = bounds;
                    volumelList.Add(visVolume);

                    foreach (var cell in cells)
                    {
                        var c = new Cell(visVolume);
                        c.aabb = new Bounds(cell.Center, cell.Size);
                        visVolume.AddCell(c);
                    }
                }

                success = cells != null;
            }
            return(success);
        }
        void ComputeVolumeCells()
        {
            var scene        = SceneManager.GetActiveScene();
            var colliderList = new LinkedList <Collider>();

            var roots = scene.GetRootGameObjects();

            foreach (var root in roots)
            {
                if (!root.gameObject.activeSelf)
                {
                    continue;
                }

                var colliders = root.GetComponentsInChildren <Collider>();
                foreach (var collider in colliders)
                {
                    if (!collider.isTrigger && collider.GetComponent <VolumeCellRasterExample>() == null && collider.enabled && collider.gameObject.activeSelf)
                    {
                        colliderList.AddLast(collider);
                    }
                }
            }

            Debug.LogFormat("Collider Count {0}", colliderList.Count);
            var raster = new VolumeCellRaster(new RasterSettings(CellSize, MinPlayAreaHeight, MaxPlayAreaHeight));

            foreach (var vol in Volumes)
            {
                raster.AddVolume(vol.size, vol.center, vol.transform);
            }

            _cells = raster.ComputeVolumeCells(colliderList);

            for (int i = 0; i < _cells.Count; ++i)
            {
                var cell = _cells[i];
                GenerateCells(new Bounds(cell.Center, cell.Size), CellSize);
                Debug.LogFormat("{0} Min {1} Max {2} Size{3}", i, cell.BoundsMin, cell.BoundsMax, cell.Size);
            }
        }