Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using UnityEngine.Jobs;
using Unity.Jobs;
using Unity.Mathematics;
public class TransformAccessSample : MonoBehaviour
{
[SerializeField] private Transform parent;
private TransformAccessArray transforms;
private JobHandle handle;
void OnEnable()
{
transforms = new TransformAccessArray(parent.GetComponentsInChildren<Transform>(), 6);
transforms.RemoveAtSwapBack(0);
parent.DetachChildren();
}
void OnDisable()
{
transforms.Dispose();
}
void Update()
{
handle.Complete();
handle = new RotateJob(Time.timeSinceLevelLoad).Schedule(transforms, handle);
JobHandle.ScheduleBatchedJobs();
}
//[Unity.Burst.BurstCompile]
struct RotateJob : IJobParallelForTransform
{
private float offset;
const float height = 1;
const float per = 128;
const float size = 0.05f;
public RotateJob(float offset)
{
this.offset = offset;
}
public void Execute(int index, TransformAccess transform)
{
Vector3 pos = transform.localPosition;
float x = pos.x * 0.2f + offset;
float z = pos.z * 0.2f + offset;
float2 noisePos = new float2(x, z);
pos.y = noise.psrnoise(noisePos, new float2(per, per)) * height;
transform.localPosition = pos;
}
}
}
@tsubaki

This comment has been minimized.

Copy link
Owner Author

tsubaki commented Nov 14, 2018

143
22 42 09

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.