forked from keijiro/KlakNDI
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ReceiverBenchmark.cs
66 lines (51 loc) · 1.79 KB
/
ReceiverBenchmark.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
using UnityEngine;
using Klak.Ndi;
class ReceiverBenchmark : MonoBehaviour
{
[SerializeField] Mesh _mesh = null;
[SerializeField] Material _material = null;
[SerializeField] NdiResources _resources = null;
[SerializeField] string _hostName = "";
GameObject[] _instances = new GameObject[16];
System.Collections.IEnumerator Start()
{
for (var index = 0; index < 16; index++)
_instances[index] = CreateInstance(index);
var interval = new WaitForSeconds(0.3f);
while (true)
{
var index = Random.Range(0, 15);
if (_instances[index] == null)
{
_instances[index] = CreateInstance(index);
}
else
{
Destroy(_instances[index]);
_instances[index] = null;
}
yield return interval;
}
}
GameObject CreateInstance(int index)
{
var components = new []
{ typeof(MeshFilter), typeof(MeshRenderer), typeof(NdiReceiver) };
var go = new GameObject($"Receiver {index}", components);
var x = (index % 4 + 0.5f) / 4 - 0.5f;
var y = (index / 4 + 0.5f) / 4 - 0.5f;
go.transform.parent = transform;
go.transform.localPosition = new Vector3(x, y, 0);
go.transform.localScale = Vector3.one / 4;
var mf = go.GetComponent<MeshFilter>();
mf.sharedMesh = _mesh;
var mr = go.GetComponent<MeshRenderer>();
mr.sharedMaterial = _material;
var receiver = go.GetComponent<NdiReceiver>();
receiver.SetResources(_resources);
receiver.ndiName = $"{_hostName} (Sender {index})";
receiver.targetRenderer = mr;
receiver.targetMaterialProperty = "_MainTex";
return go;
}
}