using System;
using Unity.Simulation;
namespace UnityEngine.Experimental.Perception.Randomization.Scenarios
{
///
/// Defines a scenario that is compatible with the Run in Unity Simulation window
///
/// The type of constants to serialize
public abstract class UnitySimulationScenario : Scenario where T : UnitySimulationConstants, new()
{
///
/// Returns whether the entire scenario has completed
///
public sealed override bool isScenarioComplete => currentIteration >= constants.totalIterations;
///
/// Progresses the current scenario iteration
///
protected sealed override void IncrementIteration()
{
currentIteration += constants.instanceCount;
}
///
/// Deserializes this scenario's constants from the Unity Simulation AppParams Json file
///
public sealed override void Deserialize()
{
if (Configuration.Instance.IsSimulationRunningInCloud())
constants = Configuration.Instance.GetAppParams();
else
base.Deserialize();
currentIteration = constants.instanceIndex;
}
}
///
/// A class encapsulating the scenario constants fields required for Unity Simulation cloud execution
///
[Serializable]
public class UnitySimulationConstants
{
///
/// The total number of iterations to run a scenario for
///
public int totalIterations = 100;
///
/// The number of Unity Simulation instances assigned to executed this scenario
///
public int instanceCount = 1;
///
/// The Unity Simulation instance index of the currently executing worker
///
public int instanceIndex;
}
}