-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChildSpawnMessage.cs
More file actions
88 lines (70 loc) · 2 KB
/
ChildSpawnMessage.cs
File metadata and controls
88 lines (70 loc) · 2 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
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class ChildSpawnMessage : MessageBase
{
public const short MessageId = 8000;
public NetworkInstanceId ParentId
{
get { return m_parentId; }
}
public NetworkInstanceId Id
{
get { return m_id; }
}
public int ChildId
{
get { return m_childId; }
}
public Vector3 Position
{
get { return m_position; }
}
public byte[] Payload
{
get { return m_payload; }
}
public ChildSpawnMessage()
{
}
public ChildSpawnMessage(ChildIdentity obj, byte[] payload)
{
NetworkIdentity childIdentity = obj.GetComponent<NetworkIdentity>();
m_id = childIdentity.netId;
m_childId = obj.ChildId;
m_position = obj.transform.position;
NetworkIdentity parentId = null;
Transform parent = obj.transform.parent;
while (parentId == null && parent != null)
{
parentId = parent.GetComponent<NetworkIdentity>();
parent = parent.parent;
}
if (parentId)
m_parentId = parentId.netId;
else
Debug.LogError("Error: Child identity was placed on an object with no parent with a network identity");
m_payload = payload;
}
public override void Serialize(NetworkWriter writer)
{
writer.Write(m_id);
writer.Write(m_parentId);
writer.Write(m_childId);
writer.Write(m_position);
writer.WriteBytesFull(m_payload);
}
public override void Deserialize(NetworkReader reader)
{
m_id = reader.ReadNetworkId();
m_parentId = reader.ReadNetworkId();
m_childId = reader.ReadInt32();
m_position = reader.ReadVector3();
m_payload = reader.ReadBytesAndSize();
}
private NetworkInstanceId m_parentId;
private NetworkInstanceId m_id;
private int m_childId;
private Vector3 m_position;
private byte[] m_payload;
}