using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Perception.Randomization.Samplers;
namespace UnityEngine.Experimental.Perception.Randomization.Parameters
{
///
/// Parameters, in conjunction with a parameter configuration, are used to create convenient interfaces for
/// randomizing simulations.
///
[Serializable]
public abstract class Parameter
{
[HideInInspector, SerializeField] internal bool collapsed;
///
/// The sample type generated by this parameter
///
public abstract Type sampleType { get; }
///
/// Returns an IEnumerable that iterates over each sampler field in this parameter
///
public abstract IEnumerable samplers { get; }
///
/// Constructs a new parameter
///
protected Parameter()
{
InitializeSamplers();
}
///
/// Returns the display name of a parameter type
///
/// A subclass of Parameter
/// The parameter type's display name
public static string GetDisplayName(Type type)
{
return type.Name.Replace("Parameter", "");
}
///
/// Deterministically ensures that no sampler shares the same seed when a parameter is initialized
///
void InitializeSamplers()
{
var i = 0;
foreach (var sampler in samplers)
{
sampler.IterateState(i++);
sampler.ResetState();
}
}
internal void RandomizeSamplers()
{
foreach (var sampler in samplers)
{
sampler.baseSeed = SamplerUtility.GenerateRandomSeed();
sampler.ResetState();
}
}
///
/// Resets the state of each sampler employed by this parameter
///
public void ResetState()
{
foreach (var sampler in samplers)
sampler.ResetState();
}
///
/// Offsets the state of each sampler employed by this parameter
///
/// Often the current scenario iteration
public void IterateState(int offsetIndex)
{
foreach (var sampler in samplers)
sampler.IterateState(offsetIndex);
}
///
/// Generates a generic sample
///
/// The generated sample
public abstract object GenericSample();
///
/// Validates parameter settings
///
public virtual void Validate() { }
}
}