11using System ;
22using System . Collections ;
33using System . IO ;
4+ using JetBrains . Annotations ;
45using Unity . FilmInternalUtilities ;
56using UnityEngine ;
67
@@ -38,13 +39,17 @@ public abstract class BaseRenderCapturer : MonoBehaviour {
3839 public Texture GetInternalTexture ( ) { return m_rt ; }
3940
4041 /// <summary>
41- /// Capture the contents of RenderTexture into file
42+ /// Capture the contents of RenderTexture to file
4243 /// </summary>
4344 /// <param name="outputFilePath">The path of the file</param>
4445 /// <param name="outputFormat">The output file format</param>
45- public void CaptureToFile ( string outputFilePath , RenderCacheOutputFormat outputFormat = RenderCacheOutputFormat . PNG )
46+ /// <returns>True if successful, false otherwise</returns>
47+ public bool TryCaptureToFile ( string outputFilePath , RenderCacheOutputFormat outputFormat = RenderCacheOutputFormat . PNG )
4648 {
4749 RenderTexture rt = UpdateRenderTextureV ( ) ;
50+ if ( null == rt )
51+ return false ;
52+
4853 TextureFormat textureFormat = TextureFormat . RGBA32 ;
4954 bool isPNG = true ;
5055 if ( RenderCacheOutputFormat . EXR == outputFormat ) {
@@ -56,14 +61,29 @@ public void CaptureToFile(string outputFilePath, RenderCacheOutputFormat outputF
5661 if ( ! writeSuccess ) {
5762 Debug . LogError ( $ "[SIS] Can't write to file: { outputFilePath } ." + Environment . NewLine ) ;
5863 }
64+
65+ return true ;
5966 }
6067
68+ /// <summary>
69+ /// Capture the contents of RenderTexture to file
70+ /// </summary>
71+ /// <param name="outputFilePath">The path of the file</param>
72+ /// <param name="outputFormat">The output file format</param>
73+ [ Obsolete ( "Replaced by TryCaptureToFile()" ) ]
74+ public void CaptureToFile ( string outputFilePath , RenderCacheOutputFormat outputFormat = RenderCacheOutputFormat . PNG )
75+ {
76+ //[TODO-sin: 2022-9-26] Remove CaptureToFile() function in 0.17.x-preview
77+ TryCaptureToFile ( outputFilePath , outputFormat ) ;
78+ }
79+
6180//----------------------------------------------------------------------------------------------------------------------
6281
6382 /// <summary>
6483 /// Updates the render texture used for the capturing process
6584 /// </summary>
66- /// <returns>The updated render texture</returns>
85+ /// <returns>The updated render texture if successful, null otherwise</returns>
86+ [ CanBeNull ]
6787 protected abstract RenderTexture UpdateRenderTextureV ( ) ;
6888
6989
0 commit comments