private Prop PlaceProp(Prop prop, Vector3 placement) { Prop cellProp = prop; cellProp.gameObject = TerrainStripFactory.GetUsablePropFromPool(prop); cellProp.gameObject.transform.position = new Vector3(placement.x, 1 + prop.yOffset, placement.z); cellProp.gameObject.SetActive(true); return(cellProp); }
private void Awake() { if (_sharedInstance != null) { Destroy(gameObject); return; } _sharedInstance = this; }
private void SetupRiverType() { //All these values need balancing float speed = TerrainStripFactory.RandomRangeExcept(1, 3, _lastStripSpeed); int propOffset = TerrainStripFactory.RandomRangeExcept(4, 6, _lastPropOffset); int numProps = Random.Range(3, 5); for (int i = 0; i < numProps; i++) { MovableProp tempMovableProp = GetUsablePropFromPool(MovablePropType.LOG); tempMovableProp.transform.position = new Vector3((-9f * _logDirection) + (i * propOffset * _logDirection), 0.5f, zPos); tempMovableProp.transform.rotation = Quaternion.Euler(tempMovableProp.transform.eulerAngles.x, 90 * _logDirection, 0); tempMovableProp.Speed = speed; tempMovableProp.Direction = new Vector3(_logDirection, 0, 0); tempMovableProp.gameObject.SetActive(true); tempMovableProp.Type = MovablePropType.LOG; _movableProps.Add(tempMovableProp); } }
private void SetupRoadType() { //All these values need balancing float speed = TerrainStripFactory.RandomRangeExcept(1.5f, 3, _lastStripSpeed); int propOffset = TerrainStripFactory.RandomRangeExcept(3, 6, _lastPropOffset); int numProps = TerrainStripFactory.RandomRangeExcept(3, 5, _lastNumProps); int randomSign = Random.Range(0, 2) * 2 - 1; int carChoice = TerrainStripFactory.RandomRangeExcept(0, _usableRoadTypes.Length, _lastCarChoice); for (int i = 0; i < numProps; i++) { MovableProp tempMovableProp = GetUsablePropFromPool(_usableRoadTypes[carChoice]); tempMovableProp.transform.position = new Vector3((-9f * randomSign) + (i * propOffset * randomSign), 0.7f, zPos); tempMovableProp.transform.rotation = Quaternion.Euler(tempMovableProp.transform.eulerAngles.x, 90 * randomSign, 0); tempMovableProp.Speed = speed; tempMovableProp.Direction = new Vector3(randomSign, 0, 0); tempMovableProp.gameObject.SetActive(true); _movableProps.Add(tempMovableProp); } }
private void CreateCells(Prop prop = new Prop()) { float xPosBase = -9.5f; //Left most x position on TerrainStrip; offset by .5 to get center float xPosIncrement = 1; float zPos = transform.position.z; for (int i = 0; i < _cells.Capacity; i++) { // Chance of prop beign spawned in a cell int objectChance; //Also very ugly code; need a better way of setting prop rules for strip if (i < 6 || i > 13) { objectChance = (Type == TerrainType.River) ? 0 : Random.Range(1, 3); //balance this } else { objectChance = Random.Range(1, 7); } if (_lastTerrainType == TerrainType.Grass && Type == TerrainType.River && _inaccessibleCells.Contains(i)) { objectChance = 2; } if (_lastTerrainType == TerrainType.River && Type == TerrainType.Grass && !_inaccessibleCells.Contains(i)) { objectChance = 2; } if (zPosKey < 3 && i == 10) { objectChance = 2; } Cell tempCell = new Cell(); tempCell.gridPos = new Vector3(xPosBase + (i * xPosIncrement), 0, zPos); if (!IsMovable && objectChance == 1 && prop.propPrefab != null) { Prop cellProp = PlaceProp(prop, tempCell.gridPos); _testProps.Add(cellProp); tempCell.accessible = cellProp.propAccessibility; if (!tempCell.accessible) { _tempInaccessibleCells.Add(i); } } else if (Type == TerrainType.River) { tempCell.accessible = false; if (i < 6 || i > 13) { _tempInaccessibleCells.Add(i); } } else if (i < 6 || i > 13) { tempCell.accessible = false; } else { tempCell.accessible = true; } _cells.Add(tempCell); } if (!IsMovable && _testProps.Count < 1 && prop.propPrefab != null) { int randomCellNum = Random.Range(6, 13); if (zPosKey == 0) { randomCellNum = TerrainStripFactory.RandomRangeExcept(6, 13, 10); } Cell tempCell = _cells[randomCellNum]; Prop cellProp = PlaceProp(prop, tempCell.gridPos); _testProps.Add(cellProp); tempCell.accessible = cellProp.propAccessibility; _cells[randomCellNum] = tempCell; } _inaccessibleCells = _tempInaccessibleCells; _lastTerrainType = Type; }