forked from BananaHemic/Mumble-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MumbleTester.cs
91 lines (77 loc) · 2.74 KB
/
MumbleTester.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* This is the front facing script to control how MumbleUnity works.
* It's expected that, to fit in properly with your application,
* You'll want to change this class (and possible SendMumbleAudio)
* in order to work the way you want it to
*/
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.Collections;
using Mumble;
public class MumbleTester : MonoBehaviour {
public MumbleAudioPlayer MyMumbleAudioPlayer;
public MumbleMicrophone MyMumbleMic;
public DebugValues DebuggingVariables;
private MumbleClient _mumbleClient;
public string HostName = "1.2.3.4";
public int Port = 64738;
public string Username = "ExampleUser";
public string Password = "1passwordHere!";
void Start () {
if(HostName == "1.2.3.4")
{
Debug.LogError("Please set the mumble host name to your mumble server");
return;
}
_mumbleClient = new MumbleClient(HostName, Port, DebuggingVariables);
if (DebuggingVariables.UseRandomUsername)
Username += Random.Range(0, 100f);
_mumbleClient.Connect(Username, Password);
if(MyMumbleAudioPlayer != null)
_mumbleClient.AddMumbleAudioPlayer(MyMumbleAudioPlayer);
if(MyMumbleMic != null)
_mumbleClient.AddMumbleMic(MyMumbleMic);
#if UNITY_EDITOR
if (DebuggingVariables.EnableEditorIOGraph)
{
EditorGraph editorGraph = EditorWindow.GetWindow<EditorGraph>();
editorGraph.Show();
StartCoroutine(UpdateEditorGraph());
}
#endif
}
void OnApplicationQuit()
{
Debug.LogWarning("Shutting down connections");
if(_mumbleClient != null)
_mumbleClient.Close();
}
IEnumerator UpdateEditorGraph()
{
long numPacketsReceived = 0;
long numPacketsSent = 0;
long numPacketsLost = 0;
while (true)
{
yield return new WaitForSeconds(0.1f);
long numSentThisSample = _mumbleClient.NumUDPPacketsSent - numPacketsSent;
long numRecvThisSample = _mumbleClient.NumUDPPacketsReceieved - numPacketsReceived;
long numLostThisSample = _mumbleClient.NumUDPPacketsLost - numPacketsLost;
Graph.channel[0].Feed(-numSentThisSample);
Graph.channel[1].Feed(-numRecvThisSample);
Graph.channel[2].Feed(-numLostThisSample);
numPacketsSent += numSentThisSample;
numPacketsReceived += numRecvThisSample;
numPacketsLost += numLostThisSample;
}
}
void Update () {
if (Input.GetKeyDown(KeyCode.S))
{
_mumbleClient.SendTextMessage("This is an example message from Unity");
print("Sent mumble message");
}
}
}