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<Entity> entities = new NativeArray<Entity>(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,绝了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值