Пример #1
0
        public Property(EndianBinaryReader reader)
        {
            int bitField1 = reader.ReadInt32();

            m_camID     = (bitField1 & 0xFF);
            m_soundID   = (SoundID)((bitField1 & 0x1F00) >> 0x08);
            m_exitID    = (bitField1 & 0x7E000) >> 0x0D;
            m_polyColor = (bitField1 & 0x7F80000) >> 0x13;

            int bitField2 = reader.ReadInt32();

            m_linkNo      = (bitField2 & 0xFF);
            m_wallCode    = (WallCode)((bitField2 & 0xF00) >> 0x08);
            m_specialCode = (SpecialCode)((bitField2 & 0xF000) >> 0x0C);
            m_attribCode  = (AttributeCode)((bitField2 & 0x1F0000) >> 0x10);
            m_groundCode  = (GroundCode)((bitField2 & 0x3E00000) >> 0x15);

            int bitField3 = reader.ReadInt32();

            m_camMoveBg     = (bitField3 & 0xFF);
            m_roomCamID     = (bitField3 & 0xFF00) >> 0x08;
            m_roomPathID    = (bitField3 & 0xFF0000) >> 0x10;
            m_roomPathPntNo = (bitField3 & unchecked ((int)0xFF000000)) >> 0x18;

            m_cameraBehavior = reader.ReadInt32();
        }
Пример #2
0
    public bool PlayRandomSound(params SoundID[] soundIDs)
    {
        // Get random sound ID
        SoundID soundID = soundIDs[UnityEngine.Random.Range(0, soundIDs.Length)];

        return(PlaySound(soundID));
    }
Пример #3
0
 public static void PlaySound(SoundID soundId)
 {
     int i = _sfxIds.IndexOf(soundId);
     SoundEffect effect = _sfx.ElementAt(i);
     SoundEffectInstance sound = effect.CreateInstance();
     sound.Play();
 }
Пример #4
0
        public Property(Triangle tri)
        {
            m_attribCode = tri.AttributeCode;

            m_cameraBehavior = tri.CameraBehavior;

            m_camID = tri.CameraID;

            m_camMoveBg = tri.CamMoveBG;

            m_exitID = tri.ExitIndex;

            m_groundCode = tri.GroundCode;

            m_linkNo = tri.LinkNumber;

            m_polyColor = tri.PolyColor;

            m_roomCamID = tri.RoomCamID;

            m_roomPathID = tri.RoomPathID;

            m_roomPathPntNo = tri.RoomPathPointNo;

            m_soundID = tri.SoundID;

            m_specialCode = tri.SpecialCode;

            m_wallCode = tri.WallCode;
        }
Пример #5
0
    public bool PlayMusic(SoundID soundID)
    {
        // Stop current music
        if (musicSource != null)
        {
            // Stop music
            musicSource.Stop();

            // Set disabled
            musicSource.enabled = false;
        }

        // Set music source
        musicSource = musicLookup[soundID];

        if (musicSource != null)
        {
#if EDIT_MODE
            musicSource.Copy(prefabMusicLookup[soundID]);
#endif

            // Set enabled
            musicSource.enabled = true;

            // Play music
            musicSource.Play();

            return(true);
        }

        return(false);
    }
Пример #6
0
        public static PacketWriter PlaySound(SoundID sound)
        {
            var pw = GetWriter(ServerPacketID.PlaySound);

            pw.Write(sound);
            return(pw);
        }
Пример #7
0
 public SoundEvent(SoundID id, Vector3 position, float vol, bool loop)
 {
     this.id       = id;
     this.position = position;
     this.vol      = vol;
     this.loop     = loop;
 }
Пример #8
0
 public static PacketWriter PlaySoundAt(SoundID sound, Vector2 position)
 {
     var pw = GetWriter(ServerPacketID.PlaySoundAt);
     pw.Write(sound);
     pw.Write(position);
     return pw;
 }
