public virtual void PlaySound(string name) { if (string.IsNullOrEmpty(name)) { return; } var mode = Transform3D != null ? SoundModes.Mode3D : 0; Sound sound = SoundWorld.SoundCreate(name, mode); if (sound == null) { return; } //!!!!attachedToScene var channel = SoundWorld.SoundPlay(null, sound, EngineApp.DefaultSoundChannelGroup, 0.5, true); if (channel != null) { if (Transform3D != null) { channel.Position = Transform3D.Position; //channel.Velocity = xxx; } channel.Pause = false; } }
public virtual void PlaySound(Component_Sound sound) { var mode = Transform3D != null ? SoundModes.Mode3D : 0; var sound2 = sound?.Result?.LoadSoundByMode(mode); if (sound2 == null) { return; } //!!!!attachedToScene var channel = SoundWorld.SoundPlay(null, sound2, EngineApp.DefaultSoundChannelGroup, 0.5, true); if (channel != null) { if (Transform3D != null) { channel.Position = Transform3D.Position; //channel.Velocity = xxx; } channel.Pause = false; } }
void Play() { if (playCalling) { return; } playCalling = true; Stop(); if (EnabledInHierarchyAndIsNotResource && ParentScene != null) { var res = ParentRoot?.HierarchyController?.CreatedByResource; if (res != null && res.InstanceType == Resource.InstanceType.SeparateInstance) { var soundComponent = Sound.Value; if (soundComponent != null && soundComponent.Result != null) { bool streaming = false; switch (Streaming.Value) { case StreamingEnum.Auto: { string fileName = soundComponent.LoadFile.Value.ResourceName; if (!string.IsNullOrEmpty(fileName) && Path.GetExtension(fileName).ToLower() == ".ogg") { long length = 0; try { length = VirtualFile.GetLength(fileName); } catch { } if (length > 400000) { streaming = true; } } } break; case StreamingEnum.Enable: streaming = true; break; } SoundModes mode = SoundModes.Mode3D; if (ReplayDelay == 0 || streaming) //if( replayDelay == 0 ) { mode |= SoundModes.Loop; } if (streaming) { mode |= SoundModes.Stream; } sound = soundComponent.Result.LoadSoundByMode(mode); if (sound != null) { channel = SoundWorld.SoundPlay(ParentScene, sound, EngineApp.DefaultSoundChannelGroup, Priority, true); if (channel != null) { channel.Position = Transform.Value.Position; channel.Volume = Volume; UpdateChannelRolloffGraph(); channel.Pitch = Pitch; OnBeforePlay(); BeforePlayEvent?.Invoke(this); channel.Pause = false; lastUpdateEngineTime = EngineApp.EngineTime; } } } } } playCalling = false; }