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

相关推荐
yyyyy_abc3 小时前
ceph学习笔记
笔记·ceph·学习
晓梦林3 小时前
ximai靶场学习笔记
android·笔记·学习
nashane3 小时前
HarmonyOS 6学习:外接键盘CapsLock与长截图功能的实战调试与完整解决方案
学习·华为·计算机外设·harmonyos
一口吃俩胖子4 小时前
【脉宽调制DCDC功率变换学习笔记021】时域性能准则
笔记·学习
@杰克成5 小时前
Java学习30
java·开发语言·学习
三品吉他手会点灯6 小时前
C语言学习笔记 - 40.数据类型 - scanf函数的编程规范与非法输入处理
c语言·开发语言·笔记·学习
Bechamz7 小时前
大数据开发学习Day36
大数据·学习
happymaker06268 小时前
SpringBoot学习日记——DAY02(SpringBoot整合Swagger3)
java·spring boot·学习
新手unity自用笔记9 小时前
unity简单新手上手动画系统讲解
unity·游戏引擎