Пример #9
0
        public static void PlaySound(SoundID id)
        {
            //new Thread(delegate {
                switch (id)
                {
                    case SoundID.PowerOn:
                        Utility.Piezo(1000, 100);
                        break;
                    case SoundID.PowerOff:
                        Utility.Piezo(100, 100);
                        break;
                    case SoundID.Overload:
                        Utility.Piezo(200, 1000);
                        Thread.Sleep(1500);
                        Utility.Piezo(200, 1000);
                        Thread.Sleep(1500);
                        Utility.Piezo(200, 1000);
                        break;
                    case SoundID.Click:
                        Utility.Piezo(2000, 80);
                        break;
                    case SoundID.USBDeviceInserted:
                        Utility.Piezo(500, 100);
                        Utility.Piezo(1000, 100);
                        break;
                    case SoundID.USBDeviceRemoved:
                        Utility.Piezo(1000, 100);
                        Utility.Piezo(500, 100);
                        break;

                    default:
                        break;
                }
            //}) { Priority = ThreadPriority.Normal }.Start();
        }
Пример #10
0
    /*
     *      MUSIC JINGLES
     */

    public void PlayJingleAboveMusic(SoundID id)
    {
        if (Options.GetMuteSFX())
        {
            return;
        }

        GameObject jingle = null;

        foreach (var sound in sounds.list)
        {
            if (sound.id == id)
            {
                if (sound.prefab == null)
                {
                    continue;
                }

                jingle = sound.prefab;
            }
        }

        if (jingle == null)
        {
            return;
        }

        StartCoroutine(crossFade(jingle));
    }
Пример #11
0
        public Triangle(Vector3 vert1, Vector3 vert2, Vector3 vert3, Property prop, int groupIndex)
        {
            m_vertex1 = vert1;

            m_vertex2 = vert2;

            m_vertex3 = vert3;

            GroupIndex = groupIndex;

            m_camID     = prop.CameraID;
            m_soundID   = prop.SoundID;
            m_exitID    = prop.ExitIndex;
            m_polyColor = prop.PolyColor;

            m_linkNo      = prop.LinkNumber;
            m_wallCode    = prop.WallCode;
            m_specialCode = prop.SpecialCode;
            m_attribCode  = prop.AttributeCode;
            m_groundCode  = prop.GroundCode;

            m_camMoveBg     = prop.CamMoveBG;
            m_roomCamID     = prop.RoomCamID;
            m_roomPathID    = prop.RoomPathID;
            m_roomPathPntNo = prop.RoomPathPointNo;

            m_cameraBehavior = prop.CameraBehavior;
        }
Пример #12
0
 public static PacketWriter PlaySoundAtEntity(SoundID sound, MapEntityIndex mapEntityIndex)
 {
     var pw = GetWriter(ServerPacketID.PlaySoundAtEntity);
     pw.Write(sound);
     pw.Write(mapEntityIndex);
     return pw;
 }
Пример #13
0
        public SoundManager(IContentManager contentManager)
        {
            // Load the values from file
            var values = AudioManager.LoadValues(_fileName, _rootNodeName);

            // Create the _infos and _soundBuffers arrays large enough to hold all values
            var max = values.Max(x => x.Value);
            _infos = new ISoundInfo[max + 1];
            _soundBuffers = new SoundBuffer[_infos.Length];

            // Populate both collections
            foreach (var value in values)
            {
                var id = new SoundID(value.Value);
                var soundInfo = new SoundInfo(value.Key, id);

                // Ensure no duplicates
                if (_infos[(int)id] != null)
                    throw new DuplicateKeyException(string.Format("Two or more SoundInfos found with the ID `{0}`!", soundInfo.ID));

                if (_infosByName.ContainsKey(soundInfo.Name))
                    throw new DuplicateKeyException(string.Format("Two or more SoundInfos found with the name `{0}`!",
                        soundInfo.Name));

                // Add
                _infosByName.Add(soundInfo.Name, soundInfo);
                _infos[(int)soundInfo.ID] = soundInfo;
                _soundBuffers[(int)soundInfo.ID] = contentManager.LoadSoundBuffer(
                    ContentPaths.SoundsFolder + "/" + soundInfo.Name, ContentLevel.GameScreen);
            }
        }
