Beispiel #1
0
        public static CityData GenerateCity(CitySettings settings, VoronoiDiagram voronoi)
        {
            if (voronoi.VoronoiCells.Count < 1)
            {
                return(null);
            }

            //Create helpers if none are created.
            if (_districtBuilder == null)
            {
                _districtBuilder = new DistrictBuilder();
            }

            //Generate the city
            var cityData = new CityData();

            voronoi.RefreshVoronoi();

            //divide the city into districts
            cityData.Districts = _districtBuilder.CreateCityDistricts(settings, voronoi);

            cityData.Bounds = MathHelpers.GetCityBounds(cityData);

            return(cityData);
        }
        public List<District> CreateCityDistricts(CitySettings settings,VoronoiDiagram voronoi)
        {
            _citySettings = settings;

            //create districts cells from the voronoi cells
            _districtCells = GenerateDistrictCells(voronoi);

            //create districts from the  corresponding district cells
            return settings.DistrictSettings.Select(CreateDistrict).ToList();
        }
        public List <District> CreateCityDistricts(CitySettings settings, VoronoiDiagram voronoi)
        {
            _citySettings = settings;

            //create districts cells from the voronoi cells
            _districtCells = GenerateDistrictCells(voronoi);

            //create districts from the  corresponding district cells
            return(settings.DistrictSettings.Select(CreateDistrict).ToList());
        }
Beispiel #4
0
        public static CityData GenerateCity(CitySettings settings, VoronoiDiagram voronoi)
        {
            if (voronoi.VoronoiCells.Count < 1)
                return null;

            //Create helpers if none are created.
            if (_districtBuilder == null)
            {
                _districtBuilder = new DistrictBuilder();
            }

            //Generate the city
            var cityData = new CityData();

            voronoi.RefreshVoronoi();

            //divide the city into districts
            cityData.Districts = _districtBuilder.CreateCityDistricts(settings,voronoi);

            cityData.Bounds = MathHelpers.GetCityBounds(cityData);

            return cityData;
        }
Beispiel #5
0
        /// <summary>
        /// Initialize this viewModel
        /// </summary>
        public void Initialize(DrawService drawService)
        {
            //initialize draw service
            _drawService = drawService;
            //_drawService.OnClick += OnClick;

            //create empty voronoi Diagram
            _points = new List<Point>();
            _voronoiDiagram = new VoronoiDiagram();
            _cityData = new CityData();

            _citySettings = new CitySettings();

            //seed for random generation
            Seed = DateTime.Now.GetHashCode();

            //store default settings
            foreach (var districtType in _districtTypes)
            {
                DistrictSettings.Add(new DistrictSettings(districtType));
                break;
            }

            RaisePropertyChanged("DistrictSettings");

            //debug for math test and drawing
            MathTesting();
        }
        /// <summary>
        /// set required data for generating the terrain
        /// </summary>
        public void InitializeSettings(TerrainSettings terrainSettings, GenerationSettings voronoiSettings, GameObject parent, CitySettings citySettings)
        {
            //store settings
            _terrainSettings = terrainSettings;
            _voronoiSettings = voronoiSettings;
            _citySettings = citySettings;
            _parentGameObject = parent;

            //initialize noise
            //if no seed is specified generate a random one
            if (!terrainSettings.UseSeed)
            {
                _terrainSettings.GroundSeed = Random.Range(int.MinValue, int.MaxValue);
                _terrainSettings.MountainSeed = Random.Range(int.MinValue, int.MaxValue);
                _terrainSettings.TreeSeed = Random.Range(int.MinValue, int.MaxValue);
                _terrainSettings.DetailSeed = Random.Range(int.MinValue, int.MaxValue);
            }

            //create noise
            _groundNoise = new PerlinNoise(_terrainSettings.GroundSeed);
            _treeNoise = new PerlinNoise(_terrainSettings.TreeSeed);
            _detailNoise = new PerlinNoise(_terrainSettings.DetailSeed);

            //calculate total size of 1 terrain tile based on the city bounds
            _terrainSize = (int)(_voronoiSettings.Width * 2f);

            _grassLayers = 0;
            _meshLayers = 0;

            //create the prototypes used by the generator
            CreatePrototypes();
        }
        /// <summary>
        /// Initialize base settings
        /// </summary>
        public void Initialize()
        {
            //create a town generator object when it doesn't exist yet
            if (_townGenerator != null) return;

            //Access towngenerator
            _townGenerator = TownGenerator.GetInstance();

            //Set default settings
            _generationSettings = new GenerationSettings
            {
                VoronoiAlgorithm = VoronoiAlgorithm.Fortune,
                PointAlgorithm = PointGenerationAlgorithm.CityLike
            };

            //City settings
            _citySettings = new CitySettings();
            _citySettings.DebugMode = false;

            //Create a base district type
            CreatePrefabSelection("Grass");

            //Terrain settings editor
            _terrainEditor = new TerrainEditor(new TerrainSettings(), this);

            //Define a style for the foldout
            _foldoutStyle = new GUIStyle(EditorStyles.foldout)
            {
                fontStyle = FontStyle.Bold,
            };

            var c = Color.black;
            _foldoutStyle.onActive.textColor = c;
            _foldoutStyle.normal.textColor = c;
            _foldoutStyle.onNormal.textColor = c;
            _foldoutStyle.hover.textColor = c;
            _foldoutStyle.onHover.textColor = c;
            _foldoutStyle.focused.textColor = c;
            _foldoutStyle.onFocused.textColor = c;
            _foldoutStyle.active.textColor = c;
            _foldoutStyle.onActive.textColor = c;
        }