Contains Bounds of the building, and the position
Inheritance: Voronoi.Point
コード例 #1
0
        private void CreateBuildingOnRoad(Road road)
        {
            var         cell        = road.ParentCell;
            const int   offset      = 6;
            const float minDistance = 0.5f;

            //Create an offset line of this road towards the inside of the cell
            var offsetLine = road.GenerateOffsetParallelTowardsPoint(offset, cell.SitePoint);

            //calculate total length of the line
            var length   = offsetLine.Length();
            var traveled = minDistance;

            //keep repeating until the end is reached
            while (traveled < length - minDistance)
            {
                //get point on line using normalized values [0,1]
                var pc  = traveled / length;
                var pos = offsetLine.FindRandomPointOnLine(pc, pc);

                //Create a building site from this point
                var bs = BuildingSite.FromPoint(pos);
                bs.ParentRoad = road;
                road.Buildings.Add(bs);


                //travel along the line using the width of the building site
                traveled += (minDistance + bs.Width / 2);
            }
        }
コード例 #2
0
 public static BuildingSite FromPoint(Point p)
 {
     var b = new BuildingSite(p.X, p.Y);
     return b;
 }
コード例 #3
0
ファイル: TownBuilder.cs プロジェクト: TobieD/City-Generator
        /// <summary>
        /// Spawn a building on the position
        /// </summary>
        private void SpawnBuilding(Vector3 position, GameObject prefab, BuildingSite building)
        {
            var road = building.ParentRoad;

            //Make the building face the road, make a perpendicular line from the building pos to the road
            var lookAtPos = road.FindPerpendicularPointOnLine(new Point(position.x, position.z)).ToVector3();

            //get correct spawn height from the terrain
            position.y = _terrain.SampleHeight(position);
            lookAtPos.y = position.y;

            //Get bounds of the prefab and store them
            var size = prefab.GetPrefabBounds();
            building.Width = (int)size.x;
            building.Height = (int)size.z;

            //don't spawn when there is a collision
            var colliderPos = position;
            colliderPos.y += size.y / 2;
            if (isOverlapping(prefab, position))
            {
                return;
            }

            //instantiate the building
            var go = (GameObject)Object.Instantiate(prefab, position, prefab.transform.rotation);

            //look at the road
            go.transform.LookAt(lookAtPos);

            //flip on Y
            go.transform.RotateAround(position, go.transform.up, 180);
            go.isStatic = true;
            go.SetParent(_buildingParent);

            building.UserData = go;

            //Remove grass and other details around the object
            //RemoveDetailsAroundGameObject((GameObject)go);

            //Add to the buildings list
            _buildings.Add(building);
        }
コード例 #4
0
        public static BuildingSite FromPoint(Point p)
        {
            var b = new BuildingSite(p.X, p.Y);

            return(b);
        }