public void OnNetworkInstantiatedServer(string type, string owner, NetDataWriter writer) { netStates.Clear(); netIDs.Clear(); netStates.Add(SerializeNetworkState(writer)); netIDs.Add(ID); foreach (NetComponent nComponent in Owner.GetAllComponents <NetComponent>()) { // Skip NetworkIdentity component since it's already processed. if (nComponent is NetworkIdentity) { continue; } nComponent.Setup(CurrentNetworkID, owner == "SERVER"); NetworkObjects.TryAdd(CurrentNetworkID, nComponent); CurrentNetworkID++; if (nComponent is INetPersistable netPersist) { netStates.Add(NetLogicHelper.SerializePersistable(netPersist)); } else { netStates.Add(null); // Padding for deserialization. } netIDs.Add(nComponent.ID); } }
public byte[] GetBufferedData(NetDataWriter writer) { netStates.Clear(); netIDs.Clear(); netStates.Add(SerializeNetworkState(writer)); netIDs.Add(ID); foreach (NetComponent nComponent in Owner.GetAllComponents <NetComponent>()) { if (nComponent is INetPersistable netPersist) { netStates.Add(NetLogicHelper.SerializePersistable(netPersist)); } else { netStates.Add(null); // Padding for deserialization. } netIDs.Add(nComponent.ID); } InstantiateData buffer = new InstantiateData(netStates, netIDs.ToArray()); return(buffer.Serialize(new NetDataWriter())); }