/// <summary>
 /// Plays a music track
 /// </summary>
 public void PlayMusic(MusicID ID)
 {
     if (!sm_sharedMusic[(int)ID].sound.isPlaying)
     {
         sm_sharedMusic[(int)ID].fadeState = FadeState.FADE_IN;
         sm_sharedMusic[(int)ID].sound.Play();
     }
 }
Exemple #2
0
        /// <summary>
        /// Finds the next free <see cref="MusicID"/>.
        /// </summary>
        /// <param name="usedIDs">Collection of <see cref="MusicID"/>s already assigned.</param>
        /// <param name="start">The <see cref="MusicID"/> to start at.</param>
        /// <returns>The next free <see cref="MusicID"/>. The returned value will be marked as used in the
        /// <paramref name="usedIDs"/>.</returns>
        static MusicID NextFreeID(HashSet<MusicID> usedIDs, MusicID start)
        {
            while (!usedIDs.Add(start))
            {
                start++;
            }

            return start;
        }
Exemple #3
0
        /// <summary>
        /// Finds the next free <see cref="MusicID"/>.
        /// </summary>
        /// <param name="usedIDs">Collection of <see cref="MusicID"/>s already assigned.</param>
        /// <param name="start">The <see cref="MusicID"/> to start at.</param>
        /// <returns>The next free <see cref="MusicID"/>. The returned value will be marked as used in the
        /// <paramref name="usedIDs"/>.</returns>
        static MusicID NextFreeID(HashSet <MusicID> usedIDs, MusicID start)
        {
            while (!usedIDs.Add(start))
            {
                start++;
            }

            return(start);
        }
        public S2C_PlayThemeMusic(PacketReader reader, ChannelID channelID, NetID senderNetID)
        {
            this.SenderNetID = senderNetID;
            this.ChannelID   = channelID;

            this.SourceNetID = reader.ReadNetID();
            this.MusicID     = reader.ReadMusicID();

            this.ExtraBytes = reader.ReadLeft();
        }
    /// <summary>
    /// Creates and adds a new music track
    /// </summary>
    void CreateMusic(MusicID ID, AudioSource source)
    {
        int index = (int)ID;

        sm_sharedMusic[index].sound                  = Instantiate(source);
        sm_sharedMusic[index].maxVolume              = sm_sharedMusic[index].sound.volume * m_overallMusicMultiplier;
        sm_sharedMusic[index].sound.volume           = 0.0f;
        sm_sharedMusic[index].sound.transform.parent = sm_soundParent.transform;
        sm_sharedMusic[index].sound.Stop();
        DontDestroyOnLoad(sm_sharedMusic[index].sound);
    }
 AudioClip GetMusicFromResources(MusicID musicID)
 {
     AudioClip clip = null;
     switch (musicID)
     {
         case MusicID.Menu:
             clip = GetResourceFromSource("menu") as AudioClip;
             break;
         case MusicID.Level1:
             clip = GetResourceFromSource("Chorus1") as AudioClip;
             break;
         case MusicID.Level2:
             clip = GetResourceFromSource("Chorus2") as AudioClip;
             break;
         default:
             clip = null;
             break;
     }
     return clip;
 }
 // if _Id < 0, the current music clip will be played
 public static void PlayMusique(MusicID musicID)
 {
     if (instance != null)
     {
         if ((MusicID)musicID != MusicID.NoMusic)
         {
             if (instance.mCurrentSong != (MusicID)musicID)
             {
                 instance.mCurrentSong = (MusicID)musicID;
                 instance.mMusicSource.clip = instance.GetMusicFromResources(instance.mCurrentSong);
                 instance.mMusicSource.Play();
             }
         }
         else if (instance.mCurrentSong != MusicID.NoMusic)
         {
             instance.mMusicSource.clip = instance.GetMusicFromResources(instance.mCurrentSong);
             instance.mMusicSource.Play();
         }
     }
 }
 /// <summary>
 /// Creates and adds a new music track
 /// </summary>
 void CreateMusic(MusicID ID, AudioSource source)
 {
     int index = (int)ID;
     sm_sharedMusic[index].sound = Instantiate(source);
     sm_sharedMusic[index].maxVolume = sm_sharedMusic[index].sound.volume * m_overallMusicMultiplier;
     sm_sharedMusic[index].sound.volume = 0.0f;
     sm_sharedMusic[index].sound.transform.parent = sm_soundParent.transform;
     sm_sharedMusic[index].sound.Stop();
     DontDestroyOnLoad(sm_sharedMusic[index].sound);
 }
 /// <summary>
 /// Stops a music track
 /// </summary>
 public void StopMusic(MusicID ID)
 {
     sm_sharedMusic[(int)ID].fadeState = FadeState.FADE_OUT;
 }
 /// <summary>
 /// Plays a music track
 /// </summary>
 public void PlayMusic(MusicID ID)
 {
     if(!sm_sharedMusic[(int)ID].sound.isPlaying)
     {
         sm_sharedMusic[(int)ID].fadeState = FadeState.FADE_IN;
         sm_sharedMusic[(int)ID].sound.Play();
     }
 }
