private void InstantiateSkinAsset(string meshCase, bool flipped, Vector2 coords, Transform appendTo, StageSkin skin, bool useSkinMaterial = true) { _basset = Instantiate(skin.GetAsset(meshCase)) as GameObject; _basset.name = "mesh: " + meshCase; if (flipped) { _basset.name += " (flipped)"; } if (useSkinMaterial) { _brenderer = _basset.GetComponent <Renderer>(); _brenderer.material = skin.SkinMaterial; } _basset.transform.position = new Vector3(coords.x, 0f, coords.y); _basset.transform.parent = appendTo; Vector3 scale = _basset.transform.localScale; if (flipped) { scale.x = -scale.x; } scale.x = (float)Math.Round(scale.x, 3); scale.y = (float)Math.Round(scale.y, 3); scale.z = (float)Math.Round(scale.z, 3); _basset.transform.localScale = scale; if (meshCase == "goal_side" && flipped) { _basset.transform.GetChild(0).localScale = new Vector3(-1, 1, 1); } }
private void CreateStreetLight(Vector2 indexes, Vector2 coords, Transform appendTo, StageSkin skin) { bool flipped = true; if (indexes.x == 0) { flipped = false; } InstantiateSkinAsset("street_light", flipped, coords, appendTo, skin, false); }
private void ConstructBlockAssets(Dictionary <string, GameObject> blocksCoords, Vector2 coords, Vector2 indexes, StageSkin skin, Transform parent) { Vector2 adjacentCoords; _bgo = new GameObject(); _bgo.transform.position = new Vector3(coords.x, 0f, coords.y); _bgo.name = "block: " + indexes.x + "_" + indexes.y; _bcollider = _bgo.AddComponent <BoxCollider>(); _bcollider.size = _bsize; _bcollider.center = _bcenter; _bgo.transform.parent = parent; // Ground CreateLayoutBlock(indexes, coords, _bgo.transform, skin); // Back adjacentCoords = new Vector2(coords.x, coords.y + _blockHeight); if (!blocksCoords.ContainsKey(adjacentCoords.x + "_" + adjacentCoords.y)) { CreateLayoutBlock(indexes, adjacentCoords, _bgo.transform, skin, "back"); } // Front adjacentCoords = new Vector2(coords.x, coords.y - _blockHeight); if (indexes.y > 0 && !blocksCoords.ContainsKey(adjacentCoords.x + "_" + adjacentCoords.y)) { CreateLayoutBlock(indexes, adjacentCoords, _bgo.transform, skin, "front"); } // Left adjacentCoords = new Vector2(coords.x - _blockWidth, coords.y); if (indexes.x > 0 && !blocksCoords.ContainsKey(adjacentCoords.x + "_" + adjacentCoords.y)) { CreateLayoutBlock(indexes, adjacentCoords, _bgo.transform, skin, "left"); } // Right adjacentCoords = new Vector2(coords.x + _blockWidth, coords.y); if (indexes.x < GetMaxLanes - 1 && !blocksCoords.ContainsKey(adjacentCoords.x + "_" + adjacentCoords.y)) { CreateLayoutBlock(indexes, adjacentCoords, _bgo.transform, skin, "right"); } // Street Light if (indexes.y < StageLength - 1 && (indexes.x == 0 || indexes.x == GetValidPositions.Length - 1) && (skin.StreetLightAsset != null && _streetLightFrequency > 0)) { if (indexes.y == _nextStreetLight - 1) { CreateStreetLight(indexes, coords, _bgo.transform, skin); } } }
private void CreateLayoutBlock(Vector2 indexes, Vector2 coords, Transform appendTo, StageSkin skin, string direction = "none") { string meshCase; bool flipped = false; if (direction == "left" || direction == "right") { meshCase = "ledge"; if (direction == "left") { flipped = true; } } else { if (indexes.x > 0 && indexes.x < GetMaxLanes - 1) { meshCase = "mid"; } else { meshCase = "side"; if (indexes.x == GetMaxLanes - 1) { flipped = true; } } if (direction == "back" || direction == "front") { meshCase += "_" + direction; } } if (meshCase == "mid" || meshCase == "side" || meshCase == "ledge") { if (indexes.y != 0 && indexes.y % 2 != 0) { meshCase += "_alt"; } } InstantiateSkinAsset(meshCase, flipped, coords, appendTo, skin); }
public GameObject ConstructFinalStage() { Vector2 coords; Vector2 indexes; int iRows; int iLane; string label; float z = GetLowestZ; GameObject result = new GameObject(); result.name = BaseValues.LABEL_STAGE_BLOCKS_RESULT;; StageSkin skin = _stageSkin.GetComponent <StageSkin>(); Dictionary <string, GameObject> blocksCoords = StageCleanup(); _bsize = new Vector3(_blockWidth, _blockColliderHeight, _blockHeight); _bcenter = new Vector3(0f, -_blockColliderHeight / 2, 0f); _nextStreetLight = _streetLightFrequency; // Goal Object GameObject goal = new GameObject(); BoxCollider goalCollider = goal.AddComponent <BoxCollider>(); goalCollider.isTrigger = true; goal.name = BaseValues.TAG_GOAL; goal.tag = BaseValues.TAG_GOAL; goalCollider.size = new Vector3(_blockWidth * GetValidPositions.Length, 4f, _blockHeight / 2); goalCollider.center = new Vector3(0, 2f, 0); goal.transform.parent = result.transform; for (iRows = 0; iRows < StageLength; iRows++) { for (iLane = 0; iLane < GetValidPositions.Length; iLane++) { coords.x = GetValidPositions[iLane]; coords.y = z; indexes.x = iLane; indexes.y = iRows; label = coords.x + "_" + coords.y; if (blocksCoords.ContainsKey(label)) { ConstructBlockAssets(blocksCoords, coords, indexes, skin, result.transform); } // Creates the goal finish line if (iRows == StageLength - 1) { bool goalFlipped = false; string goalLabel = "goal_"; if (iLane > 0 && iLane < GetValidPositions.Length - 1) { goalLabel += "mid"; } else { if (iLane == GetValidPositions.Length - 1) { goalFlipped = true; } goalLabel += "side"; } coords.y = 0; InstantiateSkinAsset(goalLabel, goalFlipped, coords, goal.transform, skin, false); } } if (iRows == StageLength - 1) { goal.transform.position = new Vector3(0, 0, z); } z += GetBlockHeight; if (_streetLightFrequency > 0 && iRows == _nextStreetLight - 1) { _nextStreetLight += _streetLightFrequency; } } gameObject.SetActive(false); return(result); }