using System;
using Unity.Simulation;
namespace UnityEngine.Experimental.Perception.Randomization.Scenarios
{
///
/// Defines a scenario that is compatible with the Run in USim window
///
/// The type of constants to serialize
public abstract class USimScenario : Scenario where T : USimConstants, 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 USim 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 USim cloud execution
///
[Serializable]
public class USimConstants
{
///
/// The total number of iterations to run a scenario for
///
public int totalIterations = 100;
///
/// The number of USim instances assigned to executed this scenario
///
public int instanceCount = 1;
///
/// The USim instance index of the currently executing worker
///
public int instanceIndex;
}
}