This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from VT-DevGiT/devlopement
V1.3.0
- Loading branch information
Showing
54 changed files
with
1,379 additions
and
273 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using MEC; | ||
using Synapse.Api; | ||
using System.IO; | ||
using UnityEngine; | ||
using VT_Api.Extension; | ||
|
||
namespace VT_Api.Core.Audio | ||
{ | ||
public class AudioManager | ||
{ | ||
#region Attributes & Properties | ||
public static AudioManager Get => Singleton<AudioManager>.Instance; | ||
|
||
private Controller _controller; | ||
|
||
#endregion | ||
|
||
#region Constructors & Destructor | ||
internal AudioManager() { | ||
|
||
Synapse.Api.Logger.Get.Debug("AudioRun"); | ||
} | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
internal void Init() | ||
{ | ||
//_controller = new Controller(); | ||
} | ||
|
||
public void Loop(bool enabled) | ||
{ | ||
_controller.Loop = enabled; | ||
//Synapse.Api.Logger.Get.Info($"Loop : {_controller.Loop}"); | ||
} | ||
|
||
private void UnmutePlayer(Player player) | ||
{ | ||
var id = player.Radio.mirrorIgnorancePlayer._playerId; | ||
_controller.UnMutePlayer(id); | ||
} | ||
|
||
private void MutePlayer(Player player) | ||
{ | ||
var id = player.Radio.mirrorIgnorancePlayer._playerId; | ||
_controller.MutePlayer(id); | ||
} | ||
|
||
public bool Play(string mpgFilePath) | ||
{ | ||
if (!File.Exists(mpgFilePath)) | ||
{ | ||
Synapse.Api.Logger.Get.Info($"File not found : {mpgFilePath}"); | ||
return false; | ||
} | ||
|
||
Timing.RunCoroutine(_controller.PlayFromFile(mpgFilePath)); | ||
//Synapse.Api.Logger.Get.Info("Playing."); | ||
return true; | ||
} | ||
|
||
public void Stop() | ||
{ | ||
_controller.Stop(); | ||
//Synapse.Api.Logger.Get.Info("Stopped."); | ||
} | ||
|
||
public void Volume(uint volume) | ||
{ | ||
_controller.Volume = Mathf.Clamp(volume, 0, 100) / 100; | ||
_controller.RefreshChannels(); | ||
|
||
//Synapse.Api.Logger.Get.Info($"Volume set to {volume}."); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
using Assets._Scripts.Dissonance; | ||
using Dissonance; | ||
using MEC; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using UnityEngine; | ||
using VT_Api.Reflexion; | ||
|
||
namespace VT_Api.Core.Audio | ||
{ | ||
internal class Controller | ||
{ | ||
|
||
#region Attributes & Properties | ||
public DissonanceComms Comms => Radio.comms; | ||
public FakeMicrophone Microphone; | ||
|
||
public bool Loop { get; set; } | ||
public float Volume { get; set; } = 1; | ||
|
||
public readonly List<string> MutedPlayers = new List<string>(); | ||
#endregion | ||
|
||
#region Constructors & Destructor | ||
|
||
public Controller() | ||
{ | ||
Microphone = Comms.gameObject.AddComponent<FakeMicrophone>(); | ||
Microphone.AudioController = this; | ||
InitEvents(); | ||
} | ||
#endregion | ||
|
||
#region Methods | ||
public void UnMutePlayer(string playerId) | ||
{ | ||
MutedPlayers.Remove(playerId); | ||
UnMutePlayer(playerId); | ||
Comms.PlayerChannels.Open(playerId, false, ChannelPriority.Default, Volume); | ||
} | ||
public void MutePlayer(string playerId) | ||
{ | ||
var channel = Comms.PlayerChannels._openChannelsBySubId.FirstOrDefault(x => x.Value.TargetId == playerId); | ||
Comms.PlayerChannels.Close(channel.Value); | ||
} | ||
|
||
private void InitEvents() | ||
{ | ||
Synapse.Server.Get.Events.Round.RoundRestartEvent += OnRestartingRound; | ||
Synapse.Server.Get.Events.Round.WaitingForPlayersEvent += OnWaitingForPlayers; | ||
|
||
} | ||
|
||
public IEnumerator<float> PlayFromFile(string path, float volume = 100, bool loop = false) | ||
{ | ||
if (string.IsNullOrWhiteSpace(path)) | ||
yield break; | ||
|
||
if (!File.Exists(path)) | ||
{ | ||
Synapse.Api.Logger.Get.Error($"Error File not found: {path}."); | ||
yield break; | ||
} | ||
|
||
Stop(); | ||
|
||
yield return Timing.WaitForOneFrame; | ||
yield return Timing.WaitForOneFrame; | ||
|
||
Volume = Mathf.Clamp(volume, 0, 100) / 100; | ||
RefreshChannels(); | ||
|
||
Microphone.File = new FileStream(path, FileMode.Open); | ||
Microphone.Stop = false; | ||
Comms._capture.SetField("_microphone", Microphone); | ||
Comms.ResetMicrophoneCapture(); | ||
Comms.IsMuted = false; | ||
Loop = loop; | ||
} | ||
|
||
public void Stop() | ||
{ | ||
if (Microphone != null) | ||
Microphone.Stop = true; | ||
} | ||
|
||
public void RefreshChannels() | ||
{ | ||
foreach (var channel in Comms.PlayerChannels._openChannelsBySubId.Values.ToList()) | ||
{ | ||
Comms.PlayerChannels.Close(channel); | ||
Comms.PlayerChannels.Open(channel.TargetId, false, ChannelPriority.Default, Volume); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
|
||
#region Events | ||
private void OnRestartingRound() | ||
{ | ||
Comms.OnPlayerJoinedSession -= OnPlayerJoinedSession; | ||
} | ||
|
||
private void OnWaitingForPlayers() | ||
{ | ||
Comms.OnPlayerJoinedSession += OnPlayerJoinedSession; | ||
Synapse.Server.Get.Host.Radio.Network_syncPrimaryVoicechatButton = true; | ||
Synapse.Server.Get.Host.DissonanceUserSetup.NetworkspeakingFlags = SpeakingFlags.IntercomAsHuman; | ||
} | ||
|
||
private void OnPlayerJoinedSession(VoicePlayerState player) | ||
{ | ||
Comms.PlayerChannels.Open(player.Name, false, ChannelPriority.Default, Volume); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
} |
Oops, something went wrong.