Guest User

Untitled

a guest
Jul 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. [System.Serializable]
  2. public struct Scale : IComponentData
  3. {
  4. public float3 Value;
  5. }
  6.  
  7. [UnityEngine.ExecuteInEditMode]
  8. public class CustomTransformSystem : JobComponentSystem
  9. {
  10. struct CustomTransformGroup
  11. {
  12. public int Length;
  13.  
  14. [ReadOnly]
  15. public ComponentDataArray<Position> Positions;
  16.  
  17. [ReadOnly]
  18. public ComponentDataArray<LocalRotation> Rotations;
  19.  
  20. [ReadOnly]
  21. public ComponentDataArray<Scale> Scales;
  22.  
  23. public ComponentDataArray<TransformMatrix> Transforms;
  24. }
  25.  
  26. [Inject]
  27. CustomTransformGroup transformGroup;
  28.  
  29. [ComputeJobOptimization]
  30. struct CustomTransformGroupJob : IJobParallelFor
  31. {
  32. [ReadOnly]
  33. public ComponentDataArray<Position> Positions;
  34.  
  35. [ReadOnly]
  36. public ComponentDataArray<LocalRotation> Rotations;
  37.  
  38. [ReadOnly]
  39. public ComponentDataArray<Scale> Scales;
  40.  
  41. public ComponentDataArray<TransformMatrix> Transforms;
  42.  
  43. public void Execute(int i)
  44. {
  45. Transforms[i] = new TransformMatrix
  46. {
  47. Value = math.mul(math.rottrans(Quaternion.Euler(Rotations[i].Value.value.xyz), Positions[i].Value), math.scale(Scales[i].Value))
  48. };
  49. }
  50. }
  51.  
  52. protected override JobHandle OnUpdate(JobHandle inputDeps)
  53. {
  54. var transformJob = new CustomTransformGroupJob
  55. {
  56. Transforms = transformGroup.Transforms,
  57. Positions = transformGroup.Positions,
  58. Rotations = transformGroup.Rotations,
  59. Scales = transformGroup.Scales,
  60. };
  61.  
  62. return transformJob.Schedule(transformGroup.Length, 64, inputDeps);
  63. }
  64. }
Add Comment
Please, Sign In to add comment