/// <summary> /// Creates demonstration store for use in recording. /// Has no effect if the demonstration store was already created. /// </summary> internal DemonstrationWriter LazyInitialize(IFileSystem fileSystem = null) { if (m_DemoWriter != null) { return(m_DemoWriter); } if (m_Agent == null) { m_Agent = GetComponent <Agent>(); } m_FileSystem = fileSystem ?? new FileSystem(); var behaviorParams = GetComponent <BehaviorParameters>(); if (string.IsNullOrEmpty(DemonstrationName)) { DemonstrationName = behaviorParams.BehaviorName; } if (string.IsNullOrEmpty(DemonstrationDirectory)) { DemonstrationDirectory = Path.Combine(Application.dataPath, k_DefaultDirectoryName); } DemonstrationName = SanitizeName(DemonstrationName, MaxNameLength); var filePath = MakeDemonstrationFilePath(m_FileSystem, DemonstrationDirectory, DemonstrationName); var stream = m_FileSystem.File.Create(filePath); m_DemoWriter = new DemonstrationWriter(stream); AddDemonstrationWriterToAgent(m_DemoWriter); return(m_DemoWriter); }
/// <summary> /// Close the DemonstrationWriter and remove it from the Agent. /// Has no effect if the DemonstrationWriter is already closed (or wasn't opened) /// </summary> public void Close() { if (m_DemoWriter != null) { RemoveDemonstrationWriterFromAgent(m_DemoWriter); m_DemoWriter.Close(); m_DemoWriter = null; } }
/// <summary> /// Add additional DemonstrationWriter to the Agent. It is still up to the user to Close this /// DemonstrationWriters when recording is done. /// </summary> /// <param name="demoWriter"></param> public void AddDemonstrationWriterToAgent(DemonstrationWriter demoWriter) { var behaviorParams = GetComponent <BehaviorParameters>(); demoWriter.Initialize( DemonstrationName, behaviorParams.BrainParameters, behaviorParams.FullyQualifiedBehaviorName ); m_Agent.DemonstrationWriters.Add(demoWriter); }
/// <summary> /// Remove additional DemonstrationWriter to the Agent. It is still up to the user to Close this /// DemonstrationWriters when recording is done. /// </summary> /// <param name="demoWriter"></param> public void RemoveDemonstrationWriterFromAgent(DemonstrationWriter demoWriter) { m_Agent.DemonstrationWriters.Remove(demoWriter); }