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

相关推荐
cape_NO_716 分钟前
运动控制卡--概述学习
学习·自动化
飞向星河1 小时前
SV学习笔记——数组、队列
笔记·学习·c#
胡西风_foxww2 小时前
中学学习难点管理思维魔方
学习·中学·难点
末零2 小时前
Unity 取色板
unity·游戏引擎
无敌最俊朗@2 小时前
Unity大型游戏开发全流程指南
unity·游戏引擎
Moonnnn.3 小时前
51单片机——程序执行过程(手工汇编)
汇编·笔记·嵌入式硬件·学习·51单片机
虾米神探3 小时前
Unity InputField + ScrollRect实现微信聊天输入框功能
unity·游戏引擎
大宝剑1703 小时前
blender学习25.3.8
学习·blender
咩咩觉主4 小时前
C# &Unity 唐老狮 No.7 模拟面试题
开发语言·unity·c#
咩咩觉主4 小时前
Unity网络开发基础 (2) 网络协议基础
网络·unity·c#