public void Can_create_from_schema_object() { var data = new ComponentData(0, SchemaComponentData.Create()); // Easiest way to get a valid `SchemaObject`. try { var schemaObject = data.SchemaData.Value.GetFields(); var position = new Position.Snapshot(new Coordinates(10, 10, 10)); Position.Serialization.SerializeSnapshot(position, schemaObject.AddObject(Position.ComponentId)); var playerHeartbeatClient = new PlayerHeartbeatClient.Snapshot(); PlayerHeartbeatClient.Serialization.SerializeSnapshot(playerHeartbeatClient, schemaObject.AddObject(PlayerHeartbeatClient.ComponentId)); var snapshot = new EntitySnapshot(schemaObject); Assert.IsTrue(snapshot.TryGetComponentSnapshot <Position.Snapshot>(out var outPosition)); Assert.IsTrue( snapshot.TryGetComponentSnapshot <PlayerHeartbeatClient.Snapshot>(out var playerHeartbeat)); Assert.AreEqual(outPosition.Coords.X, 10, Double.Epsilon); } finally { data.SchemaData.Value.Destroy(); } }
public ComponentData Build() { var schemaComponentData = SchemaComponentData.Create(); var fields = schemaComponentData.GetFields(); // Write the read acl var workerRequirementSet = fields.AddObject(1); foreach (var attr in readPermissions) { // Add another WorkerAttributeSet to the list var set = workerRequirementSet.AddObject(1); set.AddString(1, attr); } // Write the component write acl foreach (var writePermission in writePermissions) { var keyValuePair = fields.AddObject(2); keyValuePair.AddUint32(1, writePermission.Key); var containedRequirementSet = keyValuePair.AddObject(2); var containedAttributeSet = containedRequirementSet.AddObject(1); containedAttributeSet.AddString(1, writePermission.Value); } return(new ComponentData(EntityAclComponentId, schemaComponentData)); }
public Snapshot ToComponentSnapshot(global::Unity.Entities.World world) { var componentDataSchema = new ComponentData(11113, SchemaComponentData.Create()); Serialization.SerializeComponent(this, componentDataSchema.SchemaData.Value.GetFields(), world); var snapshot = Serialization.DeserializeSnapshot(componentDataSchema.SchemaData.Value.GetFields()); componentDataSchema.SchemaData?.Destroy(); componentDataSchema.SchemaData = null; return(snapshot); }
/// <summary> /// Adds an entity to the snapshot /// </summary> /// <param name="entityId">The entity ID of the entity to be added to the snapshot</param> /// <param name="entityTemplate">The entity to be added to the snapshot.</param> /// <remarks> /// You should obtain `entityId` using the `GetNextEntityId()` method, otherwise you could be given /// invalid entity IDs. /// </remarks> public void AddEntity(EntityId entityId, EntityTemplate entityTemplate) { if (entities.ContainsKey(entityId)) { throw new ArgumentException($"EntityId {entityId} already exists in the snapshot"); } var entity = entityTemplate.GetEntity(); // This is a no-op if the entity already has persistence. entity.Add(new ComponentData(PersistenceComponentId, SchemaComponentData.Create())); entities[entityId] = entity; }
public void Accept <TUpdate, TSnapshot>(uint componentId, Dynamic.VTable <TUpdate, TSnapshot> vtable) where TUpdate : struct, ISpatialComponentUpdate where TSnapshot : struct, ISpatialComponentSnapshot { if (!data.ContainsKey(componentId)) { return; } var componentData = new ComponentData(componentId, SchemaComponentData.Create()); vtable.SerializeSnapshot((TSnapshot)data[componentId], componentData); Entity.Add(componentData); }