Пример #14
0
        private static void Piezo(SoundID id)
        {
            switch (id)
            {
                case SoundID.PowerOn:
                    Utility.Piezo(1000, 200);
                    break;
                case SoundID.PowerOff:
                    Utility.Piezo(100, 200);
                    break;
                case SoundID.Overload:
                    Utility.Piezo(200, 1000);
                    Thread.Sleep(1500);
                    Utility.Piezo(200, 1000);
                    Thread.Sleep(1500);
                    Utility.Piezo(200, 1000);
                    break;
                case SoundID.Click:
                    Utility.Piezo(2000, 100);
                    break;
                case SoundID.USBDeviceInserted:
                    Utility.Piezo(500, 100);
                    Utility.Piezo(1000, 100);
                    break;
                case SoundID.USBDeviceRemoved:
                    Utility.Piezo(1000, 100);
                    Utility.Piezo(500, 100);
                    break;

            }
        }
Пример #15
0
        public override void SerializeBlock(SerializerObject s)
        {
            if (s.GameSettings.EngineVersion == EngineVersion.GBC_R1_PocketPC)
            {
                FileOffsets = s.SerializeArraySize <uint, uint>(FileOffsets, name: nameof(FileOffsets));
                FileOffsets = s.SerializeArray <uint>(FileOffsets, FileOffsets.Length, name: nameof(FileOffsets));
                if (Files == null)
                {
                    Files = new SoundFile_PPC[FileOffsets.Length];
                }
                for (int i = 0; i < FileOffsets.Length; i++)
                {
                    if (FileOffsets[i] == 0)
                    {
                        continue;
                    }
                    s.Goto(BlockStartPointer + FileOffsets[i]);
                    Files[i] = s.SerializeObject <SoundFile_PPC>(Files[i], name: $"{nameof(Files)}[{i}]");
                }
            }
            else
            {
                DataOffsetsOffset  = s.Serialize <ushort>(DataOffsetsOffset, name: nameof(DataOffsetsOffset));
                UShort_02          = s.Serialize <ushort>(UShort_02, name: nameof(UShort_02));
                SoundIDOffsetCount = s.Serialize <ushort>(SoundIDOffsetCount, name: nameof(SoundIDOffsetCount));
                SoundOffsetCount   = s.Serialize <ushort>(SoundOffsetCount, name: nameof(SoundOffsetCount));

                s.DoAt(BlockStartPointer + DataOffsetsOffset, () => {
                    SoundIDOffsets = s.SerializeArray <ushort>(SoundIDOffsets, SoundIDOffsetCount, name: nameof(SoundIDOffsets));
                    SoundOffsets   = s.SerializeArray <ushort>(SoundOffsets, SoundOffsetCount, name: nameof(SoundOffsets));
                });
                if (SoundIDs == null)
                {
                    SoundIDs = new SoundID[SoundIDOffsetCount];
                }
                if (Sounds == null)
                {
                    Sounds = new Sound[SoundOffsetCount];
                }
                for (int i = 0; i < SoundIDs.Length; i++)
                {
                    s.Goto(BlockStartPointer + SoundIDOffsets[i]);
                    SoundIDs[i] = s.SerializeObject <SoundID>(SoundIDs[i], name: $"{nameof(SoundIDs)}[{i}]");
                }
                for (int i = 0; i < Sounds.Length; i++)
                {
                    int nextOff = i < Sounds.Length - 1 ? SoundOffsets[i + 1] : (int)BlockSize;
                    int length  = nextOff - SoundOffsets[i];
                    s.Goto(BlockStartPointer + SoundOffsets[i]);
                    Sounds[i] = s.SerializeObject <Sound>(Sounds[i], onPreSerialize: d => d.Length = length, name: $"{nameof(Sounds)}[{i}]");
                    if (Sounds[i].SoundProgramID.HasValue)
                    {
                        Sounds[i].SoundProgram = s.DoAt(DependencyTable.GetPointer(Sounds[i].SoundProgramID.Value - 1), () => {
                            return(s.SerializeObject <GBC_SoundProgram>(Sounds[i].SoundProgram, name: nameof(Sound.SoundProgram)));
                        });
                    }
                }
            }
        }
