zoukankan      html  css  js  c++  java
  • ECS:WriteGroup

    定义:
    使用WriteGroup标记了同一个component的components就属于一个WriteGroup:
        public struct W : IComponentData
        {
           public int Value;
        }
        [WriteGroup(typeof(W))]
        public struct A : IComponentData
        {
           public int Value;
        }
        [WriteGroup(typeof(W))]
        public struct B : IComponentData
        {
           public int Value;
        }
        上面的代码中,W A B就属于同一个W Group。
     
    使用:
    让WriteGroup生效的方法:在Query中开启WriteGroup选项:
    public class AddingSystem : JobComponentSystem
    {
       protected override JobHandle OnUpdate(JobHandle inputDeps) {
          return Entities
             .WithEntityQueryOptions(EntityQueryOptions.FilterWriteGroup)
             .ForEach((ref W w, in B b) => { }).Schedule(inputDeps);}
    }
    使用EntityQueryDesc: 
    public class AddingSystem : JobComponentSystem
    {
       private EntityQuery m_Query;
       protected override void OnCreate()
       {
           var queryDescription = new EntityQueryDesc
           {
               All = new ComponentType[] {
                  ComponentType.ReadWrite<W>(),
                  ComponentType.ReadOnly<B>()
               },
               Options = EntityQueryOptions.FilterWriteGroup
           };
           m_Query = GetEntityQuery(queryDescription);
       }
       // Define Job and schedule...
    }
    这样,在Query的时候,WriteGroup就会影响查询的结果了。
     
    规则:
    (1)同一个Group的components,查询时只会包含一个,同组的component相互是互斥的,比如上面的W A B,查询结果只会返回包含W A B任意一个的entity;
    (2)可以显示的要求包含同组的其他component。
    以此规则计算,上面的例子中,query结果是包含W和B的,包含A的会被排除。
     
    应用:
    (1)扩展或覆盖原有system功能的写入目标,可以保证原来的system正常工作,但是包含了自己的特殊component的entity按照覆盖的方式工作。
        Unity.Transforms里面的没一个component都是用了write group的特性。
    (2)提供system的可扩展性。
     
     
  • 相关阅读:
    Java控制台常用命令
    redis如何查看所有的key
    An internal error has occurred. Java heap space
    redis演练
    各种编程实现的树
    MYSQL两个数据库字符集保持一致问题
    进程控制之fork函数
    进程控制之进程标识符
    进程环境之getrlimit和setrlimit函数
    进程环境之setjmp和longjmp函数
  • 原文地址:https://www.cnblogs.com/sifenkesi/p/12386453.html
Copyright © 2011-2022 走看看