void IChannelToClientZone.Spawn(int entityId, Type protoType, int ownerId, EntityFlags flags, ISpawnPayload payload) { var entity = _entityFactory.Create(protoType); entity.Id = entityId; entity.ProtoType = protoType; entity.Zone = this; entity.OwnerId = ownerId; entity.Flags = flags; if (payload != null) { payload.Notify(entity); } _entityMap.Add(entityId, entity); entity.OnSpawn(); EntitySpawned?.Invoke(entity); }
public void Spawn(int entityId, Type protoType, int ownerId, EntityFlags flags, ISpawnPayload payload) { _writer.Write((byte)2); _writer.Write(entityId); var typeAlias = TypeTable.GetAlias(protoType); if (typeAlias == 0) { throw new ArgumentException("Type of protoType doesn't have alias. Type: " + protoType.FullName); } _writer.Write(typeAlias); _writer.Write(ownerId); _writer.Write((byte)flags); ProtobufStreamHelper.WriteObject(_writer, payload, TypeTable, TypeModel); }