Пример #16
0
 public AudioClip Get(SoundID ID)
 {
     if (dicSounds.Count == 0)
     {
         GenerateDictionary();
     }
     return(dicSounds[ID]);
 }
Пример #17
0
 public void Stop(SoundID SoundID)
 {
     if (!channels[(int)SoundID].isPlaying)
     {
         return;
     }
     channels[(int)SoundID].Stop();
 }
Пример #18
0
 public void Pause(SoundID SoundID)
 {
     if (!channels[(int)SoundID].isPlaying)
     {
         return;
     }
     channels[(int)SoundID].Pause();
 }
Пример #19
0
 public static void TryPlayMenuSound(SoundID soundID)
 {
     try
     {
         (CustomWorldMod.rainWorldInstance.processManager.currentMainLoop as Menu.Menu).PlaySound(soundID);
     }
     catch (Exception e) { CustomWorldMod.Log("Exception " + e, true); }
 }
Пример #20
0
 public static void PlaySound(SoundID id)
 {
     switch (DeviceManager.ActiveDevice)
     {
         case DeviceType.EMX: Piezo(id); break;
         case DeviceType.ChipworkX: Audio(id); break;
     }
 }
Пример #21
0
    public void StopSound(SoundID soundID)
    {
        AudioSource audioSource = soundLookup[soundID];

        if (audioSource != null)
        {
            audioSource.Stop();
        }
    }
Пример #22
0
        /// <summary>
        /// Finds the next free <see cref="SoundID"/>.
        /// </summary>
        /// <param name="usedIDs">Collection of <see cref="SoundID"/>s already assigned.</param>
        /// <param name="start">The <see cref="SoundID"/> to start at.</param>
        /// <returns>The next free <see cref="SoundID"/>. The returned value will be marked as used in the
        /// <paramref name="usedIDs"/>.</returns>
        static SoundID NextFreeID(HashSet<SoundID> usedIDs, SoundID start)
        {
            while (!usedIDs.Add(start))
            {
                start++;
            }

            return start;
        }
Пример #23
0
    /// <summary>
    /// 指定されたIDのサウンドを再生する
    /// </summary>
    /// <param name="soundId"></param>
    public static void PlaySound(SoundID soundId)
    {
        if (!Instance._sounds.TryGetValue(soundId, out var sound))
        {
            return;
        }

        sound.Play();
    }
Пример #24
0
        /// <summary>
        /// Finds the next free <see cref="SoundID"/>.
        /// </summary>
        /// <param name="usedIDs">Collection of <see cref="SoundID"/>s already assigned.</param>
        /// <param name="start">The <see cref="SoundID"/> to start at.</param>
        /// <returns>The next free <see cref="SoundID"/>. The returned value will be marked as used in the
        /// <paramref name="usedIDs"/>.</returns>
        static SoundID NextFreeID(HashSet <SoundID> usedIDs, SoundID start)
        {
            while (!usedIDs.Add(start))
            {
                start++;
            }

            return(start);
        }
Пример #25
0
        public void DestroyAllSound(SoundID soundID)
        {
            List <Sound> sounds = _playingSoundList.Where(s => s._id.Equals(soundID.ToString())).ToList();

            for (int i = sounds.Count - 1; i >= 0; i--)
            {
                sounds[i].Finish(false);
            }
            sounds.Clear();
        }
