/// <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);
        }
Esempio n. 2
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;
            }
        }
        /// <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);
        }
Esempio n. 4
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);
 }
Esempio n. 5
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);
 }