public void CreateProceduralScene() { var floorWidgetsCount = Mathf.RoundToInt(_random.RandomFloat(_floorWidgetsCountRange.x, _floorWidgetsCountRange.y)); var floorWidgetsPossibilities = new List <Action <GameObject> >() { (g) => { var widget = g.AddComponent <CrossLineWidget>(); RandomizeCrossLineWidget(widget); }, (g) => { var widget = g.AddComponent <RingWidget>(); RandomizeRingWidget(widget); }, (g) => { var widget = g.AddComponent <SquareRingWidget>(); RandomizeSquareRingWidget(widget); } }; for (int i = 0; i < floorWidgetsCount; i++) { _random.RandomElement(floorWidgetsPossibilities).Invoke(_sceneGenerator._floorGenerator.gameObject); } var wallsCount = Mathf.RoundToInt(_random.RandomFloat(_wallsCountRange.x, _wallsCountRange.y)); for (int i = 0; i < wallsCount; i++) { var wallLength = _random.RandomFloat(_wallsLengthRange.x, _wallsLengthRange.y); var startPoint = new Vector2(_random.RandomFloat(0, 1), _random.RandomFloat(0, 1)); var angle = _random.RandomFloat(Mathf.PI * 2); var endPoint = startPoint + new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)) * wallLength; var wallWidget = _sceneGenerator._wallsGenerator.gameObject.AddComponent <SingleWallWidget>(); wallWidget._startPoint = startPoint; wallWidget._endPoint = endPoint; } var orbitingWallsCount = Mathf.RoundToInt(_random.RandomFloat(_orbitingWallsCountRange.x, _orbitingWallsCountRange.y)); for (int i = 0; i < orbitingWallsCount; i++) { var angleLength = _random.RandomFloat(_orbitingWallsAngleLengthRange.x, _orbitingWallsAngleLengthRange.y); var radius = _random.RandomFloat(0.2f, 0.5f); var startAngle = _random.RandomFloat(Mathf.PI * 2); var startPoint = new Vector2(Mathf.Sin(startAngle), Mathf.Cos(startAngle)) * radius + new Vector2(0.5f, 0.5f); var endAngle = startAngle + angleLength; var endPoint = new Vector2(Mathf.Sin(endAngle), Mathf.Cos(endAngle)) * radius + new Vector2(0.5f, 0.5f); var wallWidget = _sceneGenerator._wallsGenerator.gameObject.AddComponent <SingleWallWidget>(); wallWidget._startPoint = startPoint; wallWidget._endPoint = endPoint; } _sceneGenerator._floorSize = new Vector2Int(_random.RandomInt(_floorSizeRange.x, _floorSizeRange.y), _random.RandomInt(_floorSizeRange.x, _floorSizeRange.y)); _sceneGenerator.Generate(); _waterTile.transform.localScale = new Vector3(_sceneGenerator._floorSize.x * 0.02985f, 1, _sceneGenerator._floorSize.y * 0.02985f); }
public override void AddProps(PropsSpecification propsSpecification, FloorSpecification floorSpecification) { var propsCount = Mathf.RoundToInt(floorSpecification.Size.x * floorSpecification.Size.y * _propsDensity); for (int i = 0; i < propsCount; i++) { var coords = new Vector2Int(_random.RandomInt(floorSpecification.Size.x), _random.RandomInt(floorSpecification.Size.y)); var angle = _random.RandomElement(new List <float>() { 0, 90, 180, 270 }); var propPrefab = _random.RandomElement(_possibleProps); if (floorSpecification.FloorPresenceArray[coords.x, coords.y]) { propsSpecification.SetDefinition(coords, new PropInstanceDefinition() { Angle = angle, Prefab = propPrefab }); } } }
public override void AddProps(PropsSpecification propsSpecification, FloorSpecification floorSpecification) { var propsGroupsCount = Mathf.RoundToInt(floorSpecification.Size.x * floorSpecification.Size.y * _propsGroupsDensity); for (int i = 0; i < propsGroupsCount; i++) { var coords = new Vector2Int(_random.RandomInt(floorSpecification.Size.x), _random.RandomInt(floorSpecification.Size.y)); var groupRadius = Mathf.CeilToInt(_random.RandomFloat(_groupRadiusRange.x, _groupRadiusRange.y)); var countInGroup = _random.RandomFloat(_propsDensityPerGroupRange.x, _propsDensityPerGroupRange.y) * (groupRadius + 1) * (groupRadius + 1); for (int j = 0; j < countInGroup; j++) { var thisPropCoords = coords + new Vector2Int(_random.RandomInt(-groupRadius, groupRadius), _random.RandomInt(-groupRadius, groupRadius)); if (thisPropCoords.x >= 0 && thisPropCoords.y >= 0 && thisPropCoords.x < floorSpecification.Size.x && thisPropCoords.y < floorSpecification.Size.y) { var angle = _random.RandomFloat(0, 360); var propPrefab = _random.RandomElement(_possibleProps); var offsetFromCenter = new Vector2(_random.RandomFloat(-0.5f, 0.5f), _random.RandomFloat(-0.5f, 0.5f)); if (floorSpecification.FloorPresenceArray[thisPropCoords.x, thisPropCoords.y]) { propsSpecification.SetDefinition(thisPropCoords, new PropInstanceDefinition() { Angle = angle, Prefab = propPrefab, OffsetFromCenter = offsetFromCenter }); } } } } }