c# - Unity ECS 不显示自包更新以来创建的实体
问题描述
我尝试生成一些实体并为它们分配网格和材质。不知何故,它们既没有出现在编辑器中,也没有出现在游戏视图中。当我使用“GameObjectToEntity”转换脚本时,实体确实出现了,我尝试了新的 Alpha 版本的编辑器 (2020.1.0a25),但它没有帮助。我也在使用URP。它可能与更新预览包(实体、混合渲染等)有关,因为我在使用旧版本的不同项目中没有问题。不过,我可能在我的代码中遗漏了一些东西。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Unity.Rendering;
using Unity.Transforms;
using Unity.Mathematics;
using Unity.Collections;
public class EntityCreator : MonoBehaviour
{
[SerializeField] public Mesh theMesh;
[SerializeField] public Material theMaterial;
// Start is called before the first frame update
void Start()
{
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
EntityArchetype eArch = entityManager.CreateArchetype(
typeof(RenderMesh),
typeof(Translation),
typeof(LocalToWorld),
typeof(MoveSpeedComponent)
);
NativeArray<Entity> eArray = new NativeArray<Entity>(10, Allocator.Temp);
entityManager.CreateEntity(eArch, eArray);
foreach (Entity ent in eArray)
{
entityManager.SetComponentData(ent, new Translation { Value = new Vector3(0f,0f, 0f) });
entityManager.SetSharedComponentData(ent, new RenderMesh
{
mesh = theMesh, material = theMaterial
});
}
eArray.Dispose();
}
}
非常感谢您抽出宝贵时间
解决方案
EntityArchetype eArch =
entityManager.CreateArchetype(
typeof(RenderMesh),
typeof(Translation),
typeof(LocalToWorld),
typeof(MoveSpeedComponent),
typeof(RenderBounds));
推荐阅读
- javascript - 用 morris.js 放多行
- node.js - 如何使用 child_process 在相同和不同的终端上运行命令?
- django - 有没有办法在运行时生成 SearchVector 字段内容?
- angular - 从模板调用组件时,Angular / 将数据发送到组件
- java - 查找字符串数组中最长和最短的字符串
- kotlin - 从场景形式场景中隐藏 arObject
- c++ - (C++) 用于评估返回不正确值的简单算术表达式的解析树
- vue.js - 嵌套数组 Vue 中的总计
- python - 如何在soup.find_all中打印“未找到”?
- python - 将数据保存在 JSON 文件中