【Unity3D】ECS入门学习(八)块组件 ArchetypeChunk

全局唯一组件,修改数值后不会产生新的组件,而是全部实体的块组件内容都同步变化。

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组件也会同步修改。

相关推荐
Yupureki24 分钟前
从零开始的C++学习生活 9:stack_queue的入门使用和模板进阶
c语言·数据结构·c++·学习·visual studio
小年糕是糕手1 小时前
【数据结构】单链表“0”基础知识讲解 + 实战演练
c语言·开发语言·数据结构·c++·学习·算法·链表
半夏知半秋1 小时前
lua对象池管理工具剖析
服务器·开发语言·后端·学习·lua
CoookeCola2 小时前
Google Landmarks Dataset v2 (GLDv2):面向实例级识别与检索的500万图像,200k+类别大规模地标识别基准
图像处理·人工智能·学习·目标检测·计算机视觉·视觉检测
syt_biancheng2 小时前
C++ 多态(1)
jvm·c++·学习
ue星空2 小时前
逆向分析光与影:33号远征队使用的UE技术栈
笔记·学习
立志成为大牛的小牛2 小时前
数据结构——二十二、并查集(王道408)
c语言·数据结构·笔记·学习·考研
二十三之歌2 小时前
Redis 中文学习手册
数据库·redis·学习
青衫码上行3 小时前
【从0开始学习Java | 第21篇】网络编程综合练习
java·网络·学习
失心疯_20233 小时前
PyQt开发_小学学习辅助工具
学习·pyqt