Exemple #11
0
        public void AutoUpdateMusic()
        {
            const string title            = "Update music";
            const string confirmMsg       = "The following changes are to be made (+ for add, - for remove):";
            const string upToDateMsg      = "The music is already up-to-date.";
            const string acceptChangesMsg = "Accept these {0} changes and update the music?";
            const string doneMsg          = "Music successfully updated!";

            var cm = NetGore.Content.ContentManager.Create();
            var mm = AudioManager.GetInstance(cm).MusicManager;

            // Find all the music files
            var files = Directory.GetFiles(ContentPaths.Build.Music);

            // Find the new files (file exists, but MusicInfo does not)
            var newFiles =
                files.Where(f => !mm.MusicInfos.Any(mi => StringComparer.OrdinalIgnoreCase.Equals(mi.Name, Path.GetFileName(f)))).
                ToArray();

            // Find the removed files (MusicInfo exists, but file does not)
            var removedFiles =
                mm.MusicInfos.Where(mi => !files.Any(f => StringComparer.OrdinalIgnoreCase.Equals(mi.Name, Path.GetFileName(f)))).
                ToArray();

            // Check if there are any changes
            if (newFiles.Length <= 0 && removedFiles.Length <= 0)
            {
                return;
            }

            // Display list of changes

            var sb = new StringBuilder();

            sb.AppendLine(confirmMsg);

            const int maxLines = 25;
            var       lines    = 0;

            foreach (var f in removedFiles)
            {
                sb.AppendLine(" - " + Path.GetFileName(f.Name) + " [" + f.ID + "]");
                if (++lines > maxLines)
                {
                    break;
                }
            }

            foreach (var f in newFiles)
            {
                sb.AppendLine(" + " + Path.GetFileName(f));
                if (++lines > maxLines)
                {
                    break;
                }
            }

            sb.AppendLine();
            sb.AppendLine(string.Format(acceptChangesMsg, newFiles.Length + removedFiles.Length));

            if (MessageBox.Show(sb.ToString(), title, MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            // Update by taking the existing MusicInfos, removing the ones to remove, adding the new ones

            var mis = mm.MusicInfos.ToList();

            foreach (var toRemove in removedFiles)
            {
                mis.Remove(toRemove);
            }

            var usedIDs = new HashSet <MusicID>();

            foreach (var mi in mis)
            {
                usedIDs.Add(mi.ID);
            }

            var musicIDCounter = new MusicID(1);

            foreach (var toAdd in newFiles)
            {
                var name = Path.GetFileName(toAdd);
                var id   = NextFreeID(usedIDs, musicIDCounter);
                mis.Add(new MusicInfo(name, id));
            }

            // Save it all
            mm.ReloadData(mis);
            mm.Save();


            MessageBox.Show(doneMsg, title, MessageBoxButtons.OK);
        }
Exemple #12
0
        /// <summary>
        /// Plays a music track by the given <see cref="MusicID"/>.
        /// </summary>
        /// <param name="id">The ID of the music to play.</param>
        /// <returns>
        /// True if the music played successfully; otherwise false.
        /// </returns>
        public bool Play(MusicID id)
        {
            try
            {
                // If the music is already playing, continue to play it
                if (_playingInfo != null && _playingInfo.ID == id)
                {
                    if (_playing.Status != SoundStatus.Playing)
                        _playing.Play();

                    return true;
                }

                // Stop the old music
                Stop();

                // Get the info for the music to play
                var info = GetMusicInfo(id);
                if (info == null)
                    return false;

                // Start the new music
                _playingInfo = info;

                var file = GetFilePath(info);
                try
                {
                    _playing = new Music(file);
                }
                catch (LoadingFailedException ex)
                {
                    const string errmsg = "Failed to load music `{0}`: {1}";
                    if (log.IsErrorEnabled)
                        log.ErrorFormat(errmsg, info, ex);
                    Debug.Fail(string.Format(errmsg, info, ex));

                    _playing = null;
                    _playingInfo = null;

                    return false;
                }

                // Set the values for the music and start playing it
                _playing.Volume = Volume;
                _playing.Loop = Loop;
                _playing.RelativeToListener = true;
                _playing.Play();
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to play music with ID `{0}`. Exception: {1}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, id, ex);
                Debug.Fail(string.Format(errmsg, id, ex));
            }

            return true;
        }
Exemple #13
0
        /// <summary>
        /// Gets the <see cref="IMusicInfo"/> for a music track.
        /// </summary>
        /// <param name="id">The id of the <see cref="IMusicInfo"/> to get.</param>
        /// <returns>The <see cref="IMusicInfo"/> for the given <paramref name="id"/>, or null if the value
        /// was invalid.</returns>
        public IMusicInfo GetMusicInfo(MusicID id)
        {
            var i = (int)id;
            if (i < 0 || i >= _infos.Length)
                return null;

            return _infos[i];
        }
 /// <summary>
 /// Stops a music track
 /// </summary>
 public void StopMusic(MusicID ID)
 {
     sm_sharedMusic[(int)ID].fadeState = FadeState.FADE_OUT;
 }
Exemple #15
0
        /// <summary>
        /// Handles the Click event of the btnUpdate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnUpdate_Click(object sender, EventArgs e)
        {
            if (DesignMode)
                return;

            const string title = "Update music";
            const string confirmMsg = "The following changes are to be made (+ for add, - for remove):";
            const string upToDateMsg = "The music is already up-to-date.";
            const string acceptChangesMsg = "Accept these {0} changes and update the music?";
            const string doneMsg = "Music successfully updated!";

            var cm = ContentManager.Create();
            var mm = AudioManager.GetInstance(cm).MusicManager;

            // Find all the music files
            var files = Directory.GetFiles(ContentPaths.Build.Music);

            // Find the new files (file exists, but MusicInfo does not)
            var newFiles =
                files.Where(f => !mm.MusicInfos.Any(mi => StringComparer.OrdinalIgnoreCase.Equals(mi.Name, Path.GetFileName(f)))).
                    ToArray();

            // Find the removed files (MusicInfo exists, but file does not)
            var removedFiles =
                mm.MusicInfos.Where(mi => !files.Any(f => StringComparer.OrdinalIgnoreCase.Equals(mi.Name, Path.GetFileName(f)))).
                    ToArray();

            // Check if there are any changes
            if (newFiles.Length <= 0 && removedFiles.Length <= 0)
            {
                MessageBox.Show(upToDateMsg, title, MessageBoxButtons.OK);
                return;
            }

            // Display list of changes

            var sb = new StringBuilder();
            sb.AppendLine(confirmMsg);

            const int maxLines = 25;
            var lines = 0;

            foreach (var f in removedFiles)
            {
                sb.AppendLine(" - " + Path.GetFileName(f.Name) + " [" + f.ID + "]");
                if (++lines > maxLines)
                    break;
            }

            foreach (var f in newFiles)
            {
                sb.AppendLine(" + " + Path.GetFileName(f));
                if (++lines > maxLines)
                    break;
            }

            sb.AppendLine();
            sb.AppendLine(string.Format(acceptChangesMsg, newFiles.Length + removedFiles.Length));

            if (MessageBox.Show(sb.ToString(), title, MessageBoxButtons.YesNo) == DialogResult.No)
                return;

            // Update by taking the existing MusicInfos, removing the ones to remove, adding the new ones

            var mis = mm.MusicInfos.ToList();

            foreach (var toRemove in removedFiles)
            {
                mis.Remove(toRemove);
            }

            var usedIDs = new HashSet<MusicID>();
            foreach (var mi in mis)
            {
                usedIDs.Add(mi.ID);
            }

            var musicIDCounter = new MusicID(1);

            foreach (var toAdd in newFiles)
            {
                var name = Path.GetFileName(toAdd);
                var id = NextFreeID(usedIDs, musicIDCounter);
                mis.Add(new MusicInfo(name, id));
            }

            // Save it all
            mm.ReloadData(mis);
            mm.Save();

            lstItems.UpdateList();

            MessageBox.Show(doneMsg, title, MessageBoxButtons.OK);
        }
Exemple #16
0
 public static void WriteMusicID(this PacketWriter writer, MusicID data)
 {
     writer.WriteUInt32((uint)data);
 }
Exemple #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MusicInfo"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="id">The id.</param>
 public MusicInfo(string name, MusicID id)
 {
     _name = name;
     _id = id;
 }