全局唯一组件,修改数值后不会产生新的组件,而是全部实体的块组件内容都同步变化。
cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
public struct MyChunkComponentData : IComponentData
{
public int num;
}
cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
public class ChunkTest : MonoBehaviour
{
private void Start()
{
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
//创建Chunk类型
EntityArchetype type = entityManager.CreateArchetype(ComponentType.ChunkComponent(typeof(MyChunkComponentData)));
//创建Chunk实体1
Entity chunkEntity = entityManager.CreateEntity(type);
//创建Chunk实体2
Entity chunkEntity2 = entityManager.CreateEntity(type);
//获取实体1的Chunk类对象
ArchetypeChunk chunk = entityManager.GetChunk(chunkEntity);
//修改Chunk值
entityManager.SetChunkComponentData(chunk, new MyChunkComponentData() { num = 10 });
}
}
修改其中一个Chunk对象的值其他实体的Chunk组件也会同步修改。