栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > 其他

Unity DOTS在hybird renderer v2 中rendermesh不显示

其他 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Unity DOTS在hybird renderer v2 中rendermesh不显示

刚出来的时候用过一段时间,各种坑后放弃了,最近看到dots更新了,想重新捡起来玩玩

emmm,结果上来就卡主了,可以说是十分的蛋疼了,直接上解决代码吧

用的URP 2020 LTS ,话说,你这api改的也太离谱了吧

using UnityEngine;
using Unity.Entities;
using Unity.Transforms;
using Unity.Collections;
using Unity.Rendering;
using Unity.Mathematics;

public class TestEntity : MonoBehaviour
{
    public Mesh mesh;
    public Material material;
    private void Start()
    {

        EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

        EntityArchetype entityArchetype = entityManager.CreateArchetype(
            typeof(LevelComponent),
            typeof(Translation),
            typeof(RenderMesh),
            typeof(LocalToWorld),
            typeof(RenderBounds),
            typeof(WorldRenderBounds),
            typeof(BuiltinMaterialPropertyUnity_LightData),
            typeof(WorldToLocal_Tag)
        );

        NativeArray entities = new NativeArray(2, Allocator.Temp);

        entityManager.CreateEntity(entityArchetype, entities);

        for (int i = 0; i < entities.Length; i++)
        {
            Entity entity = entities[i];
            entityManager.SetComponentData(entity, new LevelComponent { value =UnityEngine. Random.Range(10f,20f) });

            entityManager.SetComponentData(entity, new LocalToWorld
            {
                Value = float4x4.TRS(
                 translation: new float3(0,0,0),
                 rotation: quaternion.identity,
                 scale: Vector3.one
             )
            });

            entityManager.SetSharedComponentData(entity, new RenderMesh {
                mesh= mesh,
                material=material,
                subMesh = 0,
                layer = 0,
                castShadows = UnityEngine.Rendering.ShadowCastingMode.On,
                receiveShadows = true
            });
            entityManager.SetComponentData(entity, new RenderBounds { Value = mesh.bounds.ToAABB() });
            entityManager.SetComponentData(entity, new BuiltinMaterialPropertyUnity_LightData { Value = new float4(0, 0, 1, 0) });
        }

        entities.Dispose();


    }
}

我发现在Hybird 0.50还需要在rendermesh设置layermask,绝了

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/901193.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号