/
TrimmerServerHost.cs
59 lines (47 loc) · 1.12 KB
/
TrimmerServerHost.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
//
// Trimmer Framework for Unity
// https://sttz.ch/trimmer
//
using UnityEngine;
namespace sttz.Trimmer.Options
{
#if TRIMMER_SERVER || UNITY_EDITOR
/// <summary>
/// Script used to host <see cref="TrimmerServer"/>.
/// </summary>
public class TrimmerServerHost : MonoBehaviour
{
public int serverPort;
public bool ipv6;
public bool isDiscoverable;
public TrimmerServer Server { get; set; }
public void CreateServer(int serverPort, bool isDiscoverable, bool ipv6)
{
Server = new TrimmerServer();
Server.ServerPort = serverPort;
Server.ServerAddress = (ipv6 ? System.Net.IPAddress.IPv6Any : System.Net.IPAddress.Any);
Server.IsDiscoverable = isDiscoverable;
if (isActiveAndEnabled) {
Server.Start();
}
}
void OnEnable()
{
if (Server == null && serverPort > 0) {
CreateServer(serverPort, isDiscoverable, ipv6);
}
if (Server != null) {
Server.Start();
}
}
void OnDisable()
{
Server.Stop();
}
void Update()
{
Server.Update();
}
}
#endif
}