您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
97 行
2.9 KiB
97 行
2.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Experimental.Perception.Randomization.Samplers;
|
|
|
|
namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|
{
|
|
/// <summary>
|
|
/// Parameters, in conjunction with a parameter configuration, are used to create convenient interfaces for
|
|
/// randomizing simulations.
|
|
/// </summary>
|
|
[Serializable]
|
|
public abstract class Parameter
|
|
{
|
|
[HideInInspector, SerializeField] internal bool collapsed;
|
|
|
|
/// <summary>
|
|
/// The sample type generated by this parameter
|
|
/// </summary>
|
|
public abstract Type sampleType { get; }
|
|
|
|
/// <summary>
|
|
/// Returns an IEnumerable that iterates over each sampler field in this parameter
|
|
/// </summary>
|
|
internal abstract IEnumerable<ISampler> samplers { get; }
|
|
|
|
/// <summary>
|
|
/// Constructs a new parameter
|
|
/// </summary>
|
|
protected Parameter()
|
|
{
|
|
InitializeSamplers();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the display name of a parameter type
|
|
/// </summary>
|
|
/// <param name="type">A subclass of Parameter</param>
|
|
/// <returns>The parameter type's display name</returns>
|
|
public static string GetDisplayName(Type type)
|
|
{
|
|
return type.Name.Replace("Parameter", "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deterministically ensures that no sampler shares the same seed when a parameter is initialized
|
|
/// </summary>
|
|
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();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resets the state of each sampler employed by this parameter
|
|
/// </summary>
|
|
public void ResetState()
|
|
{
|
|
foreach (var sampler in samplers)
|
|
sampler.ResetState();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Offsets the state of each sampler employed by this parameter
|
|
/// </summary>
|
|
/// <param name="offsetIndex">Often the current scenario iteration</param>
|
|
public void IterateState(int offsetIndex)
|
|
{
|
|
foreach (var sampler in samplers)
|
|
sampler.IterateState(offsetIndex);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generates a generic sample
|
|
/// </summary>
|
|
/// <returns>The generated sample</returns>
|
|
public abstract object GenericSample();
|
|
|
|
/// <summary>
|
|
/// Validates parameter settings
|
|
/// </summary>
|
|
public virtual void Validate() { }
|
|
}
|
|
}
|