コード例 #1
0
        public static SoundInstance PlaySound3D(SoundDefinition sound, Vec3f location, float range = 2500, float volume = 1.0f, bool loop = false)
        {
            if (sound == null)
            {
                throw new ArgumentNullException("Sound is null!");
            }

            if (!CanPlay(sound)) // don't play too many sounds at once
            {
                return(null);
            }

            Logger.Log("PlayLocSound: " + sound.Name);
            var param = zTSound3DParams.Create();

            param.Volume    = volume;
            param.Radius    = range;
            param.Reverb    = 0.15f;
            param.LoopType  = loop ? 1 : 0;
            param.IsAmbient = true;

            zCVob vob;

            if (sndVobs.Count == 0)
            {
                vob = zCVob.Create();
            }
            else
            {
                int index = sndVobs.Count - 1;
                vob = sndVobs[index];
                sndVobs.RemoveAt(index);
            }

            GothicGlobals.Game.GetWorld().AddVob(vob);
            vob.TrafoObjToWorld.Position = location.ToArray();
            vob.SetPositionWorld(location.X, location.Y, location.Z);

            int idPtr = Process.Alloc(4).ToInt32();
            int id    = zCSndSys_MSS.PlaySound3D(sound.zSFX, vob, 0, param);

            Process.Write(idPtr, id);

            locSounds.Add(new ActiveSound(idPtr, param, sound, vob));
            return(new SoundInstance(sound, id));
        }