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

相关推荐
拾忆-eleven6 分钟前
NLP学习路线图(十六):N-gram模型
人工智能·学习·自然语言处理
aa32422432431 小时前
Scratch节日 | 六一儿童节抓糖果
学习·游戏·青少年编程·节日
moxiaoran57531 小时前
uni-app学习笔记十九--pages.json全局样式globalStyle设置
笔记·学习·uni-app
霸王蟹2 小时前
从前端工程化角度解析 Vite 打包策略:为何选择 Rollup 而非 esbuild。
前端·笔记·学习·react.js·vue·rollup·vite
我的golang之路果然有问题3 小时前
快速掌握 GO 之 RabbitMQ 结合 gin+gorm 案例
笔记·后端·学习·golang·rabbitmq·gin
xiaohanbao095 小时前
day41 python图像识别任务
人工智能·python·深度学习·神经网络·学习·机器学习
Chef_Chen5 小时前
从0开始学习R语言--Day13--混合效应与生存分析
学习
这是另一个世界5 小时前
Kali Linux从入门到实战:系统详解与工具指南
linux·运维·服务器·网络·学习·web安全·网络安全
Binary_ey6 小时前
AR-HUD 光波导方案优化难题待解?OAS 光学软件来破局
学习·软件需求·光学软件·光波导
我的golang之路果然有问题6 小时前
GO+RabbitMQ+Gin+Gorm+docker 部署 demo
笔记·后端·学习·docker·golang·rabbitmq·gin