Created
July 23, 2018 06:53
-
-
Save ernesernesto/9a1d5e6f3bb3ab4d9df3e2b2f44fac54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BootupJob : MonoBehaviour | |
{ | |
public GameObject cubePrefab; | |
public Settings settings; | |
public float[] spectrumBuff; | |
public Transform[] transforms; | |
public NativeArray<float> currentSpectrums; | |
public NativeArray<float> prevSpectrums; | |
public NativeArray<Vector3> origins; | |
public TransformAccessArray transformsAccess; | |
SpectrumJob spectrumJob; | |
JobHandle jobHandle; | |
void Start() | |
{ | |
...// Omitted | |
result.transformsAccess = new TransformAccessArray(result.transforms); | |
} | |
void Update() | |
{ | |
float dynamics = settings.dynamics; | |
float maxScale = settings.maxScale; | |
float rotationSpeed = settings.rotationSpeed; | |
float epsilon = settings.epsilon; | |
gameObject.transform.Rotate(Vector3.up*(rotationSpeed*Time.deltaTime)); | |
AudioListener.GetSpectrumData(spectrumBuff, 0, FFTWindow.BlackmanHarris); | |
currentSpectrums.CopyFrom(spectrumBuff); | |
spectrumJob = new SpectrumJob() | |
{ | |
maxScale = inMaxScale, | |
dynamics = inDynamics, | |
epsilon = inEpsilon, | |
currentSpectrums = this.currentSpectrums, | |
prevSpectrums = this.prevSpectrums, | |
origins = this.origins, | |
}; | |
jobHandle = spectrumJob.Schedule(transformsAccess); | |
} | |
void LateUpdate() | |
{ | |
jobHandle.Complete(); | |
spectrumJob.prevSpectrums.CopyTo(prevSpectrums); | |
} | |
void OnDestroy() | |
{ | |
currentSpectrums.Dispose(); | |
prevSpectrums.Dispose(); | |
origins.Dispose(); | |
transformsAccess.Dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment