-
Notifications
You must be signed in to change notification settings - Fork 102
/
SenderBenchmark.cs
64 lines (49 loc) · 1.66 KB
/
SenderBenchmark.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
using UnityEngine;
using Klak.Spout;
class SenderBenchmark : MonoBehaviour
{
[SerializeField] SpoutResources _resources = null;
RenderTexture _targetRT;
GameObject[] _instances = new GameObject[16];
System.Collections.IEnumerator Start()
{
_targetRT = new RenderTexture(256, 256, 32);
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(Camera), typeof(SpoutSender) };
var go = new GameObject($"Sender {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, -10);
var camera = go.GetComponent<Camera>();
camera.orthographic = true;
camera.orthographicSize = 0.5f / 4;
camera.targetTexture = _targetRT;
var sender = go.GetComponent<SpoutSender>();
sender.SetResources(_resources);
sender.spoutName = go.name;
sender.keepAlpha = true;
sender.captureMethod = CaptureMethod.Camera;
sender.sourceCamera = camera;
return go;
}
}