using System;
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;
///
/// OnAwake is executed directly after this scenario has been registered and initialized
///
protected sealed override void OnAwake()
{
currentIteration = constants.instanceIndex;
}
///
/// 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 (string.IsNullOrEmpty(Unity.Simulation.Configuration.Instance.SimulationConfig.app_param_uri))
base.Deserialize();
else
constants = Unity.Simulation.Configuration.Instance.GetAppParams();
}
}
///
/// 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;
}
}