Unity DOTS技术(十) ChunkComponent块组件

文章目录


一.简介

块组件(ChunkComponent),与共享组件类似,但在共用组件时并不会将组件移动到新的块里面去.
当将块组件的值进行修改时.将会把组件中的值进行一个统一的变化,不会产生一个新的组件
在这里插入图片描述

二.例子

1.创建ChunkComponent

在这里插入图片描述

public struct ChunkComponent9 : IComponentData
{
    public int data;
}

2.创建控制类
在这里插入图片描述

public class Test9 : MonoBehaviour
{
    void Start()
    {
        EntityArchetype tempEntityArchtype =                             World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype(ComponentType.ChunkComponent(typeof(ChunkComponent9)));
        World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(tempEntityArchtype);
    }
}

3.测试创建多个ChunkComponent后,修改值
在这里插入图片描述

void Start()
{
    //创建Chunk,注意这里需要用ComponentType.ChunkComponent函数包裹
    EntityArchetype tempEntityArchtype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype(ComponentType.ChunkComponent(typeof(ChunkComponent9)));
    //创建第一个Chunk
    Entity tempEntity = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(tempEntityArchtype);
    //创建第二个Chunk
    World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(tempEntityArchtype);
    //找到Chunk
    ArchetypeChunk tempChunk = World.DefaultGameObjectInjectionWorld.EntityManager.GetChunk(tempEntity);
    //修改Chunk值
    World.DefaultGameObjectInjectionWorld.EntityManager.SetChunkComponentData(tempChunk, new ChunkComponent9() { data = 8 });
}

4.任意物体中挂载后查看
代码中我们只修改了一个值,但两个Chunk值都修改了
在这里插入图片描述

5.块组件的增删改查操作
在这里插入图片描述

using Unity.Entities;
using UnityEngine;
public class Test9 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        //创建Chunk,注意这里需要用ComponentType.ChunkComponent函数包裹
        EntityArchetype tempEntityArchtype = World.DefaultGameObjectInjectionWorld.EntityManager.CreateArchetype(ComponentType.ChunkComponent(typeof(ChunkComponent9)));
        //创建第一个Chunk
        Entity tempEntity = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(tempEntityArchtype);
        //创建第二个Chunk
        World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(tempEntityArchtype);
        //找到Chunk
        ArchetypeChunk tempChunk = World.DefaultGameObjectInjectionWorld.EntityManager.GetChunk(tempEntity);
        //修改Chunk值
        World.DefaultGameObjectInjectionWorld.EntityManager.SetChunkComponentData(tempChunk, new ChunkComponent9() { data = 8 });
        //获取Chunk
        World.DefaultGameObjectInjectionWorld.EntityManager.GetChunkComponentData<ChunkComponent9>(tempChunk);
        //删除Chunk
        World.DefaultGameObjectInjectionWorld.EntityManager.RemoveChunkComponent<ChunkComponent9>(tempEntity);
        //增加Chunk
        World.DefaultGameObjectInjectionWorld.EntityManager.AddChunkComponentData<ChunkComponent9>(tempEntity);
        //存在判断
        World.DefaultGameObjectInjectionWorld.EntityManager.HasChunkComponent<ChunkComponent9>(tempEntity);
    }
}

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小盖子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值