Пример #26
0
 void PlaySound(Player player, SoundID soundID)
 {
     player.room.PlaySound(
         soundId: soundID,
         chunk: player.mainBodyChunk,
         loop: false,
         vol: 1f,
         pitch: 1f,
         randomStartPosition: false);
 }
Пример #27
0
        static void LogFailPlaySound(SoundID soundID)
        {
            const string errmsg = "Failed to play sound with ID `{0}`.";

            if (log.IsErrorEnabled)
            {
                log.ErrorFormat(errmsg, soundID);
            }

            Debug.Fail(string.Format(errmsg, soundID));
        }
Пример #28
0
 // Get an ID for a sound name
 public static int GetIdForSoundName(string soundName)
 {
     for (int i = 0; i < SoundID.TrackableLegacySoundCount; i++)
     {
         if (SoundID.GetTrackableLegacySoundPath(i).EndsWith(soundName))
         {
             return(i);
         }
     }
     return(0);
 }
Пример #29
0
    public bool IsSoundFinished(SoundID soundID)
    {
        AudioSource audioSource = soundLookup[soundID];

        if (audioSource != null)
        {
            return(!audioSource.isPlaying);
        }

        return(true);
    }
Пример #30
0
    public PlaySoundAction(SoundID soundId, SoundType soundType, float delay)
    {
        // Set sound ID
        _soundId = soundId;

        // Set sound type
        _soundType = soundType;

        // Set delay time
        _delay = delay;
    }
Пример #31
0
    public PlaySoundAction(SoundID soundId, SoundType soundType, float delay)
    {
        // Set sound ID
        _soundId = soundId;

        // Set sound type
        _soundType = soundType;

        // Set delay time
        _delay = delay;
    }
Пример #32
0
 public void Play(SoundID SoundID, bool loop = false, float volumen = 1, int position = 0)
 {
     if (channels[(int)SoundID].isPlaying)
     {
         return;
     }
     channels[(int)SoundID].Play();
     channels[(int)SoundID].loop   = loop;
     channels[(int)SoundID].volume = volumen;
     channels[(int)SoundID].time   = position;
 }
Пример #33
0
 public void AirVoice(SoundID line)
 {
     if (voice != null)
     {
         if (voice.currentAudioSource != null)
         {
             voice.currentAudioSource.Stop();
         }
         voice.Destroy();
     }
     voice = oracle.room.PlaySound(line, oracle.firstChunk);
     voice.requireActiveUpkeep = true;
 }
Пример #34
0
    void AddSound(SoundID soundID, AudioSource audioSource)
    {
        AudioSource source = gameObject.AddComponent <AudioSource>();

        source.Copy(audioSource);
        source.enabled = false;

        soundLookup.Add(soundID, source);

#if EDIT_MODE
        prefabSoundLookup.Add(soundID, audioSource);
#endif
    }
Пример #35
0
    public AudioClip GetRandomSoundEffect(SoundID sound)
    {
        SoundEffectList effects = SoundEffects.Find(x => x.effectID == sound);

        if (effects == null)
        {
            return(null);
        }

        List <AudioClip> sounds = effects.Sounds;

        return(sounds[Random.Range(0, sounds.Count)]);
    }
 public override void SetDefaults()
 {
     npc.height          = 480;
     npc.width           = 18;
     npc.damage          = 70;
     npc.defense         = 60;
     npc.lifeMax         = 2000;
     npc.soundHit        = 21;
     npc.soundKilled     = SoundID.CreateTrackable("dd2_explosive_trap_explode", 3, SoundType.Sound);
     npc.value           = 10f;
     npc.knockBackResist = 1f;
     npc.aiStyle         = 3;
 }
