本文整理汇总了C#中FileReader.textAssetToStrArray方法的典型用法代码示例。如果您正苦于以下问题:C# FileReader.textAssetToStrArray方法的具体用法?C# FileReader.textAssetToStrArray怎么用?C# FileReader.textAssetToStrArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader.textAssetToStrArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: generateMapFromFile
void generateMapFromFile(string name)
{
FileReader fr = new FileReader();
string[] mapArr = fr.textAssetToStrArray(name);
map = new List<List<Tile>>();
GameObject tilePrefab;
int xCoord = 0;
MapWidth = mapArr.Length;
foreach (string line in mapArr) // for each column
{
// The finished product we're building
List<Tile> column = new List<Tile>();
// The bits of the file we're building from
string[] tileStrArr = line.Split(new string[] { ";" }, StringSplitOptions.None);
int yCoord = 0;
MapHeight = tileStrArr.Length;
foreach (string tileStr in tileStrArr)
{
string[] attributes = tileStr.Split(new string[] { "," }, StringSplitOptions.None);
string env = attributes[0]; //Get string representation of tile type
int height = Int32.Parse(attributes[1]); //get int representation of tile height
Vector3 position = new Vector3(xCoord, (height / 4.0f), yCoord);
Quaternion rotation = Quaternion.Euler(new Vector3());
switch (height) // Set height
{
case 1:
tilePrefab = TilePrefab_e0;
break;
case 2:
tilePrefab = TilePrefab_e1;
break;
case 3:
tilePrefab = TilePrefab_e2;
break;
default:
tilePrefab = TilePrefab_e0;
break;
}
GameObject block = Instantiate(tilePrefab, position, rotation) as GameObject;
Tile tile = block.GetComponent<Tile>();
switch (env) // Create block based on height, type
{
case "barrier":
tile.setEnvironment("barrier");
break;
case "stone":
tile.setEnvironment("stone");
break;
case "grass":
tile.setEnvironment("grass");
GameObject bsh = Instantiate(decoBush, position, rotation) as GameObject;
break;
case "plains":
tile.setEnvironment("plains");
break;
case "forest":
tile.setEnvironment("forest");
break;
}
tile.gridPosition = new Vector2(xCoord, yCoord); // Add tile's own position on grid to the tile
column.Add(tile); // Add tile to the column
yCoord += 1; // Increment yCoord for next run
}
map.Add(column); //Add column to map
xCoord += 1; //Increment xCoord for next run
}
// Initialize center holder values
mapcenterX = MapWidth / 2;
mapcenterY = MapHeight / 2;
mapCenter = new Vector3(mapcenterX, 0.0f, mapcenterY);
groundPlane.transform.position = mapCenter;
//set camera position to the center of the map
//maybe do something like this whenever the controlling team switches, set camera position to average
// position of the new team
GameObject.Find("CameraCenter").transform.position = new Vector3(mapcenterX, 0, mapcenterY);
Instantiate(groundPlane, mapCenter, Quaternion.Euler(new Vector3()));
}