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

相关推荐
東雪木几秒前
软件设计师考试复习——CPU 结构、流水线、存储体系(主存 / 辅存)
学习·软件设计师复习
2501_9181269113 分钟前
学习所有6502写游戏动作的语句
汇编·嵌入式硬件·学习·游戏·个人开发
夏日听雨眠17 分钟前
文件学习9
数据结构·学习·算法
野犬寒鸦17 分钟前
从零起步学习JVM|| 第二章:JVM基本组成及JVM内存区域详解
服务器·开发语言·后端·学习·面试·职场和发展
罗罗攀19 分钟前
PyTorch学习笔记|张量的线性代数运算
人工智能·pytorch·笔记·学习·线性代数
苦涩花开548626 分钟前
Kubernetes学习,记一些笔记
笔记·学习·kubernetes
liliangcsdn27 分钟前
LLM长文本场景-多文档分布式分析示例
人工智能·学习
丝斯201129 分钟前
AI学习笔记整理(74)——Python学习3
笔记·python·学习
Century_Dragon29 分钟前
探索车身修复的数字化课堂 —汽车车身诊断与校正仿真教学软件
学习
qq_5710993530 分钟前
学习周报三十七
人工智能·深度学习·学习