using System; using Unity.Collections; using Unity.Jobs; using UnityEngine.Perception.Randomization.Samplers; namespace UnityEngine.Perception.Randomization.Parameters { /// /// Numeric parameters use samplers to generate randomized structs /// /// The sample type of the parameter [Serializable] public abstract class NumericParameter : Parameter where T : struct { /// /// The sample type of parameter /// public sealed override Type sampleType => typeof(T); /// /// Generates one parameter sample /// /// The generated sample public abstract T Sample(); /// /// Schedules a job to generate an array of parameter samples. /// Call Complete() on the JobHandle returned by this function to wait on the job generating the parameter samples. /// /// Number of parameter samples to generate /// The JobHandle returned from scheduling the sampling job /// A NativeArray containing generated samples public abstract NativeArray Samples(int sampleCount, out JobHandle jobHandle); internal sealed override void ApplyToTarget(int seedOffset) { if (!hasTarget) return; target.ApplyValueToTarget(Sample()); } internal override void Validate() { base.Validate(); foreach (var sampler in samplers) if (sampler is IRandomRangedSampler rangedSampler) rangedSampler.range.Validate(); } } }