using System; using UnityEngine.Perception.GroundTruth; namespace UnityEngine.Perception.Randomization.Scenarios { /// /// A scenario that runs for a fixed number of frames during each iteration /// [AddComponentMenu("Perception/Scenarios/Fixed Length Scenario")] public class FixedLengthScenario: UnitySimulationScenario { PerceptionCamera m_PerceptionCamera; /// /// Constants describing the execution of this scenario /// [Serializable] public class Constants : UnitySimulationScenarioConstants { /// /// The number of frames to render per iteration. /// [Tooltip("The number of frames to render per iteration.")] public int framesPerIteration = 1; } /// /// Returns whether the current scenario iteration has completed /// protected override bool isIterationComplete => currentIterationFrame >= constants.framesPerIteration; /// protected override void OnAwake() { base.OnAwake(); m_PerceptionCamera = FindObjectOfType(); if (m_PerceptionCamera != null && m_PerceptionCamera.captureTriggerMode != CaptureTriggerMode.Manual) { Debug.LogError("The perception camera must be set to manual capture mode", m_PerceptionCamera); m_PerceptionCamera.enabled = false; enabled = false; } } /// protected override void OnIterationStart() { if (m_PerceptionCamera != null && currentIterationFrame == constants.framesPerIteration - 1) m_PerceptionCamera.RequestCapture(); } } }