当前位置: 首页>>代码示例>>C#>>正文


C# FileReader.textAssetToStrArray方法代码示例

本文整理汇总了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()));
    }
开发者ID:point01,项目名称:Square-Wars,代码行数:91,代码来源:GameManager.cs


注:本文中的FileReader.textAssetToStrArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。