Пример #37
0
 static void VirtualMicrophone_PlaySound(On.VirtualMicrophone.orig_PlaySound_SoundID_PositionedSoundEmitter_bool_float_float_bool orig,
                                         VirtualMicrophone self, SoundID soundID, PositionedSoundEmitter controller, bool loop, float vol,
                                         float pitch, bool randomStartPosition)
 {
     if (NewSounds.SoundNames.Contains(soundID.ToString()))
     {
         SoundLoader.SoundData soundData = GetSlugcatSingSound(soundID);
         self.soundObjects.Add(new VirtualMicrophone.ObjectSound(self, soundData, loop, controller, vol, pitch, randomStartPosition));
     }
     else
     {
         orig(self, soundID, controller, loop, vol, pitch, randomStartPosition);
     }
 }
Пример #38
0
        private static void Audio(SoundID id)
        {
            //if (!MP3Control.InUse())
            //{
            //    switch (id)
            //    {
            //        case ID_BALL_HIT_WALL: MP3Control.SetSource(Resources.BinaryResources.ballHitWall); break;
            //        case ID_BALL_HIT_PADDLE: MP3Control.SetSource(Resources.BinaryResources.ballHitPaddle); break;
            //        case ID_BALL_MISS: MP3Control.SetSource(Resources.BinaryResources.ballMiss); break;
            //        default: MP3Control.SetSource(Resources.BinaryResources.beep); break;
            //    }

            //    MP3Control.Play();
            //}
        }
Пример #39
0
    public bool IsSoundFinished(SoundID soundID)
    {
        AudioSource audioSource = soundLookup[soundID];

        if (audioSource != null)
        {
            return !audioSource.isPlaying;
        }

        return true;
    }
Пример #40
0
    public void StopSound(SoundID soundID)
    {
        AudioSource audioSource = soundLookup[soundID];

        if (audioSource != null)
        {
            audioSource.Stop();
            audioSource.enabled = false;
        }
    }
Пример #41
0
	public bool PlayMusic(SoundID soundID)
	{
		// Stop current music
		if (musicSource != null)
		{
			// Stop music
			musicSource.Stop();

			// Set disabled
			musicSource.enabled = false;
		}

		// Set music source
		musicSource = musicLookup[soundID];

		if (musicSource != null)
		{
#if EDIT_MODE
			musicSource.Copy(prefabMusicLookup[soundID]);
#endif

			// Set enabled
			musicSource.enabled = true;

			// Play music
			musicSource.Play();

			return true;
		}

		return false;
	}
Пример #42
0
	public bool PlaySound(SoundID soundID, SoundType type = SoundType.Replace, float delay = 0f)
	{
		if (!isSoundEnabled) return false;

		// Get audio source
		AudioSource audioSource = soundLookup[soundID];

		if (audioSource != null)
		{
#if EDIT_MODE
			audioSource.Copy(prefabSoundLookup[soundID]);
#endif

			// Set enabled
			audioSource.enabled = true;

			if (type == SoundType.Loop)
			{
				audioSource.loop = true;

				if (!audioSource.isPlaying)
				{
					if (delay > 0)
					{
						audioSource.PlayDelayed(delay);
					}
					else
					{
						audioSource.Play();                        
                    }
				}
			}
			else
			{
				audioSource.loop = false;

				if (type == SoundType.Replace)
				{
					if (delay > 0)
					{
						audioSource.PlayDelayed(delay);
					}
					else
					{
						audioSource.Play();
					}
				}
				else if (type == SoundType.New)
				{
					audioSource.PlayOneShot(audioSource.clip);
				}
				else if (type == SoundType.Only)
				{
					if (!audioSource.isPlaying)
					{
						if (delay > 0)
						{
							audioSource.PlayDelayed(delay);
						}
						else
						{
							audioSource.Play();
						}
					}
				}
			}

			return true;
		}

		return false;
	}
