// 定义四叉树与对象数据 NativeQuadtree<Entity> quadTree = new NativeQuadtree<Entity>(Allocator.Persistent); NativeArray<Entity> entities = ...; // 从ECS获取实体 // 插入对象 JobHandle insertJob = new InsertJob { QuadTree = quad
EntityQuery entityQuery = GetEntityQuery(typeof(MyComponent), typeof(Translation)); NativeArray<Entity> entities = entityQuery.ToEntityArray(Allocator.TempJob); // Batch process entities Entities.ForEach((ref MyComponent myComponent, ref Translation translation) => { // Process entity and ...
以ComponentType数组作为参数创建Entity 以EntityArchetype作为参数创建Entity 利用现有的Entity,调用Instantiate实例化同样的Entity 创建空的Entity,然后为其添加组件(可以立即添加,也可以在需要时添加(事实上不推荐动态添加,删除))。 可以一次创建多个Entities: 使用Create Entity,创建共享archetype的Entity的数组(NativeArray)。
4.将上面的预制Entity存到某个Component中用于实例化。 5.通过SystemAPI.GetSingleton获取上面单例Component,然后CollectionHelper.CreateNativeArray接口申请对应数量的Entity容器。 6.调用state.EntityManager.Instantiate,传入Component中缓存的Entity,以及申请好的NativeArray<Entity>容器变量,NativeArray<Entity>变量会填充好实例...
现在换种思路,先创建一个Entity,并将要传递的信息组织成IComponentData绑到Entity上,形成一个个消息实体,其他ISystem通过去遍历这些消息实体实现数据在实体间传递的功能。 这种做法不仅适用于ISystem和ISystem之间的数据传递,甚至适用于MonoBehaviour和ISystem、以及ISystem和SystemBase之间的数据传递。
使用一个EntityArchetype创建一个包含多个component的entity。 使用Instantiate复制现有entity,包括其当前数据。 创建一个没有components的entity,然后向其添加components。(您可以立即添加components,也可以在需要其他components时添加。) 您也可以一次创建多个实体: CreateEntity:使用具有相同archetype的新entities填充NativeArray。
在Execute里面我们使用ChunkEntityEnumerator来遍历chunk里面的每个entity的Component,参考代码如下: NativeArray<VelocityVector> velocityVectors = chunk.GetNativeArray(ref VelocityTypeHandle); NativeArray<ObjectPosition> translations = chunk.GetNativeArray(ref PositionTypeHandle); ...
您还会注意到,用船只数量构建的NativeArray<Entity>类型将生成。管理器的实例化方法采用GameObject参数和指定实例化实体数量的NativeArray<Entity>设置。传入的GameObject必须包含前面提到的GameObjectEntity脚本以及所需的任何组件数据。EntityManager会根据预制件上的数据组件创建实体,而从未实际创建或使用任何GameObjects。
translation.Value = tempEntityPos.Position; }).ScheduleParallel(); // 保证ECB system依赖当前这个Job m_EndSimulationEcbSystem.AddJobHandleForProducer(this.Dependency); } //发射射线Job public struct RaycastJobHandle : IJob { public NativeArray<RigidBody> Bodies; ...
我将粒子加入到NativeArray中,然后使用一个游戏对象预制件来实例化实体,该预制件将用作每个实体使用的所有组件的模版。 基于被定义为碰撞体的游戏对象,循环处理了所有实体来设置数值。 void AddColliders() { // 找到所有碰撞体 GameObject[] colliders = GameObject.FindGameObjectsWithTag("SPHCollider"); ...