public void ReadPacketStream(NetDataReader stream) { ushort repObjId = stream.GetUShort(); while (repObjId != 0) { Log.Debug($"Reading ghost with id: {repObjId}"); // first read if there is a status change if (stream.GetByte() == 1) { // read the status change if (stream.GetByte() == 1) { Log.Debug("status changed: ADDED"); // added so read the persistent obj id byte objRepId = stream.GetByte(); // Create new instance of the object IPersistentObject obj = PersistentObjectManager.CreatePersistentObject(objRepId); // unpack stream data obj.Deserialize(stream); ReplicatedObjects[repObjId] = new ReplicationRecord { Id = repObjId, Entity = obj as ReplicatableObject }; } else { Log.Debug("status changed: REMOVED"); // remove the record but also need to destroy game object or queue it to be destroyed.. if (ReplicatedObjects.TryGetValue(repObjId, out ReplicationRecord record)) { Log.Debug($"Removing record: {record.Id}"); //GameObject.Destroy(record.Entity); ReplicatedObjects.Remove(repObjId); } } } else { Log.Debug("State update"); // no status change just new state information so unpack into existing replicated obj ReplicatedObjects[repObjId].Entity.Deserialize(stream); } repObjId = stream.GetUShort(); } }
public void StartReplicating(ReplicatableObject obj) { ReplicationRecord record = new ReplicationRecord { Id = NextId++, ReplicationSystemId = Id, Status = ReplicationRecord.ReplicationSystemStatus.Added, Entity = obj }; obj.AddReplicationRecord(record); ReplicatedObjects[record.Id] = record; }
public virtual void AddReplicationRecord(ReplicationRecord record) { ReplicationRecords[record.ReplicationSystemId] = record; }