Exemple #1
0
    public bool AddComponent(Entity entity, ComponentType componentType)
    {
        if (HasComponent(entity, componentType))
        {
            return(false);
        }

        EntityComponentStore->AssertCanAddComponent(entity, componentType);

        if (m_IsMainThread)
        {
            EntityManager.BeforeStructuralChange();
        }

        var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

        StructuralChange.AddComponentEntity(EntityComponentStore, &entity, componentType.TypeIndex);

        var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);

        EntityQueryManager.AddAdditionalArchetypes(changedArchetypes);
        ManagedComponentStore.Playback(ref EntityComponentStore->ManagedChangesTracker);

        return(true);
    }
Exemple #2
0
    /// <summary>
    /// EntityManager.BeforeStructuralChange must be called before invoking this.
    /// ManagedComponentStore.Playback must be called after invoking this.
    /// EntityQueryManager.AddAdditionalArchetypes must be called after invoking this.
    /// Invoking this must be wrapped in ArchetypeChangeTracking.
    /// </summary>
    /// <param name="entity"></param>
    /// <param name="componentType"></param>
    /// <returns></returns>
    public bool AddComponentDuringStructuralChange(Entity entity, ComponentType componentType)
    {
        if (HasComponent(entity, componentType))
        {
            return(false);
        }

        var result = StructuralChange.AddComponentEntity(EntityComponentStore, &entity, componentType.TypeIndex);

        return(result);
    }