Пример #43
0
    /// <summary>
    /// Creates and adds a new sound effect
    /// </summary>
    void CreateSound(SoundID ID, AudioSource source, int instances, string name)
    {
        int index = (int)ID;
        float volume = source.volume * m_overallSoundMultiplier;
        sm_sharedSound[index].instances = new List<AudioSource>();
        sm_sharedSound[index].name = name;

        for(int i = 0; i < instances; ++i)
        {
            sm_sharedSound[index].instances.Add(
                i == 0 ? source : Instantiate(source));

            sm_sharedSound[index].instances[i].transform.parent = sm_soundParent.transform;
            sm_sharedSound[index].instances[i].Stop();
            sm_sharedSound[index].instances[i].volume = volume;
            DontDestroyOnLoad(sm_sharedSound[index].instances[i]);
        }
    }
Пример #44
0
 /// <summary>
 /// Attempts to create a <see cref="Sound"/> instance.
 /// </summary>
 /// <param name="id">The <see cref="SoundID"/>.</param>
 /// <param name="spatialized">True if this is for a spatialized sound; false for a static sound.</param>
 /// <param name="info">When this method returns a non-null object, contains the <see cref="ISoundInfo"/> for the
 /// <paramref name="id"/>.</param>
 /// <returns>
 /// The <see cref="Sound"/> instance, or null if it failed to be created.
 /// </returns>
 Sound InternalCreateSound(SoundID id, bool spatialized, out ISoundInfo info)
 {
     // Get the sound info
     info = GetSoundInfo(id);
     return InternalCreateSound(info, spatialized);
 }
Пример #45
0
        /// <summary>
        /// Plays a sound by the given <see cref="SoundID"/>.
        /// </summary>
        /// <param name="id">The ID of the sound to play.</param>
        /// <param name="source">The <see cref="IAudioEmitter"/> that the sound is coming from.</param>
        /// <returns>
        /// True if the sound played successfully; otherwise false.
        /// </returns>
        public bool Play(SoundID id, IAudioEmitter source)
        {
            // Create the sound instance
            ISoundInfo info;
            var snd = InternalCreateSound(id, true, out info);
            if (snd == null)
                return false;

            // Set the sound up and start playing it
            SoundInstance si;
            try
            {
                snd.Position = new Vector3(source.Position, 0f);
                si = new SoundInstance(info, snd, source);
                snd.Play();
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to play sound `{0}`: {1}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, info, ex);

                try
                {
                    snd.Dispose();
                }
                catch (Exception ex2)
                {
                    const string errmsg2 = "Failed to dispose sound that failed to play `{0}`: {1}";
                    if (log.IsWarnEnabled)
                        log.WarnFormat(errmsg2, info, ex2);
                }

                return false;
            }

            // Add to the list of active sounds
            _soundInstances.Add(si);

            return true;
        }
Пример #46
0
        static void LogFailPlaySound(SoundID soundID)
        {
            const string errmsg = "Failed to play sound with ID `{0}`.";
            if (log.IsErrorEnabled)
                log.ErrorFormat(errmsg, soundID);

            Debug.Fail(string.Format(errmsg, soundID));
        }
Пример #47
0
 public static PacketWriter PlaySound(SoundID sound)
 {
     var pw = GetWriter(ServerPacketID.PlaySound);
     pw.Write(sound);
     return pw;
 }
