private void GetRailGridFromFile(TextAsset level) { string[] lines = SplitOnNewline(level.text); int gridHeight = lines.Length; int gridWidth = lines[0].Length; railGrid = new Rail[gridHeight, gridWidth]; for (int y = 0; y < gridHeight; y++) { string line = lines[y]; for (int x = 0; x < gridWidth; x++) { Vector3 pos = new Vector3(x * cellSize, 0, y * cellSize); char railChar = line[x]; Rail rail = GetRail(railChar, pos); railGrid[y, x] = rail; if (rail != null) { _waypoints.AddRange(rail.GetWaypoints()); } } } WeldRailParts(); }
private Rail GetRail(char rail, Vector3 pos) { /* * t = top * b = bottom * l = left * r = right * - = vertical * | = horizontal * x = free cell * s = spawnPoint */ switch (rail) { case '-': return(((GameObject)Instantiate(straightNS, pos, Quaternion.identity, transform)).GetComponent <Rail>()); case '|': return(((GameObject)Instantiate(straightOW, pos, Quaternion.identity, transform)).GetComponent <Rail>()); case 't': return(((GameObject)Instantiate(curveSW, pos, Quaternion.identity, transform)).GetComponent <Rail>()); case 'b': return(((GameObject)Instantiate(curveNW, pos, Quaternion.identity, transform)).GetComponent <Rail>()); case 'l': return(((GameObject)Instantiate(curveSE, pos, Quaternion.identity, transform)).GetComponent <Rail>()); case 'r': return(((GameObject)Instantiate(curveNE, pos, Quaternion.identity, transform)).GetComponent <Rail>()); case 's': // TODO lagerhallen model Rail spawnRail = ((GameObject)Instantiate(straightNS, pos, Quaternion.identity, transform)).GetComponent <Rail>(); spawnWaypoint = spawnRail.GetWaypoints()[0]; return(spawnRail); case 'x': return(null); default: throw new InvalidEnumArgumentException(); } }