-
-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathClientObjectManagerParentingTest.cs
More file actions
110 lines (88 loc) · 4.09 KB
/
ClientObjectManagerParentingTest.cs
File metadata and controls
110 lines (88 loc) · 4.09 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System.Collections;
using Mirage.Tests.Runtime;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace Mirage.Tests.Runtime.ClientServer
{
public class ClientObjectManagerParentingTest : ClientServerSetup
{
[UnityTest]
public IEnumerator AutoParentingWorks()
{
var parent = InstantiateForTest(_characterPrefab);
serverObjectManager.Spawn(parent);
var child = InstantiateForTest(_characterPrefab);
child.SpawnSettings = new NetworkSpawnSettings
{
SendPosition = true,
SendRotation = true,
SendParent = SpawnParentingMode.Auto
};
child.transform.SetParent(parent.transform);
child.transform.localPosition = new Vector3(1, 2, 3);
serverObjectManager.Spawn(child);
// Wait for spawn messages to be processed
yield return null;
yield return null;
var clientParent = _remoteClients[0].Get(parent);
var clientChild = _remoteClients[0].Get(child);
Assert.That(clientChild.transform.parent, Is.EqualTo(clientParent.transform));
Assert.That(clientChild.transform.localPosition, Is.EqualTo(new Vector3(1, 2, 3)));
}
[UnityTest]
public IEnumerator ManualParentingWorks()
{
var parent = InstantiateForTest(_characterPrefab);
serverObjectManager.Spawn(parent);
var child = InstantiateForTest(_characterPrefab);
child.SpawnSettings = new NetworkSpawnSettings
{
SendPosition = true,
SendParent = SpawnParentingMode.Manual
};
child.Parent = parent;
child.transform.localPosition = new Vector3(4, 5, 6);
serverObjectManager.Spawn(child);
yield return null;
yield return null;
var clientParent = _remoteClients[0].Get(parent);
var clientChild = _remoteClients[0].Get(child);
Assert.That(clientChild.transform.parent, Is.EqualTo(clientParent.transform));
Assert.That(clientChild.transform.localPosition, Is.EqualTo(new Vector3(4, 5, 6)));
}
[UnityTest]
public IEnumerator SpawnWithParentIdentityOverload()
{
var parent = InstantiateForTest(_characterPrefab);
serverObjectManager.Spawn(parent);
var child = InstantiateForTest(_characterPrefab);
child.SpawnSettings = new NetworkSpawnSettings { SendParent = SpawnParentingMode.Manual };
serverObjectManager.Spawn(child, parent);
yield return null;
yield return null;
var clientParent = _remoteClients[0].Get(parent);
var clientChild = _remoteClients[0].Get(child);
Assert.That(child.transform.parent, Is.EqualTo(parent.transform), "Should be parented on server");
Assert.That(clientChild.transform.parent, Is.EqualTo(clientParent.transform), "Should be parented on client");
}
[UnityTest]
public IEnumerator AutoParentingFindsHighestIdentity()
{
var grandParent = InstantiateForTest(_characterPrefab);
serverObjectManager.Spawn(grandParent);
var parentWithoutIdentity = new GameObject("ParentNoNI").transform;
parentWithoutIdentity.SetParent(grandParent.transform);
var child = InstantiateForTest(_characterPrefab);
child.SpawnSettings = new NetworkSpawnSettings { SendParent = SpawnParentingMode.Auto };
child.transform.SetParent(parentWithoutIdentity);
serverObjectManager.Spawn(child);
yield return null;
yield return null;
var clientGrandParent = _remoteClients[0].Get(grandParent);
var clientChild = _remoteClients[0].Get(child);
Assert.That(clientChild.transform.parent, Is.EqualTo(clientGrandParent.transform));
Object.DestroyImmediate(parentWithoutIdentity.gameObject);
}
}
}