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)); }
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)); }
private static extern bool PlaySound(byte[] pszSound, IntPtr hmod, SoundFlag fdwSound);
private static extern bool PlaySound(string pszSound, UIntPtr hmod, SoundFlag fdwSound);