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


C# Level.SetCharMap方法代码示例

本文整理汇总了C#中Level.SetCharMap方法的典型用法代码示例。如果您正苦于以下问题:C# Level.SetCharMap方法的具体用法?C# Level.SetCharMap怎么用?C# Level.SetCharMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Level的用法示例。


在下文中一共展示了Level.SetCharMap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateLevel

 /**
  * @brief Create level parse from file.
  *
  * @param int levelNo
  * @return Level
  **/
 public void CreateLevel(int levelNo, List<Enemy> ignoreEnemies)
 {
     Dictionary<Vector2, char> charMap = new Dictionary<Vector2, char>();
     TextAsset asset = (TextAsset)Resources.Load ("Levels/Level" + levelNo.ToString (), typeof(TextAsset));
     levelObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
     levelObject.renderer.enabled = false;
     levelObject.name = "Level" + levelNo;
     string[] lines = asset.text.Split ('\n');
     int width = 0;
     int height = lines.Length;
     for (int y = 0; y < lines.Length; ++y) {
         string line = lines [y];
         for (int x = 0; x < line.Length; ++x) {
             if (line.Length > width)
                 width = line.Length;
             char c = line [x];
             charMap.Add (new Vector2 (x, y), c);
         }
     }
     Level level = new Level (levelNo, width, height);
     this.level = level;
     level.SetCharMap(charMap);
     foreach (Vector2 key in charMap.Keys) {
         Vector3 position = this.MatrixToPosition(key);
         int x = (int)key.x;
         int y = (int)key.y;
         Vector2 p = new Vector2(x, y);
         char c = charMap[p];
         if (level.IsFloor(x, y)) {
             GameObject floorPrefab = (GameObject)Resources.Load ("Prefabs/floorPrefab", typeof(GameObject));
             GameObject floor = (GameObject)Instantiate (floorPrefab, position, Quaternion.identity);
             floor.transform.parent = levelObject.transform;
             level.SetObject(p, floor);
         }
         if (level.IsRoute(x, y)) {
             GameObject routePrefab = null;
             if (this.level.IsFloor(x + 1, y) || this.level.IsFloor(x - 1, y) || this.level.IsFloor(x, y + 1) || this.level.IsFloor(x, y - 1)) {
                 routePrefab = (GameObject)Resources.Load ("Prefabs/routeEntrancePrefab", typeof(GameObject));
             } else {
                 routePrefab = (GameObject)Resources.Load ("Prefabs/routePrefab", typeof(GameObject));
             }
             GameObject route = (GameObject)Instantiate (routePrefab, position, Quaternion.identity);
             route.transform.parent = levelObject.transform;
             // if route is placed holizontally, rotate object.
             if (level.IsRoute(x - 1, y) || level.IsRoute(x + 1, y)) {
                 route.transform.Rotate (new Vector3 (0, 90, 0));
             }
             level.SetObject(p, route);
             // add Gate
             if (char.IsUpper(c)) {
                 GameObject gatePrefab = (GameObject)Resources.Load("Prefabs/gatePrefab", typeof(GameObject));
                 this.AddGate(route, gatePrefab);
             } else if (c == '|') {
                 GameObject gatePrefab = (GameObject)Resources.Load("Prefabs/autoGatePrefab", typeof(GameObject));
                 this.AddGate(route, gatePrefab);
             }
         } else if (level.IsWall(x, y)) {
             GameObject wallPrefab = null;
             GameObject wall = null;
             bool isHorizontal = level.IsFloor(x - 1, y) ^ level.IsFloor(x + 1, y);
             bool isCurve = false;
             bool isCorner = false;
             if (c == '#') {
                 if ((level.IsWall(x + 1, y) && level.IsWall(x, y + 1)) ||
                     (level.IsWall(x + 1, y) && level.IsWall(x, y - 1)) ||
                     (level.IsWall(x - 1, y) && level.IsWall(x, y + 1)) ||
                     (level.IsWall(x - 1, y) && level.IsWall(x, y - 1)) ) {
                     wallPrefab = (GameObject)Resources.Load ("Prefabs/cornerWallPrefab", typeof(GameObject));
                     isCorner = true;
                 } else if (isHorizontal) {
                     wallPrefab = (GameObject)Resources.Load ("Prefabs/curveWallPrefab", typeof(GameObject));
                     isCurve = true;
                 } else {
                     // Normal Wall
                     wallPrefab = (GameObject)Resources.Load ("Prefabs/wallPrefab", typeof(GameObject));
                 }
             } else if (char.IsLower(c)) {
                 // corner Wall
                 wallPrefab = (GameObject)Resources.Load ("Prefabs/switchWallPrefab", typeof(GameObject));
             } else if (c == '$') {
                 // Broken Wall
                 wallPrefab = (GameObject)Resources.Load ("Prefabs/brokenWallPrefab", typeof(GameObject));
             } else if (c == '%') {
                 // Window Wall
                 wallPrefab = (GameObject)Resources.Load ("Prefabs/windowWallPrefab", typeof(GameObject));
             }
             wall = (GameObject)Instantiate(wallPrefab, position, Quaternion.identity);
             if (isCurve) {
                 if (level.IsFloor(x - 1, y)) {
                     wall.transform.Rotate (new Vector3 (0, 180, 0));
                 }
             } else {
                 if (isCorner) {
                     // cornerWall
//.........这里部分代码省略.........
开发者ID:giginet,项目名称:PanicColony,代码行数:101,代码来源:LevelManager.cs


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