public void Send(TransportConnection connection, int resource, ref Wav wav) { using var writer = new DataBufferWriter(0); writer.WriteInt((int)EAudioSendType.SendReplyResourceData); writer.WriteInt(resource); writer.WriteValue((double)wav.getLength()); foreach (var(_, feature) in Features) { feature.Driver.Send(default, connection, writer.Span);
protected override void OnUpdate() { foreach (ref readonly var entity in playerSet.GetEntities()) { if (entity.TryGet(out AudioStartTime startTime)) { entity.Set(new AudioCurrentPlayTime(worldTime.Total - startTime.Value)); } } foreach (ref readonly var entity in playAudioSet.GetEntities()) { var resource = entity.Get <ResourceHandle <AudioResource> >(); if (!resource.IsLoaded) { continue; } var volume = 1f; if (entity.TryGet(out AudioVolumeComponent volumeComponent)) { volume = volumeComponent.Volume; } var delay = TimeSpan.Zero; if (entity.TryGet(out AudioDelayComponent delayComponent)) { delay = delayComponent.Delay; } using var writer = new DataBufferWriter(16 + Unsafe.SizeOf <SControllerEvent>()); writer.WriteValue((int)EAudioSendType.SendAudioPlayerData); writer.WriteStaticString(typeName); writer.WriteValue(new SControllerEvent { State = SControllerEvent.EState.Play, ResourceId = entity.Get <ResourceHandle <AudioResource> >().Result.Id, Player = entity.Get <AudioPlayerId>().Id, Volume = volume, Delay = delay }); entity.Set(new AudioStartTime { Value = worldTime.Total + delay }); foreach (var(_, feature) in Features) { unsafe { feature.Driver.Broadcast(feature.PreferredChannel, new Span <byte>((void *)writer.GetSafePtr(), writer.Length)); } } } foreach (ref readonly var entity in stopAudioSet.GetEntities()) { var delay = TimeSpan.Zero; if (entity.TryGet(out AudioDelayComponent delayComponent)) { delay = delayComponent.Delay; } using var writer = new DataBufferWriter(16 + Unsafe.SizeOf <SControllerEvent>()); writer.WriteValue((int)EAudioSendType.SendAudioPlayerData); writer.WriteStaticString(typeName); writer.WriteValue(new SControllerEvent { State = SControllerEvent.EState.Stop, Player = entity.Get <AudioPlayerId>().Id, Delay = delay }); foreach (var(_, feature) in Features) { unsafe { feature.Driver.Broadcast(feature.PreferredChannel, new Span <byte>((void *)writer.GetSafePtr(), writer.Length)); } } } playAudioSet.Remove <PlayAudioRequest>(); playAudioSet.Remove <StopAudioRequest>(); toDisposeSet.DisposeAllEntities(); }