protected override void OnCopyTo(Component target, Duality.Cloning.CloneProvider provider) { base.OnCopyTo(target, provider); SoundEmitter c = target as SoundEmitter; c.sources = this.sources == null ? null : this.sources.Select(s => provider.RequestObjectClone(s)).ToList(); }
/// <summary> /// Updates the sound source. /// </summary> /// <param name="emitter">The sources parent <see cref="SoundEmitter"/>.</param> /// <returns>True, if the source is still active. False, if it requests to be removed.</returns> public bool Update(SoundEmitter emitter) { // Revalidate Sound reference this.sound.MakeAvailable(); // If the SoundInstance has been disposed, set to null if (this.instance != null && this.instance.Disposed) { this.instance = null; } // If there is a SoundInstance playing, but it's the wrong one, stop it if (this.instance != null && this.instance.Sound != this.sound) { this.instance.Stop(); this.instance = null; } if (this.instance == null) { // If this Source isn't looped and it HAS been played already, remove it if (!this.looped && this.hasBeenPlayed) { return(false); } // Play the sound this.instance = DualityApp.Sound.PlaySound3D(this.sound, emitter.GameObj); this.instance.Pos = this.offset; this.instance.Looped = this.looped; this.instance.Volume = this.volume; this.instance.Pitch = this.pitch; this.instance.Lowpass = this.lowpass; this.instance.Paused = this.paused; this.hasBeenPlayed = true; } return(true); }
public override bool Convert(ConvertOperation convert) { List<Sound> availData = convert.Perform<Sound>().ToList(); // Generate objects foreach (Sound snd in availData) { if (convert.IsObjectHandled(snd)) continue; GameObject gameobj = convert.Result.OfType<GameObject>().FirstOrDefault(); SoundEmitter emitter = convert.Result.OfType<SoundEmitter>().FirstOrDefault(); if (emitter == null && gameobj != null) emitter = gameobj.GetComponent<SoundEmitter>(); if (emitter == null) emitter = new SoundEmitter(); convert.SuggestResultName(emitter, snd.Name); SoundEmitter.Source source = new SoundEmitter.Source(snd); emitter.Sources.Add(source); convert.AddResult(emitter); convert.MarkObjectHandled(snd); } return false; }
/// <summary> /// Updates the sound source. /// </summary> /// <param name="emitter">The sources parent <see cref="SoundEmitter"/>.</param> /// <returns>True, if the source is still active. False, if it requests to be removed.</returns> public bool Update(SoundEmitter emitter) { // Revalidate Sound reference this.sound.MakeAvailable(); // If the SoundInstance has been disposed, set to null if (this.instance != null && this.instance.Disposed) this.instance = null; // If there is a SoundInstance playing, but it's the wrong one, stop it if (this.instance != null && this.instance.Sound != this.sound) { this.instance.Stop(); this.instance = null; } if (this.instance == null) { // If this Source isn't looped and it HAS been played already, remove it if (!this.looped && this.hasBeenPlayed) return false; // Play the sound this.instance = DualityApp.Sound.PlaySound3D(this.sound, emitter.GameObj); this.instance.Pos = this.offset; this.instance.Looped = this.looped; this.instance.Volume = this.volume; this.instance.Pitch = this.pitch; this.instance.Paused = this.paused; this.hasBeenPlayed = true; } return true; }