Guest User

Untitled

a guest
May 24th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. //Unity2018.2.0b4 [EntityComponentSystem(ECS) ver0.0.12-preview1]
  2. using UnityEngine;
  3. using Unity.Entities;
  4. using Unity.Collections;
  5. using System.Linq;
  6. using System.Collections.Generic;
  7. using Unity.Jobs;
  8.  
  9. struct DATA1 : IComponentData
  10. {
  11. public int val;
  12. }
  13.  
  14. //JobComponentSystemを継承したクラスはComponentData同士の依存関係をうまく処理してくれるとのこと。
  15. class JOB_SYSTEM : JobComponentSystem {
  16.  
  17. //IJobProcessComponentDataを継承すると、
  18. //指定のComponentDataを簡単に並列化できる。
  19. [ComputeJobOptimization]
  20. struct JOB : IJobProcessComponentData<DATA1> {
  21. public void Execute(ref DATA1 data)
  22. {
  23. data.val += 10;
  24. }
  25. }
  26.  
  27.  
  28. //JobComponentSystem
  29. protected override JobHandle OnUpdate(JobHandle inputDeps)
  30. {
  31. //ジョブ同士の依存情報を持ったJobHandleが引数で入ってくるのでそれを第3引数に渡す。
  32. //第2引数は内部ループの分割数だそうです。
  33. var outputdeps = new JOB().Schedule(this, 16, inputDeps);
  34.  
  35. //戻り値で新しい依存情報が戻ってくるのでそれを返却する。
  36. return outputdeps;
  37. }
  38. }
  39.  
  40.  
  41. class ECS_SCRIPT : MonoBehaviour
  42. {
  43. EntityManager EM;
  44. private void Start()
  45. {
  46. EM = World.Active.GetOrCreateManager<EntityManager>();
  47. var archeType = EM.CreateArchetype(typeof(DATA1));
  48.  
  49. var instance = new NativeArray<Entity>(50000, Allocator.Temp);
  50. EM.CreateEntity(archeType, instance);
  51. instance.Dispose();
  52. }
  53.  
  54. }
Add Comment
Please, Sign In to add comment