文章目录
- 一.简介
- 二.例子
一.简介
块组件(ChunkComponent),与共享组件类似,但在共用组件时并不会将组件移动到新的块里面去.
当将块组件的值进行修改时.将会把组件中的值进行一个统一的变化,不会产生一个新的组件

二.例子
1.创建ChunkComponent

public struct ChunkComponent9 : IComponentData
{
public int data;
}
2.创建控制类

public class Test9 : MonoBehaviour
{
void Start()
{
EntityArchetype tempEntityArchtype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype(ComponentType.ChunkComponent(typeof(ChunkComponent9)));
World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(tempEntityArchtype);
}
}
3.测试创建多个ChunkComponent后,修改值

void Start()
{
//创建Chunk,注意这里需要用ComponentType.ChunkComponent函数包裹
EntityArchetype tempEntityArchtype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype(ComponentType.ChunkComponent(typeof(ChunkComponent9)));
//创建第一个Chunk
Entity tempEntity = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(tempEntityArchtype);
//创建第二个Chunk
World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(tempEntityArchtype);
//找到Chunk
ArchetypeChunk tempChunk = World.DefaultGameObjectInjectionWorld.EntityManager.GetChunk(tempEntity);
//修改Chunk值
World.DefaultGameObjectInjectionWorld.EntityManager.SetChunkComponentData(tempChunk, new ChunkComponent9() { data = 8 });
}
4.任意物体中挂载后查看
代码中我们只修改了一个值,但两个Chunk值都修改了

5.块组件的增删改查操作

using Unity.Entities;
using UnityEngine;
public class Test9 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
//创建Chunk,注意这里需要用ComponentType.ChunkComponent函数包裹
EntityArchetype tempEntityArchtype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype(ComponentType.ChunkComponent(typeof(ChunkComponent9)));
//创建第一个Chunk
Entity tempEntity = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(tempEntityArchtype);
//创建第二个Chunk
World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(tempEntityArchtype);
//找到Chunk
ArchetypeChunk tempChunk = World.DefaultGameObjectInjectionWorld.EntityManager.GetChunk(tempEntity);
//修改Chunk值
World.DefaultGameObjectInjectionWorld.EntityManager.SetChunkComponentData(tempChunk, new ChunkComponent9() { data = 8 });
//获取Chunk
World.DefaultGameObjectInjectionWorld.EntityManager.GetChunkComponentData<ChunkComponent9>(tempChunk);
//删除Chunk
World.DefaultGameObjectInjectionWorld.EntityManager.RemoveChunkComponent<ChunkComponent9>(tempEntity);
//增加Chunk
World.DefaultGameObjectInjectionWorld.EntityManager.AddChunkComponentData<ChunkComponent9>(tempEntity);
//存在判断
World.DefaultGameObjectInjectionWorld.EntityManager.HasChunkComponent<ChunkComponent9>(tempEntity);
}
}












![[vue2项目]vue2+supermap[mapboxgl]+天地图之地图的基础操作(画线+自定义打点)](https://img-blog.csdnimg.cn/direct/ed72751382f54841aec090524f85ff7e.png)






![七天进阶elasticsearch[one]](https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=.%5Cpic%5C1716887925609.png&pos_id=img-jarqX7Zy-1717580146667)