Пример #48
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 sound";
            const string confirmMsg = "The following changes are to be made (+ for add, - for remove):";
            const string upToDateMsg = "The sound is already up-to-date.";
            const string acceptChangesMsg = "Accept these {0} changes and update the sound?";
            const string doneMsg = "Sound successfully updated!";

            var cm = ContentManager.Create();
            var sm = AudioManager.GetInstance(cm).SoundManager;

            // Find all the sound files
            var files = Directory.GetFiles(ContentPaths.Build.Sounds);

            // Find the new files (file exists, but SoundInfo does not)
            var newFiles =
                files.Where(f => !sm.SoundInfos.Any(si => StringComparer.OrdinalIgnoreCase.Equals(si.Name, Path.GetFileName(f)))).
                    ToArray();

            // Find the removed files (SoundInfo exists, but file does not)
            var removedFiles =
                sm.SoundInfos.Where(si => !files.Any(f => StringComparer.OrdinalIgnoreCase.Equals(si.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 SoundInfos, removing the ones to remove, adding the new ones

            var sis = sm.SoundInfos.ToList();

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

            var usedIDs = new HashSet<SoundID>();
            foreach (var si in sis)
            {
                usedIDs.Add(si.ID);
            }

            var soundIDCounter = new SoundID(1);

            foreach (var toAdd in newFiles)
            {
                var name = Path.GetFileName(toAdd);
                var id = NextFreeID(usedIDs, soundIDCounter);
                sis.Add(new SoundInfo(name, id));
            }

            // Save it all
            sm.ReloadData(sis);
            sm.Save();

            lstItems.UpdateList();

            MessageBox.Show(doneMsg, title, MessageBoxButtons.OK);
        }
Пример #49
0
	void AddSound(SoundID soundID, AudioSource audioSource)
	{
		AudioSource source = gameObject.AddComponent<AudioSource>();
		source.Copy(audioSource);
		source.enabled = false;

		soundLookup.Add(soundID, source);

#if EDIT_MODE
		prefabSoundLookup.Add(soundID, audioSource);
#endif
	}
Пример #50
0
        /// <summary>
        /// Gets the <see cref="SoundBuffer"/> for the given <see cref="SoundID"/>.
        /// </summary>
        /// <param name="id">The <see cref="SoundID"/> for the <see cref="SoundBuffer"/> to get.</param>
        /// <returns>The <see cref="SoundBuffer"/> for the <paramref name="id"/>, or null if the <see cref="SoundBuffer"/>
        /// failed to load or the <paramref name="id"/> is invalid.</returns>
        protected SoundBuffer GetSoundBuffer(SoundID id)
        {
            var i = (int)id;
            if (i < 0 || i >= _soundBuffers.Length)
                return null;

            return _soundBuffers[i];
        }
Пример #51
0
 public static PlaySoundAction Create(SoundID soundId, SoundType soundType = SoundType.Replace, float delay = 0)
 {
     return new PlaySoundAction(soundId, soundType, delay);
 }
Пример #52
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SoundInfo"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="id">The id.</param>
 public SoundInfo(string name, SoundID id)
 {
     _name = name;
     _id = id;
 }
Пример #53
0
        /// <summary>
        /// Gets the <see cref="ISoundInfo"/> for a sound.
        /// </summary>
        /// <param name="id">The id of the <see cref="ISoundInfo"/> to get.</param>
        /// <returns>The <see cref="ISoundInfo"/> for the given <paramref name="id"/>, or null if the value
        /// was invalid.</returns>
        public ISoundInfo GetSoundInfo(SoundID id)
        {
            var i = (int)id;
            if (i < 0 || i >= _infos.Length)
                return null;

            return _infos[i];
        }
Пример #54
0
        /// <summary>
        /// Stops all instances of a sound with the given <see cref="SoundID"/>.
        /// </summary>
        /// <param name="id">The ID of the sounds to stop.</param>
        public void Stop(SoundID id)
        {
            for (var i = 0; i < _soundInstances.Count; i++)
            {
                if (_soundInstances[i].SoundInfo.ID != id)
                    continue;

                _soundInstances.RemoveAt(i);
                i--;
            }
        }
Пример #55
0
 public static void Add(SoundID soundId, SoundEffect effect)
 {
     _sfxIds.Add(soundId);
     _sfx.Add(effect);
 }
Пример #56
0
 /// <summary>
 /// Plays a sound effect
 /// </summary>
 public void PlaySound(SoundID ID)
 {
     sm_sharedSound[(int)ID].shouldPlaySound = true;
 }