当前位置: 首页 > news >正文

Unity Dots从入门到精通之 Prefab引用 转 实体引用

文章目录

    • 前言
    • 安装 DOTS 包
    • 实体引用Authoring

前言

DOTS(面向数据的技术堆栈)是一套由 Unity 提供支持的技术,用于提供高性能游戏开发解决方案,特别适合需要处理大量数据的游戏,例如大型开放世界游戏。

本文讲解我在开发Dots的过程中,当我们有一些预制体,希望作为实体,在运行时会克隆出来的,比如士兵和子弹。我们可以新建一个EntitiesReferences实体引用类。用来存储多个预制体转化的实体引用。

  • Unity 2022.3.52f1
  • Entities 1.3.10

安装 DOTS 包

要安装 DOTS 包,请按照以下步骤操作:

(1)从菜单“窗口 → 包管理器”打开包管理器。
(2)搜索“ Entities” 并安装 Entities和Entities Graphics。
(3)搜索“ Universal RP” 并安装 Universal RP,并设置Graphics/Scriptable Render Pipeline Settings。

这会添加“实体”作为依赖项,并递归添加它所依赖的关联包( Burst、Collections、Jobs、Mathematics等)。

在这里插入图片描述

实体引用Authoring

using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;

public class EntitiesReferencesAuthoring : MonoBehaviour
{
    public GameObject redSoldierPrefab;
    public GameObject blueSoldierPrefab;
    
    public GameObject bulletPrefabPrefab;
    
    public Transform redStartPoint;
    public Transform blueStartPoint;

	//Baker类,把Mono转为Entity
    private class Baker : Baker<EntitiesReferencesAuthoring>
    {
        public override void Bake(EntitiesReferencesAuthoring authoring)
        {
            Entity entity = GetEntity(TransformUsageFlags.Dynamic);
            AddComponent(entity, new EntitiesReferences
            {
                redMeleePrefabEntity = GetEntity(authoring.redSoldierPrefab, TransformUsageFlags.Dynamic),
                blueMeleePrefabEntity = GetEntity(authoring.blueSoldierPrefab, TransformUsageFlags.Dynamic),
               
                bulletPrefabEntity = GetEntity(authoring.bulletPrefabPrefab, TransformUsageFlags.Dynamic),
                
                redStartPosition = authoring.redStartPoint.position,
                blueStartPosition = authoring.blueStartPoint.position,
            });
        }
    }
}

//实体引用类
public struct EntitiesReferences : IComponentData
{
    public Entity redMeleePrefabEntity;
    public Entity blueMeleePrefabEntity;

    public Entity bulletPrefabEntity;
    
    public float3 redStartPosition;
    public float3 blueStartPosition;
}

相关文章:

  • QT:TCP示例
  • linux查看定时任务与设置定时任务
  • C#的判断语句总结
  • C++面试题:C++怎么避免头文件循环引用?
  • 游戏引擎学习第146天
  • 学习小程序开发--Day1
  • 学习网络安全需要哪些基础?
  • C++单例进化论
  • P8686 [蓝桥杯 2019 省 A] 修改数组--并查集 or Set--lower_bound()的解法!!!
  • 设计模式 一、软件设计原则
  • Spring源码探析(二):BootstrapContext初始化深度解析(默认配置文件加密实现原理)
  • [算法笔记]cin和getline的并用、如何区分两个数据对、C++中std::tuple类
  • uniapp版本加密货币行情应用
  • Unity DOTS从入门到精通之EntityCommandBufferSystem
  • C#模拟鼠标点击,模拟鼠标双击,模拟鼠标恒定速度移动,可以看到轨迹
  • 【vitepress】如何搭建并部署自己的博客网站
  • sqlserver中的锁模式 | SQL SERVER如何开启MVCC(使用row-versioning)【启用行版本控制减少锁争用】
  • 基于单片机的智慧农业大棚系统(论文+源码)
  • mysql(community版)压缩包安装教程
  • 【计算机网络】确认家庭网络是千兆/百兆带宽并排查问题
  • 巴基斯坦称未违反停火协议
  • “一节课、两小时”,体育正在回归“C位”
  • 解放军仪仗分队参加白俄罗斯纪念苏联伟大卫国战争胜利80周年阅兵活动
  • 东方红资管官宣:41岁原国信资管董事长成飞出任新总经理
  • 上海市委常委会会议暨市生态文明建设领导小组会议研究基层减负、生态环保等事项
  • 上海杨浦:优秀“博主”购房最高可获200万补贴