您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
61 行
2.1 KiB
61 行
2.1 KiB
using System;
|
|
using Unity.Simulation;
|
|
|
|
namespace UnityEngine.Perception.Randomization.Scenarios
|
|
{
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
/// <typeparam name="T">The type of scenario constants to serialize</typeparam>
|
|
public abstract class UnitySimulationScenario<T> : PerceptionScenario<T>
|
|
where T : UnitySimulationScenarioConstants, new()
|
|
{
|
|
/// <inheritdoc/>
|
|
protected override bool isScenarioReadyToStart
|
|
{
|
|
get
|
|
{
|
|
if (!Configuration.Instance.IsSimulationRunningInCloud() && !m_SkippedFirstFrame)
|
|
{
|
|
m_SkippedFirstFrame = true;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected sealed override bool isScenarioComplete => currentIteration >= constants.totalIterations;
|
|
|
|
/// <inheritdoc/>
|
|
protected override void LoadConfigurationAsset()
|
|
{
|
|
if (Configuration.Instance.IsSimulationRunningInCloud())
|
|
{
|
|
var filePath = new Uri(Configuration.Instance.SimulationConfig.app_param_uri).LocalPath;
|
|
LoadConfigurationFromFile(filePath);
|
|
}
|
|
else
|
|
{
|
|
base.LoadConfigurationAsset();
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override void DeserializeConfiguration()
|
|
{
|
|
base.DeserializeConfiguration();
|
|
if (Configuration.Instance.IsSimulationRunningInCloud())
|
|
constants.instanceIndex = int.Parse(Configuration.Instance.GetInstanceId()) - 1;
|
|
currentIteration = constants.instanceIndex;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected sealed override void IncrementIteration()
|
|
{
|
|
currentIteration += constants.instanceCount;
|
|
}
|
|
}
|
|
}
|