protected override void MoveLeft(Vector3 pos) { float leftPos = pos.x - (treesSpacing * gridWidth / 2); for (int i = 0; i < gridDepth; i++) { var treesLine = grid[i]; treesLine.position.x = pos.x; var tree = treesLine.trees[treesLine.gridRightIndex]; tree.position = new Vector3(leftPos, tree.position.y, tree.position.z) + GetRandomOffset(tree.scaleIndex); if (tree.treeObject != null) { tree.treeObject.mainTransform.position = tree.position; } treesLine.gridRightIndex -= 1; if (treesLine.gridRightIndex < 0) { treesLine.gridRightIndex = gridWidth - 1; } treesLine.gridLeftIndex -= 1; if (treesLine.gridLeftIndex < 0) { treesLine.gridLeftIndex = gridWidth - 1; } tree.isActive = !RoadSystem.CheckCollision(tree.position); } }
protected override void MoveRight(Vector3 pos) { for (int i = 0; i < gridDepth; i++) { var treesLine = grid[i]; treesLine.position.x = pos.x; uint uniqueTreeId = treesLine.GetTreeUniqueId(treesLine.trees[treesLine.gridRightIndex]) + 1; float rightPos = treesLine.GetPositionXByUniqueId(uniqueTreeId); var tree = treesLine.trees[treesLine.gridLeftIndex]; tree.position = new Vector3(rightPos, treesLine.position.y, treesLine.position.z); tree.position += GetRandomOffset(treesLine, tree, uniqueTreeId); //tree.debugObject.transform.position = tree.position; if (tree.treeObject != null) { pool.Push(tree.treeObject); tree.treeObject = null; } treesLine.gridRightIndex = (treesLine.gridRightIndex + 1) % gridWidth; treesLine.gridLeftIndex = (treesLine.gridLeftIndex + 1) % gridWidth; tree.isActive = !RoadSystem.CheckCollision(tree.position); } }
protected override void ForestMoveZ(int sdi) { if (character.position.z - grid[sdi].position.z > treesSpacing * 3) { var treesLine = grid[sdi]; treesLine.gridLeftIndex = 0; treesLine.gridRightIndex = gridWidth - 1; int indexOfEnd = (sdi + gridDepth - 1) % gridDepth; Vector3 pos = grid[indexOfEnd].position + treesSpacing * groundForward; for (int x = 0; x < gridWidth; x++) { var tree = treesLine.trees[x]; tree.scaleIndex = (int)(3.99f * Random.value); tree.rotationIndex = (int)(3.99f * Random.value); tree.position = pos + (x - gridWidth / 2) * treesSpacing * Vector3.right + GetRandomOffset(tree.scaleIndex); if (tree.treeObject != null) { pool.Push(tree.treeObject); tree.treeObject = null; } tree.isActive = !RoadSystem.CheckCollision(tree.position); } treesLine.position = pos; startGridIndex = (startGridIndex + 1) % gridDepth; } }
protected override void ForestMoveZ(int sdi) { if (character.position.z - grid[sdi].position.z > 30) { var treesLine = grid[sdi]; treesLine.gridLeftIndex = 0; treesLine.gridRightIndex = gridWidth - 1; lastFirstTreeId += treesLine.GetTreesCount(); treesLine.firstTreeId = lastFirstTreeId; int indexOfEnd = (sdi + gridDepth - 1) % gridDepth; var endTreesLine = grid[indexOfEnd]; treesLine.uniqueLineId = endTreesLine.uniqueLineId + 1; treesLine.treesSpacing = spacingController.GetSpacingByUniqueTreesLineId(treesLine.uniqueLineId); Vector3 pos = endTreesLine.position + (endTreesLine.treesSpacing + treesLine.treesSpacing) * 0.5f * groundForward; treesLine.position = pos; float startTreePos = pos.x - (gridWidth / 2) * treesLine.treesSpacing; uint firstTreeLocalId = treesLine.GetLocalTreeId(startTreePos); pos.x = StaticTreesLine.lineLeft + firstTreeLocalId * treesLine.treesSpacing; for (int x = 0; x < gridWidth; x++) { var tree = treesLine.trees[x]; //tree.scaleIndex recalculated in GetRandomOffset tree.rotationIndex = (int)(3.99f * Random.value); pos.x += treesLine.treesSpacing; tree.position = pos; tree.position += GetRandomOffset(treesLine, tree); if (tree.treeObject != null) { pool.Push(tree.treeObject); tree.treeObject = null; } tree.isActive = !RoadSystem.CheckCollision(tree.position); //tree.debugObject.transform.position = tree.position; } startGridIndex = (startGridIndex + 1) % gridDepth; //Debug.Log("Line spacing " + treesLine.treesSpacing + " pos " + treesLine.position); } }