using System;
using Unity.Simulation;
namespace UnityEngine.Perception.Randomization.Scenarios
{
///
/// A scenario must derive from this class to be compatible with the Run in
/// Unity Simulation window. The iterations of this scenario will be executed in parallel across a user specified
/// number of worker instances when run in Unity Simulation.
///
/// The type of scenario constants to serialize
public abstract class UnitySimulationScenario : PerceptionScenario
where T : UnitySimulationScenarioConstants, new()
{
///
protected override bool isScenarioReadyToStart
{
get
{
if (!Configuration.Instance.IsSimulationRunningInCloud() && !m_SkippedFirstFrame)
{
m_SkippedFirstFrame = true;
return false;
}
return true;
}
}
///
protected sealed override bool isScenarioComplete => currentIteration >= constants.totalIterations;
///
protected override void OnConfigurationImport()
{
if (Configuration.Instance.IsSimulationRunningInCloud())
{
DeserializeFromFile(new Uri(Configuration.Instance.SimulationConfig.app_param_uri).LocalPath);
constants.instanceIndex = int.Parse(Configuration.Instance.GetInstanceId()) - 1;
}
else
base.OnConfigurationImport();
currentIteration = constants.instanceIndex;
}
///
protected sealed override void IncrementIteration()
{
currentIteration += constants.instanceCount;
}
}
}