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

相关推荐
今天你TLE了吗2 小时前
Stream流学习总结
java·学习
周全全6 小时前
基于ElasticSearch的语义检索学习-向量化数据、向量化相似度、向量化检索
大数据·学习·elasticsearch
4***72136 小时前
网络爬虫学习:借助DeepSeek完善爬虫软件,实现模拟鼠标右键点击,将链接另存为本地文件
爬虫·学习·计算机外设
t***31656 小时前
爬虫学习案例3
爬虫·python·学习
hhcccchh6 小时前
学习vue第七天 从单页面应用(SPA)进化为后台管理系统架构
vue.js·学习·系统架构
文涛是个小白呀7 小时前
Java集合大调研
java·学习·链表·面试
hd51cc7 小时前
MFC多线程学习笔记三:线程间的通信
笔记·学习
hd51cc7 小时前
MFC多线程学习笔记四:线程间的同步
笔记·学习·mfc
龙智DevSecOps解决方案7 小时前
Perforce《2025游戏技术现状报告》Part 1:游戏引擎技术的广泛影响以及生成式AI的成熟之路
人工智能·unity·游戏引擎·游戏开发·perforce
wdfk_prog7 小时前
[Linux]学习笔记系列 -- [block]bfq-iosched
linux·笔记·学习