-
-
Notifications
You must be signed in to change notification settings - Fork 11
Entity
Entity
public struct Entity
An entity is a general purpose object. It only consists of a unique id (EntityIdentifier). Components can be assigned to an entity to give it behavior or functionality. An entity creates the relationship between all it's assigned components.
CustomDebugStringConvertible
, CustomStringConvertible
, Equatable
The unique entity identifier.
var identifier: EntityIdentifier
Returns the number of components for this entity.
var numComponents: Int
Checks if this entity has any components.
var hasComponents: Bool
var description: String
var debugDescription: String
@inlinable public func get<C>() -> C? where C: Component
@inlinable public func get<A>(component compType: A.Type = A.self) -> A? where A: Component
@inlinable public func get<A, B>(components _: A.Type, _: B.Type) -> (A?, B?) where A: Component, B: Component
@inlinable public func get<A, B, C>(components _: A.Type, _: B.Type, _: C.Type) -> (A?, B?, C?) where A: Component, B: Component, C: Component
Get the value of a component using the key Path to the property in the component.
@inlinable public func get<Comp, Value>(valueAt componentKeyPath: KeyPath<Comp, Value>) -> Value where Comp: Component
A Comp
instance must be assigned to this entity!
- componentKeyPath: The
KeyPath
to the property of the given component.
Get the value of a component using the key Path to the property in the component.
@inlinable public func get<Comp, Value>(valueAt componentKeyPath: KeyPath<Comp, Value?>) -> Value? where Comp: Component
A Comp
instance must be assigned to this entity!
- componentKeyPath: The
KeyPath
to the property of the given component.
Set the value of a component using the key path to the property in the component.
@inlinable @discardableResult public func set<Comp, Value>(value newValue: Value, for componentKeyPath: ReferenceWritableKeyPath<Comp, Value>) -> Bool where Comp: Component & DefaultInitializable
Behavior:
- If
Comp
is a component type that is currently not assigned to this entity, a new instance ofComp
will be default initialized andnewValue
will be set at the given keyPath.
- newValue: The value to set.
- componentKeyPath: The
ReferenceWritableKeyPath
to the property of the given component.
Returns true if an action was performed, false otherwise.
Set the value of a component using the key path to the property in the component.
@inlinable @discardableResult public func set<Comp, Value>(value newValue: Value?, for componentKeyPath: ReferenceWritableKeyPath<Comp, Value?>) -> Bool where Comp: Component & DefaultInitializable
Behavior:
- If
Comp
is a component type that is currently not assigned to this entity, a new instance ofComp
will be default initialized andnewValue
will be set at the given keyPath.
- newValue: The value to set.
- componentKeyPath: The
ReferenceWritableKeyPath
to the property of the given component.
Returns true if an action was performed, false otherwise.
@discardableResult public func createEntity() -> Entity
@discardableResult public func createEntity(with components: Component) -> Entity
@discardableResult public func createEntity<C>(with components: C) -> Entity where C: Collection, C.Element == Component
Checks if a component with given type is assigned to this entity.
public func has<C>(_ type: C.Type) -> Bool where C: Component
- type: the component type.
Checks if a component with a given component identifier is assigned to this entity.
public func has(_ compId: ComponentIdentifier) -> Bool
- compId: the component identifier.
Add one or more components to this entity.
@discardableResult public func assign(_ components: Component) -> Entity
- components: one or more components.
Add a component to this entity.
@discardableResult public func assign(_ component: Component) -> Entity
- component: a component.
Add a typed component to this entity.
@discardableResult public func assign<C>(_ component: C) -> Entity where C: Component
- component: the typed component.
@discardableResult public func assign<C>(_ components: C) -> Entity where C: Collection, C.Element == Component
Remove a component from this entity.
@discardableResult public func remove<C>(_ component: C) -> Entity where C: Component
- component: the component.
Remove a component by type from this entity.
@discardableResult public func remove<C>(_ compType: C.Type) -> Entity where C: Component
- compType: the component type.
Remove a component by id from this entity.
@discardableResult public func remove(_ compId: ComponentIdentifier) -> Entity
- compId: the component id.
Remove all components from this entity.
public func removeAll()
Destroy this entity.
public func destroy()
Returns an iterator over all components of this entity.
@inlinable public func makeComponentsIterator() -> ComponentsIterator
public static func ==(lhs: Entity, rhs: Entity) -> Bool
Generated at 2020-11-25T10:28:11+0000 using swift-doc 1.0.0-beta.5.
Types
- ComponentAdded
- ComponentIdentifier
- ComponentInstanceProvider
- ComponentRemoved
- ComponentSingletonProvider
- ComponentTypeProvider
- ComponentsBuilder.Context
- ComponentsBuilderPreview
- DefaultCodingStrategy
- DynamicCodingKey
- DynamicComponentProvider
- DynamicComponentProvider.Closure
- Entity
- Entity.ComponentsIterator
- EntityCreated
- EntityDestroyed
- EntityIdentifier
- EntityState
- EntityStateMachine
- Family
- Family.ComponentsIterator
- Family.EntityComponentIterator
- Family.EntityIterator
- FamilyMemberAdded
- FamilyMemberBuilderPreview
- FamilyMemberRemoved
- FamilyTraitSet
- LinearIncrementingEntityIdGenerator
- ManagedContiguousArray
- Nexus
- Nexus.EntitiesIterator
- Requires1
- Requires2
- Requires3
- Requires4
- Requires5
- Requires6
- Requires7
- Requires8
- Single
- StateComponentMapping
- StringHashing
- UnorderedSparseSet
- UnorderedSparseSet.ElementIterator
Protocols
- CodingStrategy
- Component
- ComponentProvider
- DefaultInitializable
- EntityIdentifierGenerator
- FamilyDecoding
- FamilyEncoding
- FamilyRequirementsManaging
- NexusEvent
- NexusEventDelegate
- RequiringComponents1
- RequiringComponents2
- RequiringComponents3
- RequiringComponents4
- RequiringComponents5
- RequiringComponents6
- RequiringComponents7
- RequiringComponents8
- SingleComponent
- TopLevelDecoder
- TopLevelEncoder