日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Unity DOTS ECS 0.50版本,海浪Demo

發布時間:2024/1/18 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Unity DOTS ECS 0.50版本,海浪Demo 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目前更新了新版ECS,移步新文章

ECS1.0.10海浪demo更新

國內2022-3-17更新了ECS 0.50版本,目前unity2020.3版本可以用,2021會報錯;

安裝

manifest.json添加下面三行

"com.unity.entities": "0.50.0-preview.24","com.unity.rendering.hybrid": "0.50.0-preview.24","com.havok.physics": "0.50.0-preview.24",

注意

  • 需要urp或hdrp,Hybrid Renderer升級到V2,且不支持內置渲染管線;
    詳情查看文檔:
    https://docs.unity3d.com/Packages/com.unity.rendering.hybrid@0.50/manual/creating-a-new-hybrid-renderer-project.html
  • Hybrid Renderer新版本需要設置RenderMesh的layerMask,不然屏幕上不顯示物體;
  • Burst啟用Enable Compilation后,不支持單例模式,需要關閉;
  • Demo腳本

    新建場景,掛載StartBehaviour.cs,直接運行

    Component

    HeightComponent.cs

    using Unity.Entities;namespace Component {public struct HeightComponent : IComponentData{public float InitiateHeight;public float MaxHeight;} }

    SpeedComponent.cs

    using Unity.Entities;namespace Component {public struct SpeedComponent : IComponentData{public float Speed;} }

    System

    RotationSystem.cs

    using Component; using Unity.Entities; using Unity.Mathematics; using Unity.Transforms; using UnityEngine;public partial class RotationSystem : SystemBase {protected override void OnUpdate(){var elapsedTime = Time.ElapsedTime;Entities.ForEach((Entity entity,ref Translation translation,in Rotation rotation,in HeightComponent heightComponent,in SpeedComponent speedComponent) =>{heightComponent.MaxHeight;translation.Value.y =(float) math.sin((elapsedTime + heightComponent.InitiateHeight) * StartBehaviour.Instance.speed) *StartBehaviour.Instance.maxHeight;// }).WithoutBurst().Run();// }).Schedule();}).ScheduleParallel();} }

    StartBehaviour.cs

    using System; using Component; using Unity.Entities; using Unity.Mathematics; using Unity.Rendering; using Unity.Transforms; using UnityEngine;public class StartBehaviour : MonoBehaviour {public static StartBehaviour Instance { get; private set; }[SerializeField] public int count = 100;[SerializeField] public float noiseRange = 20f;[SerializeField] public float noiseValue = 2f;[SerializeField] public float speed = 4f;[SerializeField] public float maxHeight = 1f;[SerializeField] private Mesh unitMesh;[SerializeField] private Material unitMaterial;private EntityManager _entityManager;private void Awake(){if (null == Instance)Instance = this;elseDestroy(gameObject);DontDestroyOnLoad(this);}void Start(){_entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;var archetype = _entityManager.CreateArchetype(typeof(Rotation),typeof(Translation),typeof(HeightComponent),typeof(SpeedComponent),typeof(RenderBounds),typeof(RenderMesh),typeof(LocalToWorld));for (int i = 0; i < count; i++){for (int j = 0; j < count; j++){CreateEntity(archetype, new Vector3(i * 1, 0, j * 1));}}}void CreateEntity(EntityArchetype archetype, Vector3 pos){float2 float2 = new float2(pos.x / noiseRange, pos.z / noiseRange);float f = noise.snoise(float2) / noiseValue;pos.y = f;Entity entity = _entityManager.CreateEntity(archetype);_entityManager.AddSharedComponentData(entity, new RenderMesh{mesh = unitMesh,material = unitMaterial,layerMask = 1,});_entityManager.AddComponentData(entity, new Translation(){Value = pos});_entityManager.AddComponentData(entity, new HeightComponent(){InitiateHeight = f,MaxHeight = maxHeight,});_entityManager.AddComponentData(entity, new SpeedComponent(){Speed = speed});} }

    總結

    以上是生活随笔為你收集整理的Unity DOTS ECS 0.50版本,海浪Demo的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。