private void AddTerrainStrip() { if (_unusedStrips.Count > 0) { int stripKey = _unusedStrips.Pop(); TerrainStrip unusedStrip = _stripPool[stripKey]; unusedStrip.gameObject.transform.position = new Vector3(0, 0, _lastStripPos); //In the future we not doing this randomly or at all; the TS will just grab the prop based on terrain type TerrainInfo newTerrainInfo = CreateWeightedTerrainInfo(); //Ugly ugly code; need a better way of defining rules for terrain strips if (newTerrainInfo.type == TerrainType.Grass) { unusedStrip.ReassignTerrainStrip(newTerrainInfo, TerrainProps[0]); } else if (newTerrainInfo.type == TerrainType.River) { float randValue = Random.value; if (randValue <= .75f) { unusedStrip.ReassignTerrainStrip(newTerrainInfo, TerrainProps[1], true); } else if (_stripPool[_lastStripPos - 1].Type != TerrainType.River || (_stripPool[_lastStripPos - 1].Type == TerrainType.River && _stripPool[_lastStripPos - 1].IsMovable)) { unusedStrip.ReassignTerrainStrip(newTerrainInfo, TerrainProps[1]); } else { unusedStrip.ReassignTerrainStrip(newTerrainInfo, TerrainProps[1], true); } } else if (newTerrainInfo.type == TerrainType.Road) { unusedStrip.ReassignTerrainStrip(newTerrainInfo, default(Prop), true); } else { unusedStrip.ReassignTerrainStrip(newTerrainInfo); } _stripPool.Add(_lastStripPos, unusedStrip); _stripPool.Remove(stripKey); _lastStripPos++; } else { AddNewStrip(); } }
private void OnDestroy() { TerrainStrip.StripInactive -= OnStripInactive; TerrainStrip.ResetCurrentCell(); }
private void OnStripInactive(TerrainStrip strip) { _unusedStrips.Push(strip.zPosKey); AddTerrainStrip(); }