docs.unity.cn
    Show / Hide Table of Contents

    Method WithAnyChunkComponent

    WithAnyChunkComponent<T>()

    Add an optional Chunk Component type to the query.

    Declaration
    [GenerateTestsForBurstCompatibility(GenericTypeArguments = new Type[]{typeof(BurstCompatibleComponentData)})]
    public EntityQueryBuilder WithAnyChunkComponent<T>()
    Returns
    Type Description
    EntityQueryBuilder

    The builder object that invoked this method.

    Type Parameters
    Name Description
    T

    Component type to use as an optional, read-only Chunk Component

    Remarks

    To match the resulting query, an Entity must have at least one of the query's optional component types, specified using either Unity.Entities.EntityQueryBuilder.WithAny(Unity.Entities.ComponentType*,System.Int32) or WithAnyChunkComponent<T>(). Chunk components are a distinct component type, which are different from adding the same type as a standard component.

               var entityWithPlayerComponent = EntityManager.CreateEntity();
               EntityManager.AddComponent<Player>(entityWithPlayerComponent);
    
               var entityWithPlayerChunkComponent = EntityManager.CreateEntity();
               EntityManager.AddComponent(entityWithPlayerChunkComponent, ComponentType.ChunkComponent<Player>());
    
               // This query will match both entityWithPlayerComponent and entityWithPlayerChunkComponent
               var playerQuery = new EntityQueryBuilder(Allocator.Temp)
                   .WithAny<Player>()
                   .WithAnyChunkComponent<Player>()
                   .Build(this);

    Compare this to WithAllChunkComponent<T>()

    To add additional optional Chunk Components, call this method multiple times.

    To add component types that are not known at compile time, use WithAny<T>(ref T)

    The query will request read-only access to the referenced component(s). To request read/write access, use Unity.Entities.EntityQueryBuilder.WithAnyChunkComponentRW``1(``0@)

    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on Wednesday, June 21, 2023