示例#1
0
    // Use this for initialization
    void Start()
    {
        TextAsset levelData = Resources.Load("LevelData") as TextAsset;
        StringReader sr = new StringReader(levelData.text);
        using (sr)
        {
            string line;
            line = sr.ReadLine();

            while(line != null)
            {
                // Get the level name
                string name  = line;

                int[,] h = new int[levelHeight, levelWidth];

                // Get the level height map
                sr.ReadLine();
                for(int i = 0; i < levelHeight; i++)
                {
                    line = sr.ReadLine();
                    string[] row_values = line.Split((string[])null, System.StringSplitOptions.None);
                    for(int j = 0; j < levelWidth; j++)
                    {
                        h[i,j] = int.Parse(row_values[j]);
                    }
                }

                char[,] f = new char[levelHeight, levelWidth];

                // Get the level feature map
                sr.ReadLine();
                for(int i = 0; i < levelHeight; i++)
                {
                    line = sr.ReadLine();
                    string[] row_values = line.Split((string[])null, System.StringSplitOptions.None);
                    for(int j = 0; j < levelWidth; j++)
                    {
                        f[i,j] = char.Parse(row_values[j]);
                    }
                }

                sr.ReadLine();
                line = sr.ReadLine();
                Dictionary<int[], int[]> d = new Dictionary<int[], int[]>();
                while(line != "-")
                {
                    string[] row_values = line.Split((string[])null, System.StringSplitOptions.None);
                    int[] key = new int[2] {int.Parse (row_values[0]), int.Parse (row_values[1])};
                    int[] val = new int[2] {int.Parse (row_values[2]), int.Parse (row_values[3])};
                    d[key] = val;
                    line = sr.ReadLine();
                }
                Level l = new Level(name, h, f, d);
                l.print();

                levels.Add(l);
                Debug.Log ("level added.");
                Debug.Log (levels.Count);

                line = sr.ReadLine();
            }
        }
    }