Пример #1
0
    public SoundHandle Play(
        Sound sound,
        SoundFlag flags,
        Transform parent  = null,
        Vector3?worldPos  = null,
        Unit attachToUnit = null
        )
    {
        if (sound == null)
        {
            return(new SoundHandle());
        }
        if (sound.clips.Length == 0)
        {
            return(new SoundHandle());
        }

        if (!sound.loop && 0 == (flags & SoundFlag.OneShot))
        {
            Dbg.LogWarnOnce(sound, "Tried to play {0} as one shot", sound);
            return(new SoundHandle());
        }

        if (sound.loop && 0 == (flags & SoundFlag.Looping))
        {
            Dbg.LogWarnOnce(sound, "Tried to play {0} as looping", sound);
            return(new SoundHandle());
        }

        string       channelName = sound.channel.name;
        SoundChannel channel     = channels.GetValue(channelName);

        if (channel == null)
        {
            channel = settings.defaultChannelSettings;
        }

        var sfx = GetSfxInst();

        sfx.sound = sound;
#if UNITY_EDITOR
        string name = GarbageCache.GetName(sound);
        if (!sfx.name.EndsWith(name))
        {
            sfx.name = "SFX_" + name;
        }
#endif // UNITY_EDITOR
        if (parent != null)
        {
            sfx.gameObject.transform.parent = parent;
        }

        sfx.attachedToUnit     = attachToUnit;
        sfx.transform.position = worldPos ?? (parent == null ? Vector3.zero : parent.position);

        sfx.Reset(sound, channel, timeScale: App.timeScale);
        sfx.source.Play();

        return(new SoundHandle(sfx));
    }
Пример #2
0
    public SoundHandle Play(Sound sound, SoundFlag flags, Transform parent = null, Vector3?worldPos = null)
    {
        if (sound == null)
        {
            return(new SoundHandle());
        }
        if (sound.clips.Length == 0)
        {
            return(new SoundHandle());
        }

        if (!sound.loop && 0 == (flags & SoundFlag.OneShot))
        {
            Dbg.LogWarnOnce(sound, "Tried to play {0} as one shot", sound);
            return(new SoundHandle());
        }

        if (sound.loop && 0 == (flags & SoundFlag.Looping))
        {
            Dbg.LogWarnOnce(sound, "Tried to play {0} as looping", sound);
            return(new SoundHandle());
        }

        var sfx = GetSfxInst();

        sfx.sound = sound;
        sfx.name  = "SFX_" + sound.name;
        if (parent != null)
        {
            sfx.gameObject.transform.parent = parent;
        }

        sfx.transform.position = worldPos ?? (parent == null ? Vector3.zero : parent.position);

        sfx.Setup(sound);
        sfx.source.Play();

        return(new SoundHandle(sfx));
    }
Пример #3
0
 private static extern bool PlaySound(byte[] pszSound, IntPtr hmod, SoundFlag fdwSound);
Пример #4
0
 private static extern bool PlaySound(string pszSound, UIntPtr hmod, SoundFlag fdwSound);
Пример #5
0
 private static extern bool PlaySound(byte[] pszSound, IntPtr hmod, SoundFlag fdwSound);
Пример #6
0
 private static extern bool PlaySound(string pszSound, UIntPtr hmod, SoundFlag fdwSound);