Skip to content

Commit 9ce46a8

Browse files
test: NetworkTransform related updates to manual test assets in test project [MTT-2975] (#1842)
* test Updating GenericNetworkObjectBehaviour for additional manual testing capabilities. Added label to the SpawnObject as well as made rotate enabled default. * update Just cleaning up the FixedUpdate method by exiting early if not spawned and not wrapping the rest of the "is spawned" code within an if statement.
1 parent 83343a3 commit 9ce46a8

File tree

2 files changed

+189
-33
lines changed

2 files changed

+189
-33
lines changed

testproject/Assets/Prefabs/SpawnObject.prefab

Lines changed: 131 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,115 @@
11
%YAML 1.1
22
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1 &303758344443245884
4+
GameObject:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
serializedVersion: 6
10+
m_Component:
11+
- component: {fileID: 8153383717491880065}
12+
- component: {fileID: 6579817537154308915}
13+
- component: {fileID: 580714849153498668}
14+
- component: {fileID: 4734956507012629661}
15+
m_Layer: 9
16+
m_Name: ObjectLabel
17+
m_TagString: Untagged
18+
m_Icon: {fileID: 0}
19+
m_NavMeshLayer: 0
20+
m_StaticEditorFlags: 0
21+
m_IsActive: 1
22+
--- !u!4 &8153383717491880065
23+
Transform:
24+
m_ObjectHideFlags: 0
25+
m_CorrespondingSourceObject: {fileID: 0}
26+
m_PrefabInstance: {fileID: 0}
27+
m_PrefabAsset: {fileID: 0}
28+
m_GameObject: {fileID: 303758344443245884}
29+
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
30+
m_LocalPosition: {x: 0, y: 1.6700001, z: 0}
31+
m_LocalScale: {x: 1, y: 1, z: 1}
32+
m_ConstrainProportionsScale: 0
33+
m_Children: []
34+
m_Father: {fileID: 771575417923360822}
35+
m_RootOrder: 0
36+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
37+
--- !u!23 &6579817537154308915
38+
MeshRenderer:
39+
m_ObjectHideFlags: 0
40+
m_CorrespondingSourceObject: {fileID: 0}
41+
m_PrefabInstance: {fileID: 0}
42+
m_PrefabAsset: {fileID: 0}
43+
m_GameObject: {fileID: 303758344443245884}
44+
m_Enabled: 1
45+
m_CastShadows: 1
46+
m_ReceiveShadows: 1
47+
m_DynamicOccludee: 1
48+
m_StaticShadowCaster: 0
49+
m_MotionVectors: 1
50+
m_LightProbeUsage: 1
51+
m_ReflectionProbeUsage: 1
52+
m_RayTracingMode: 2
53+
m_RayTraceProcedural: 0
54+
m_RenderingLayerMask: 1
55+
m_RendererPriority: 0
56+
m_Materials:
57+
- {fileID: 10100, guid: 0000000000000000e000000000000000, type: 0}
58+
m_StaticBatchInfo:
59+
firstSubMesh: 0
60+
subMeshCount: 0
61+
m_StaticBatchRoot: {fileID: 0}
62+
m_ProbeAnchor: {fileID: 0}
63+
m_LightProbeVolumeOverride: {fileID: 0}
64+
m_ScaleInLightmap: 1
65+
m_ReceiveGI: 1
66+
m_PreserveUVs: 0
67+
m_IgnoreNormalsForChartDetection: 0
68+
m_ImportantGI: 0
69+
m_StitchLightmapSeams: 1
70+
m_SelectedEditorRenderState: 3
71+
m_MinimumChartSize: 4
72+
m_AutoUVMaxDistance: 0.5
73+
m_AutoUVMaxAngle: 89
74+
m_LightmapParameters: {fileID: 0}
75+
m_SortingLayerID: 0
76+
m_SortingLayer: 0
77+
m_SortingOrder: 0
78+
m_AdditionalVertexStreams: {fileID: 0}
79+
--- !u!102 &580714849153498668
80+
TextMesh:
81+
serializedVersion: 3
82+
m_ObjectHideFlags: 0
83+
m_CorrespondingSourceObject: {fileID: 0}
84+
m_PrefabInstance: {fileID: 0}
85+
m_PrefabAsset: {fileID: 0}
86+
m_GameObject: {fileID: 303758344443245884}
87+
m_Text: No State
88+
m_OffsetZ: 0
89+
m_CharacterSize: 1
90+
m_LineSpacing: 1
91+
m_Anchor: 7
92+
m_Alignment: 0
93+
m_TabSize: 4
94+
m_FontSize: 24
95+
m_FontStyle: 0
96+
m_RichText: 1
97+
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
98+
m_Color:
99+
serializedVersion: 2
100+
rgba: 4294967295
101+
--- !u!114 &4734956507012629661
102+
MonoBehaviour:
103+
m_ObjectHideFlags: 0
104+
m_CorrespondingSourceObject: {fileID: 0}
105+
m_PrefabInstance: {fileID: 0}
106+
m_PrefabAsset: {fileID: 0}
107+
m_GameObject: {fileID: 303758344443245884}
108+
m_Enabled: 1
109+
m_EditorHideFlags: 0
110+
m_Script: {fileID: 11500000, guid: 7b85e388ccb24094d97ef2c46a7ef0d2, type: 3}
111+
m_Name:
112+
m_EditorClassIdentifier:
3113
--- !u!1 &771575417923360811
4114
GameObject:
5115
m_ObjectHideFlags: 0
@@ -33,7 +143,9 @@ Transform:
33143
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
34144
m_LocalPosition: {x: 0, y: 1, z: 0}
35145
m_LocalScale: {x: 0.5, y: 0.75, z: 0.5}
36-
m_Children: []
146+
m_ConstrainProportionsScale: 0
147+
m_Children:
148+
- {fileID: 8153383717491880065}
37149
m_Father: {fileID: 0}
38150
m_RootOrder: 0
39151
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -144,9 +256,13 @@ MonoBehaviour:
144256
m_Script: {fileID: 11500000, guid: fa7bfe2bc280049f38557d643d8a3471, type: 3}
145257
m_Name:
146258
m_EditorClassIdentifier:
147-
m_MoveRandomly: 0
148259
IsRegisteredPoolObject: 0
149260
IsRemovedFromPool: 0
261+
m_MoveRandomly: 0
262+
m_Rotate: 1
263+
m_RotationAmount: {x: 0, y: 3, z: 0}
264+
m_TestClientSideNotifcation: 0
265+
HasHandler: 0
150266
--- !u!114 &4600632750638426092
151267
MonoBehaviour:
152268
m_ObjectHideFlags: 0
@@ -159,7 +275,17 @@ MonoBehaviour:
159275
m_Script: {fileID: 11500000, guid: e96cb6065543e43c4a752faaa1468eb1, type: 3}
160276
m_Name:
161277
m_EditorClassIdentifier:
162-
Authority: 0
163-
Channel: 0
278+
SyncPositionX: 1
279+
SyncPositionY: 1
280+
SyncPositionZ: 1
281+
SyncRotAngleX: 1
282+
SyncRotAngleY: 1
283+
SyncRotAngleZ: 1
284+
SyncScaleX: 1
285+
SyncScaleY: 1
286+
SyncScaleZ: 1
287+
PositionThreshold: 0.001
288+
RotAngleThreshold: 0.01
289+
ScaleThreshold: 0.01
164290
InLocalSpace: 0
165-
FixedSendsPerSecond: 5
291+
Interpolate: 1

testproject/Assets/Tests/Manual/Scripts/GenericNetworkObjectBehaviour.cs

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using Unity.Netcode;
21
using UnityEngine;
2+
using Unity.Netcode;
3+
using Unity.Netcode.Components;
34

45
namespace TestProject.ManualTests
56
{
@@ -8,19 +9,47 @@ namespace TestProject.ManualTests
89
/// </summary>
910
public class GenericNetworkObjectBehaviour : NetworkBehaviour
1011
{
12+
/// <summary>
13+
/// Tells us that we are registered with a NetworkPefab pool
14+
/// This is primarily for late joining clients and object synchronization.
15+
/// </summary>
16+
public bool IsRegisteredPoolObject;
17+
18+
/// <summary>
19+
/// This tells us that the NetworkObject has been removed from a pool
20+
/// This is primarily to handle NetworkPrefab pool that was loaded in an additive scene and the
21+
/// additive scene was unloaded but the NetworkObject persisted (i.e. was spawned in a different scene)
22+
/// </summary>
23+
public bool IsRemovedFromPool;
24+
1125
[SerializeField]
1226
[Tooltip("This will make the spawned objects move around randomly. !Caution! You can generate a lot of objects this way!")]
1327
private bool m_MoveRandomly = true;
1428

29+
[SerializeField]
30+
private bool m_Rotate = false;
31+
32+
[SerializeField]
33+
private Vector3 m_RotationAmount = new Vector3(0.0f, 1.0f, 0.0f);
34+
35+
[Header("Manual Testing")]
36+
37+
[SerializeField]
38+
[Tooltip("When enabled this will make connected clients attempt to change the transform locally which should generate a" +
39+
" console log warning message on the client side.")]
40+
private bool m_TestClientSideNotifcation = false;
41+
1542
private Rigidbody m_RigidBody;
1643
private MeshRenderer m_MeshRenderer;
44+
private NetworkTransform m_NetworkTransform;
1745
private Vector3 m_Direction;
1846
private float m_Velocity;
1947

2048
private void Start()
2149
{
2250
m_RigidBody = GetComponent<Rigidbody>();
2351
m_MeshRenderer = GetComponent<MeshRenderer>();
52+
m_NetworkTransform = GetComponent<NetworkTransform>();
2453
}
2554

2655
/// <summary>
@@ -102,42 +131,43 @@ public void SetDirectionAndVelocity(Vector3 direction, float velocity)
102131
/// </summary>
103132
private void FixedUpdate()
104133
{
105-
if (NetworkManager != null && NetworkManager.IsListening)
134+
// Don't do anything until spawned
135+
if (!IsSpawned)
136+
{
137+
return;
138+
}
139+
140+
if (IsServer)
106141
{
107-
if (IsOwner)
142+
m_RigidBody.MovePosition(transform.position + m_Direction * (m_Velocity * Time.fixedDeltaTime));
143+
144+
if (m_Rotate && m_NetworkTransform != null && (m_NetworkTransform.SyncRotAngleX || m_NetworkTransform.SyncRotAngleY || m_NetworkTransform.SyncRotAngleZ))
108145
{
109-
m_RigidBody.MovePosition(transform.position + m_Direction * (m_Velocity * Time.fixedDeltaTime));
146+
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + m_RotationAmount);
147+
}
110148

111-
if (m_MoveRandomly && Random.Range(0.0f, 1.0f) < 0.01f)
112-
{
113-
var dir = Random.insideUnitCircle;
114-
m_Direction.x = dir.x;
115-
m_Direction.z = dir.y;
116-
}
149+
if (m_MoveRandomly && Random.Range(0.0f, 1.0f) < 0.01f)
150+
{
151+
var dir = Random.insideUnitCircle;
152+
m_Direction.x = dir.x;
153+
m_Direction.z = dir.y;
117154
}
118-
else
155+
}
156+
else
157+
{
158+
if (m_TestClientSideNotifcation)
119159
{
120-
if (NetworkObject != null && !NetworkObject.isActiveAndEnabled)
121-
{
122-
Debug.LogWarning($"{nameof(GenericNetworkObjectBehaviour)} id {NetworkObject.NetworkObjectId} is not active and enabled but game object is still active!");
123-
}
160+
// When LogLevel is Developer this should generate a warning message on the client side
161+
m_RigidBody.MovePosition(transform.position + Vector3.one * (2.0f * Time.fixedDeltaTime));
162+
}
163+
164+
if (NetworkObject != null && !NetworkObject.isActiveAndEnabled)
165+
{
166+
Debug.LogWarning($"{nameof(GenericNetworkObjectBehaviour)} id {NetworkObject.NetworkObjectId} is not active and enabled but game object is still active!");
124167
}
125168
}
126169
}
127170

128-
/// <summary>
129-
/// Tells us that we are registered with a NetworkPefab pool
130-
/// This is primarily for late joining clients and object synchronization.
131-
/// </summary>
132-
public bool IsRegisteredPoolObject;
133-
134-
/// <summary>
135-
/// This tells us that the NetworkObject has been removed from a pool
136-
/// This is primarily to handle NetworkPrefab pool that was loaded in an additive scene and the
137-
/// additive scene was unloaded but the NetworkObject persisted (i.e. was spawned in a different scene)
138-
/// </summary>
139-
public bool IsRemovedFromPool;
140-
141171
private void Update()
142172
{
143173
if (IsOwner && m_ShouldDespawn && NetworkObject != null)

0 commit comments

Comments
 (0)