Class ScenarioBase
Derive ScenarioBase to implement a custom scenario
Namespace: UnityEngine.Perception.Randomization.Scenarios
Syntax
public abstract class ScenarioBase : MonoBehaviour
Fields
configuration
An external text asset that is loaded when the scenario starts to configure scenario settings
Declaration
public TextAsset configuration
Field Value
Type | Description |
---|---|
TextAsset |
Properties
activeRandomizers
Enumerates over all enabled randomizers
Declaration
public IEnumerable<Randomizer> activeRandomizers { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Randomizer> |
activeScenario
Returns the active parameter scenario in the scene
Declaration
public static ScenarioBase activeScenario { get; }
Property Value
Type | Description |
---|---|
ScenarioBase |
currentIteration
The current iteration index of the scenario
Declaration
public int currentIteration { get; protected set; }
Property Value
Type | Description |
---|---|
Int32 |
currentIterationFrame
The number of frames that have elapsed since the current scenario iteration was Setup
Declaration
public int currentIterationFrame { get; }
Property Value
Type | Description |
---|---|
Int32 |
framesSinceInitialization
The number of frames that have elapsed since the scenario was initialized
Declaration
public int framesSinceInitialization { get; }
Property Value
Type | Description |
---|---|
Int32 |
genericConstants
Returns this scenario's non-typed serialized constants
Declaration
public abstract ScenarioConstants genericConstants { get; }
Property Value
Type | Description |
---|---|
ScenarioConstants |
isIterationComplete
Returns whether the current scenario iteration has completed
Declaration
protected abstract bool isIterationComplete { get; }
Property Value
Type | Description |
---|---|
Boolean |
isScenarioComplete
Returns whether the scenario has completed
Declaration
protected abstract bool isScenarioComplete { get; }
Property Value
Type | Description |
---|---|
Boolean |
isScenarioReadyToStart
The scenario will begin on the frame this property first returns true
Declaration
protected abstract bool isScenarioReadyToStart { get; }
Property Value
Type | Description |
---|---|
Boolean | Whether the scenario should start this frame |
randomizers
Return the list of randomizers attached to this scenario
Declaration
public IReadOnlyList<Randomizer> randomizers { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<Randomizer> |
state
The current activity state of the scenario
Declaration
public ScenarioBase.State state { get; }
Property Value
Type | Description |
---|---|
ScenarioBase.State |
Methods
AddRandomizer(Randomizer)
Append a randomizer to the end of the randomizer list
Declaration
public void AddRandomizer(Randomizer newRandomizer)
Parameters
Type | Name | Description |
---|---|---|
Randomizer | newRandomizer | The Randomizer to add to the Scenario |
DelayIteration()
Delays the current iteration by one frame. This results in OnIterationStart() being called again for the same iteration.
Declaration
public void DelayIteration()
Remarks
Must be called from within the OnIterationStart() function of a class inheriting from Randomizer.
DeserializeConfiguration()
Overwrites this scenario's randomizer settings and scenario constants from a JSON serialized configuration
Declaration
protected virtual void DeserializeConfiguration()
GetRandomizer(Int32)
Returns the randomizer present at the given index
Declaration
public Randomizer GetRandomizer(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The lookup index |
Returns
Type | Description |
---|---|
Randomizer | The randomizer present at the given index |
GetRandomizer<T>()
Finds and returns a randomizer attached to this scenario of the specified Randomizer type
Declaration
public T GetRandomizer<T>()
where T : Randomizer
Returns
Type | Description |
---|---|
T | A randomizer of the specified type |
Type Parameters
Name | Description |
---|---|
T | The type of randomizer to find |
Exceptions
Type | Condition |
---|---|
UnityEngine.Perception.Randomization.Scenarios.ScenarioException |
IncrementIteration()
This method selects what the next iteration index will be. By default, the scenario will simply progress to the next iteration, but this behaviour can be overriden.
Declaration
protected virtual void IncrementIteration()
InsertRandomizer(Int32, Randomizer)
Insert a randomizer at a given index within the randomizer list
Declaration
public void InsertRandomizer(int index, Randomizer newRandomizer)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index to place the randomizer |
Randomizer | newRandomizer | The randomizer to add to the list |
Exceptions
Type | Condition |
---|---|
UnityEngine.Perception.Randomization.Scenarios.ScenarioException |
LoadConfigurationAsset()
Loads and stores a JSON scenario settings configuration file before the scenario starts
Declaration
protected virtual void LoadConfigurationAsset()
LoadConfigurationFromCommandLine(String)
Deserialize scenario settings from a file passed through a command line argument
Declaration
protected void LoadConfigurationFromCommandLine(string commandLineArg = "--scenario-config-file")
Parameters
Type | Name | Description |
---|---|---|
String | commandLineArg | The command line argument to look for |
LoadConfigurationFromFile(String)
Loads a scenario configuration from a file located at the given file path
Declaration
public void LoadConfigurationFromFile(string filePath)
Parameters
Type | Name | Description |
---|---|---|
String | filePath | The file path of the scenario configuration file |
OnAwake()
OnAwake is called when this scenario MonoBehaviour is created or instantiated
Declaration
protected virtual void OnAwake()
OnComplete()
OnComplete is called when this scenario's isScenarioComplete property returns true during its main update loop
Declaration
protected virtual void OnComplete()
OnDisable()
OnEnable is called when this scenario is disabled
Declaration
protected virtual void OnDisable()
OnEnable()
OnEnable is called when this scenario is enabled
Declaration
protected virtual void OnEnable()
OnIdle()
OnIdle is called each frame after the scenario has completed
Declaration
protected virtual void OnIdle()
OnIterationEnd()
OnIterationStart is called after each iteration has completed
Declaration
protected virtual void OnIterationEnd()
OnIterationStart()
OnIterationStart is called before a new iteration begins
Declaration
protected virtual void OnIterationStart()
OnStart()
OnStart is called when the scenario first begins playing
Declaration
protected virtual void OnStart()
OnUpdate()
OnUpdate is called every frame while the scenario is playing
Declaration
protected virtual void OnUpdate()
Quit()
Exit to playmode if in the Editor or quit the application if in a built player
Declaration
protected void Quit()
RemoveRandomizerAt(Int32)
Remove the randomizer present at the given index
Declaration
public void RemoveRandomizerAt(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index of the randomizer to remove |
ResetRandomStateOnIteration()
Resets SamplerState.randomState with a new seed value generated by hashing this Scenario's randomSeed with its currentIteration
Declaration
protected virtual void ResetRandomStateOnIteration()
Restart()
Restart the scenario
Declaration
public void Restart()
RestartIteration()
Declaration
public void RestartIteration()
SerializeToFile(String)
Serializes the scenario's constants and randomizer settings to a JSON file located at the path resolved by the defaultConfigFilePath scenario property
Declaration
public virtual void SerializeToFile(string filePath)
Parameters
Type | Name | Description |
---|---|---|
String | filePath | The file path to serialize the scenario to |
SerializeToJson()
Serializes the scenario's constants and randomizer settings to a JSON string
Declaration
public virtual string SerializeToJson()
Returns
Type | Description |
---|---|
String | The scenario configuration as a JSON string |