Exemplo n.º 1
0
    public static ClapWaveSequence LoadSequenceFile(string fileName, float timePerBeat)
    {
        ClapWaveSequence waveSequence = new ClapWaveSequence();
        StreamReader reader = null;
        try
        {
            string filePath = Path.Combine(Application.streamingAssetsPath, fileName);
            if (filePath.Contains("://"))
            { //android mobile
                string newPath = Path.Combine(Application.persistentDataPath, fileName);
                if (!File.Exists(newPath))
                {
                    WWW www = new WWW(filePath);
                    while (!www.isDone) {; }                // Wait for download to complete - not pretty at all but easy hack for now
                    if (System.String.IsNullOrEmpty(www.error))
                    {
                        File.WriteAllBytes(newPath, www.bytes);
                    }

                }
                filePath = newPath;
            }
            reader = new StreamReader(filePath, System.Text.Encoding.Default);
        }
        catch (System.Exception e)
        {
            Debug.LogWarning("Cant read \"" + fileName + "\"" + e.StackTrace);
            return null;
        }
        string line = reader.ReadLine();

        do
        {
            bool[] claps = new bool[GameProperties.NUMBER_OF_COLORS];
            if (line[0] == BARIER[0])
            {
                line = reader.ReadLine();
                continue;
            }

            for (int i = 0; i < GameProperties.NUMBER_OF_COLORS; i++)
                claps[i] = line[i] != NONE;
            bool hold = line.Length > GameProperties.NUMBER_OF_COLORS && line[GameProperties.NUMBER_OF_COLORS] == HOLD;
            bool release = line.Length > GameProperties.NUMBER_OF_COLORS && line[GameProperties.NUMBER_OF_COLORS] == RELEASE;
            ClapWave wave = new ClapWave(claps, hold, release);
            waveSequence.Add(wave);

            /*
            Debug.Log(line);
            Debug.Log(wave.ToString());
            */
            line = reader.ReadLine();
        } while (line != null);

        waveSequence.GenerateTimeStamps(timePerBeat);
        return waveSequence;
    }
Exemplo n.º 2
0
    public static ClapWaveSequence LoadSequenceFile(string fileName, float timePerBeat)
    {
        ClapWaveSequence waveSequence = new ClapWaveSequence();
        StreamReader reader = null;
        try
        {
          string filePath = Path.Combine(Application.streamingAssetsPath, fileName);
          reader = new StreamReader(filePath, System.Text.Encoding.Default);
        }
        catch (System.Exception e)
        {
          Debug.LogWarning("Cant read \"" + fileName + "\"" + e.StackTrace);
          return null;
        }
        string line = reader.ReadLine();

        do
        {
            bool[] claps = new bool[GameProperties.NUMBER_OF_COLORS];
          if (line[0] == BARIER[0])
          {
        line = reader.ReadLine();
        continue;
          }

          for (int i = 0; i < GameProperties.NUMBER_OF_COLORS; i++)
        claps[i] = line[i] != NONE;
          bool hold = line.Length > GameProperties.NUMBER_OF_COLORS && line[GameProperties.NUMBER_OF_COLORS] == HOLD;
          bool release = line.Length > GameProperties.NUMBER_OF_COLORS && line[GameProperties.NUMBER_OF_COLORS] == RELEASE;
          ClapWave wave = new ClapWave(claps, hold, release);
          waveSequence.Add(wave);

          /*
          Debug.Log(line);
          Debug.Log(wave.ToString());
          */
          line = reader.ReadLine();
        } while (line != null);

        waveSequence.GenerateTimeStamps(timePerBeat);
        return waveSequence;
    }