刚出来的时候用过一段时间,各种坑后放弃了,最近看到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();
}
}
|