Пример #1
0
 public AudioControl()
 {
     soundsCount = 0;
     sounds      = new Sound_[soundsMax];
     for (int i = 0; i < soundsMax; i++)
     {
         sounds[i] = null;
     }
 }
Пример #2
0
 public void Add(Sound_ s)
 {
     for (int i = 0; i < soundsCount; i++)
     {
         if (sounds[i] == null)
         {
             sounds[i] = s;
             return;
         }
     }
     if (soundsCount < soundsMax)
     {
         sounds[soundsCount++] = s;
     }
 }
Пример #3
0
 public void Add(Sound_ s)
 {
     for (int i = 0; i < soundsCount; i++)
     {
         if (sounds[i] == null)
         {
             sounds[i] = s;
             return;
         }
     }
     if (soundsCount < soundsMax)
     {
         sounds[soundsCount++] = s;
     }
 }
Пример #4
0
    public override void OnNewFrame(Game game, NewFrameEventArgs args)
    {
        if (game.assetsLoadProgress.value != 1)
        {
            return;
        }

        if (!wasLoaded)
        {
            wasLoaded = true;
            Preload(game);
        }

        // Load audio
        for (int i = 0; i < game.audio.soundsCount; i++)
        {
            Sound_ sound = game.audio.sounds[i];
            if (sound == null)
            {
                continue;
            }
            if (sound.audio != null)
            {
                continue;
            }

            AudioData data = GetAudioData(game, sound.name);
            if (game.platform.AudioDataLoaded(data))
            {
                sound.audio = game.platform.AudioCreate(data);
                game.platform.AudioPlay(sound.audio);
            }
        }

        // Update audio position
        for (int i = 0; i < game.audio.soundsCount; i++)
        {
            Sound_ sound = game.audio.sounds[i];
            if (sound == null)
            {
                continue;
            }
            if (sound.audio == null)
            {
                continue;
            }
            game.platform.AudioSetPosition(sound.audio, sound.x, sound.y, sound.z);
        }

        // Stop audio
        for (int i = 0; i < game.audio.soundsCount; i++)
        {
            Sound_ sound = game.audio.sounds[i];
            if (sound == null)
            {
                continue;
            }
            if (sound.audio == null)
            {
                continue;
            }
            if (sound.stop)
            {
                game.platform.AudioDelete(sound.audio);
                game.audio.sounds[i] = null;
            }
        }

        // Finish or loop audio
        for (int i = 0; i < game.audio.soundsCount; i++)
        {
            Sound_ sound = game.audio.sounds[i];
            if (sound == null)
            {
                continue;
            }
            if (sound.audio == null)
            {
                continue;
            }
            if (sound.loop)
            {
                if (game.platform.AudioFinished(sound.audio) && sound.loop)
                {
                    //game.platform.AudioPlay(sound.audio);
                    AudioData data = GetAudioData(game, sound.name);
                    if (game.platform.AudioDataLoaded(data))
                    {
                        sound.audio = game.platform.AudioCreate(data);
                        game.platform.AudioPlay(sound.audio);
                    }
                }
            }
            else
            {
                if (game.platform.AudioFinished(sound.audio))
                {
                    game.audio.sounds[i] = null;
                }
            }
        }
    }
Пример #5
0
    public void AudioPlayAt(string file, float x, float y, float z)
    {
        if (file == null)
        {
            return;
        }
        if (!AudioEnabled)
        {
            return;
        }
        if (assetsLoadProgress.value != 1)
        {
            return;
        }
        string file_ = platform.StringReplace(file, ".wav", ".ogg");

        if (GetFileLength(file_) == 0)
        {
            platform.ConsoleWriteLine(platform.StringFormat("File not found: {0}", file));
            return;
        }

        Sound_ s = new Sound_();
        s.name = file_;
        s.x = x;
        s.y = y;
        s.z = z;
        audio.Add(s);
    }