欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > Unity Dots从入门到精通之 Prefab引用 转 实体引用

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

2025/3/10 7:11:05 来源:https://blog.csdn.net/qq563129582/article/details/146139947  浏览:    关键词: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转为Entityprivate 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;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词