コード例 #1
0
    void AddJSFXSounds(string[] filenames)
    {
        foreach (string filename in filenames)
        {
            string   content = System.IO.File.ReadAllText(filename);
            string[] lines   = content.Split(s_lineDelims, System.StringSplitOptions.None);
            int      lineNo  = 0;
            foreach (string lineStr in lines)
            {
                ++lineNo;
                string line = lineStr.Split('#')[0].Split('/')[0].Split(';')[0].Trim();
                if (line.Length == 0)
                {
                    continue;
                }

                // TODO remove comments
                Match m = s_jsfxRE.Match(line);
                if (!m.Success)
                {
                    Debug.LogError(filename + " line: " + lineNo + " could not parse line");
                    continue;
                }
                string   name          = m.Groups[1].Value;
                string   generator     = m.Groups[2].Value;
                string   numbersString = m.Groups[3].Value;
                string[] numberStrings = numbersString.Split(',');
                if (numberStrings.Length != 27)
                {
                    Debug.LogError(filename + " line:" + lineNo + " expected 27 values found " + numberStrings.Length);
                    continue;
                }

                float[] parameters = new float[27];
                int     i          = 0;
                bool    error      = false;
                foreach (string numstr in numberStrings)
                {
                    try
                    {
                        parameters[i] = float.Parse(numstr, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                    }
                    catch (System.Exception)
                    {
                        Debug.LogError(filename + " line:" + lineNo + " could not parse number " + numstr);
                        error = true;
                    }
                    ++i;
                }

                if (error)
                {
                    continue;
                }

                s_sounds[name] = new SoundJSFX(generator, parameters);
            }
        }
    }
コード例 #2
0
    void AddJSFXSounds(string[] filenames)
    {
        foreach(string filename in filenames)
        {
          byte[] bytes = null;
          if (!HFTWebFileDB.GetInstance().GetFile(filename, out bytes))
          {
        Debug.LogError("no such file: " + filename);
          }
          string content = System.Text.Encoding.UTF8.GetString(bytes);
          string[] lines = content.Split(s_lineDelims, System.StringSplitOptions.None);
          int lineNo = 0;
          foreach (string lineStr in lines)
          {
        ++lineNo;
        string line = lineStr.Split('#')[0].Split('/')[0].Split(';')[0].Trim();
        if (line.Length == 0)
        {
          continue;
        }

        // TODO remove comments
        Match m = s_jsfxRE.Match(line);
        if (!m.Success)
        {
          Debug.LogError(filename + " line: " + lineNo + " could not parse line");
          continue;
        }
        string name = m.Groups[1].Value;
        string generator = m.Groups[2].Value;
        string numbersString = m.Groups[3].Value;
        string[] numberStrings = numbersString.Split(',');
        if (numberStrings.Length != 27)
        {
          Debug.LogError(filename + " line:" + lineNo + " expected 27 values found " + numberStrings.Length);
          continue;
        }

        float[] parameters = new float[27];
        int i = 0;
        bool error = false;
        foreach (string numstr in numberStrings)
        {
          try
          {
            parameters[i] = float.Parse(numstr, System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
          }
          catch (System.Exception)
          {
            Debug.LogError(filename + " line:" + lineNo + " could not parse number " + numstr);
            error = true;
          }
          ++i;
        }

        if (error)
        {
          continue;
        }
        s_sounds[name] = new SoundJSFX(generator, parameters);
          }
        }
    }