/// <summary> /// Removes a component snapshot from the EntityTemplate, if it exists. /// </summary> /// <typeparam name="TSnapshot">The type of the component snapshot.</typeparam> public void RemoveComponent <TSnapshot>() where TSnapshot : struct, ISpatialComponentSnapshot { var id = ComponentDatabase.GetSnapshotComponentId <TSnapshot>(); entityData.Remove(id); acl.RemoveComponentWriteAccess(id); }
/// <summary> /// Attempts to get a component snapshot stored in the EntityTemplate. /// </summary> /// <typeparam name="TSnapshot">The type of the component snapshot.</typeparam> /// <returns>The component snapshot, if the component snapshot exists, null otherwise.</returns> public TSnapshot?GetComponent <TSnapshot>() where TSnapshot : struct, ISpatialComponentSnapshot { if (entityData.TryGetValue(ComponentDatabase.GetSnapshotComponentId <TSnapshot>(), out var snapshot)) { return((TSnapshot)snapshot); } return(null); }
/// <summary> /// Gets the SpatialOS component snapshot if present. /// </summary> /// <returns> The component snapshot, if it exists, or null otherwise.</returns> /// <typeparam name="T">The component type.</typeparam> public T?GetComponentSnapshot <T>() where T : struct, ISpatialComponentSnapshot { var id = ComponentDatabase.GetSnapshotComponentId <T>(); if (components.TryGetValue(id, out var data)) { return((T)data); } return(null); }
/// <summary>Gets the component of the associated type.</summary> /// <param name="component"> /// When this method returns, contains the component, if the component is found; otherwise, the default value <see cref="TSnapshot"/>. This parameter is passed uninitialized. /// </param> /// <typeparam name="TSnapshot">The type of the component snapshot.</typeparam> /// <returns> /// True if this contains a component of type <see cref="TSnapshot"/>; otherwise, false. /// </returns> public bool TryGetComponent <TSnapshot>(out TSnapshot component) where TSnapshot : struct, ISpatialComponentSnapshot { if (entityData.TryGetValue(ComponentDatabase.GetSnapshotComponentId <TSnapshot>(), out var boxedComponent)) { component = (TSnapshot)boxedComponent; return(true); } component = default; return(false); }
// TODO: Make ref readonly when we have a dictionary type with ref indexing semantics. public T GetComponent <T>(EntityId entityId) where T : struct, ISpatialComponentSnapshot { if (!HasComponent <T>(entityId)) { throw new ArgumentException($"The view does not have entity with Entity ID: {entityId.Id} and component with ID: {ComponentDatabase.GetSnapshotComponentId<T>()}"); } var storage = (IViewComponentStorage <T>)typeToViewStorage[typeof(T)]; return(storage.GetComponent(entityId.Id)); }
/// <summary> /// Sets the write access worker attribute for a given component. /// </summary> /// <param name="writeAccess">The write access worker attribute.</param> /// <typeparam name="TSnapshot">The type of the component.</typeparam> public void SetComponentWriteAccess <TSnapshot>(string writeAccess) where TSnapshot : struct, ISpatialComponentSnapshot { SetComponentWriteAccess(ComponentDatabase.GetSnapshotComponentId <TSnapshot>(), writeAccess); }
/// <summary> /// Retrieves the write access worker attribute for a given component. /// </summary> /// <typeparam name="TSnapshot">The type of the component.</typeparam> /// <returns>The write access worker attribute, if it exists, null otherwise.</returns> public string GetComponentWriteAccess <TSnapshot>() where TSnapshot : struct, ISpatialComponentSnapshot { return(GetComponentWriteAccess(ComponentDatabase.GetSnapshotComponentId <TSnapshot>())); }
/// <summary> /// Checks if a component snapshot is stored in the EntityTemplate. /// </summary> /// <typeparam name="TSnapshot">The type of the component snapshot.</typeparam> /// <returns>True, if the component snapshot exists, false otherwise.</returns> public bool HasComponent <TSnapshot>() where TSnapshot : struct, ISpatialComponentSnapshot { return(HasComponent(ComponentDatabase.GetSnapshotComponentId <TSnapshot>())); }