コード例 #1
0
        /// <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;
            }
        }
コード例 #2
0
        /// <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, "Demonstrations");
            }

            demonstrationName = SanitizeName(demonstrationName, MaxNameLength);
            var filePath = MakeDemonstrationFilePath(m_FileSystem, demonstrationDirectory, demonstrationName);
            var stream   = m_FileSystem.File.Create(filePath);

            m_DemoWriter = new DemonstrationWriter(stream);

            m_DemoWriter.Initialize(
                demonstrationName,
                behaviorParams.brainParameters,
                behaviorParams.fullyQualifiedBehaviorName
                );

            AddDemonstrationWriterToAgent(m_DemoWriter);

            return(m_DemoWriter);
        }
コード例 #3
0
 /// <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);
 }
コード例 #4
0
 /// <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)
 {
     m_Agent.DemonstrationWriters.Add(demoWriter);
 }