Esempio n. 1
0
    public void ParseLevel(string filename)
    {
        // Read the file and display it line by line.
        string line;
        bool   timingPointsStart = false;
        bool   hitEventsStart    = false;

        string[] tmp;

        System.IO.StreamReader file = new System.IO.StreamReader(filename);
        while ((line = file.ReadLine()) != null)
        {
            System.Console.WriteLine(line);
            line = line.Trim();
            if (line.Length == 0 || line[0] == '/')
            {
                continue;
            }

            //Debug.Log(line);

            if (line == "[TimingPoints]")
            {
                //Debug.Log("TimingPoints start");
                hitEventsStart    = false;
                timingPointsStart = true;
                continue;
            }
            if (line == "[HitEvents]")
            {
                //Debug.Log("hitobject start");
                hitEventsStart    = true;
                timingPointsStart = false;
                continue;
            }

            if (hitEventsStart)
            {
                //Debug.Log(line);
                tmp = line.Split(',');
                HitEvent hitEvents = new HitEvent();
                hitEvents.setKey(tmp[0]);
                hitEvents.setOffset(tmp[1]);
                hitEvents.setIsNote(tmp[2]);
                hitEvents.setIsMine(tmp[2]);
                hitEvents.setColour(tmp[2]);
                hitEvents.setFlashBlack(tmp[2]);
                hitEvents.setIsHold(tmp[2]);
                if (tmp.Length < 5)
                {
                    if (tmp.Length == 4)
                    {
                        hitEvents.setColorArray(tmp[3]);
                    }
                }
                else
                {
                    hitEvents.setEndOffset(tmp[3]);
                    hitEvents.setColorArray(tmp[4]);
                }
                GameManager.Instance.hitEventsList.Add(hitEvents);
            }

            if (timingPointsStart)
            {
                tmp = line.Split(',');
                TimingPoints timingPoints = new TimingPoints(Convert.ToInt32(tmp[0]), Convert.ToSingle(tmp[1]), Convert.ToInt32(tmp[2]), Convert.ToInt32(tmp[3]), Convert.ToInt32(tmp[4]));
                GameManager.Instance.timingPointsList.Add(timingPoints);
            }
        }
        file.Close();
    }