[CustomEditor(typeof(ImageSequence))]
internal class ImageSequenceAssetEditor : Editor
{
ImageSequence sequence ;
private bool m_PreviewInput = false ;
private bool m_PreviewOutput = false ;
private bool m_RequireConstantRepaint = false ;
return m_RequireConstantRepaint ;
}
private void OnEnable ( )
{
sequence = serializedObject . targetObject as ImageSequence ;
InitializePreview ( ) ;
}
protected override void OnHeaderGUI ( )
m_PreviewInput = GUILayout . Toggle ( m_PreviewInput , VFXToolboxGUIUtility . Get ( "Preview" ) , EditorStyles . miniButton ) ;
}
if ( inputFrameCount > 0 & & m_PreviewInput )
if ( inputFrameCount > 0 & & m_PreviewInput )
if ( inputFrameCount > 1 )
if ( inputFrameCount > 1 )
index = ( int ) Mathf . Floor ( ( time * 3 0 ) % inputFrameCount ) ;
index = ( int ) Mathf . Floor ( ( time * 3 0 ) % inputFrameCount ) ;
}
else
{
}
}
GUILayout . Space ( 2 4 ) ;
VFXToolboxGUIUtility . ToggleableHeader ( true , false , "Processors" ) ;
{
EditorGUI . indentLevel + + ;
for ( int i = 0 ; i < processorsCount ; i + + )
for ( int i = 0 ; i < processorsCount ; i + + )
EditorGUILayout . LabelField ( "#" + i + " - " + item . Settings . label + ( item . Enabled ? "" : " (Disabled)" ) ) ;
EditorGUILayout . LabelField ( "#" + i + " - " + item . Settings . label + ( item . Enabled ? "" : " (Disabled)" ) ) ;
GUILayout . Space ( 2 4 ) ;
VFXToolboxGUIUtility . ToggleableHeader ( true , false , "Export Settings" ) ;
EditorGUI . BeginDisabledGroup ( true ) ;
EditorGUILayout . EnumPopup ( VFXToolboxGUIUtility . Get ( "Export Format" ) , mode ) ;
EditorGUI . EndDisabledGroup ( ) ;
EditorGUILayout . TextField ( "Exporting to " , fileName ) ;
EditorGUILayout . TextField ( "Export Path" , fileName ) ;
Rect r = GUILayoutUtility . GetLastRect ( ) ;
r . width + = EditorGUIUtility . fieldWidth ;
if ( Event . current . rawType = = EventType . MouseDown & & r . Contains ( Event . current . mousePosition ) )
{
ImageSequencer . PingOutputTexture ( fileName ) ;
}
string dir = System . IO . Path . GetDirectoryName ( fileName ) ;
string file = System . IO . Path . GetFileNameWithoutExtension ( fileName ) ;
string [ ] assets ;
if ( ! fileName . StartsWith ( "Assets/" ) )
{
EditorGUILayout . HelpBox ( "The output sequence has been exported outside the project, preview will be unavailable" , MessageType . Warning ) ;
return ;
}
if ( fileName . Contains ( "#" ) )
{
if ( System . IO . Directory . Exists ( dir ) )
{
string [ ] guids = AssetDatabase . FindAssets ( file . Replace ( '#' , '*' ) , new string [ ] { dir } ) ;
assets = new string [ guids . Length ] ;
for ( int i = 0 ; i < guids . Length ; i + + )
{
assets [ i ] = AssetDatabase . GUIDToAssetPath ( guids [ i ] ) ;
}
}
else
assets = new string [ ] { } ;
}
else
{
assets = new string [ ] { fileName } ;
}
int outputFrameCount ;
if ( frameCount . intValue = = assets . Length )
outputFrameCount = frameCount . intValue ;
else
outputFrameCount = 0 ; // Something went wrong
if ( outputFrameCount > 0 )
{
if ( outputFrameCount > 1 )
{
using ( new EditorGUILayout . HorizontalScope ( ) )
{
GUILayout . Label ( "Output sequence contains " + assets . Length + " frame(s)." ) ;
GUILayout . FlexibleSpace ( ) ;
m_PreviewOutput = GUILayout . Toggle ( m_PreviewOutput , VFXToolboxGUIUtility . Get ( "Preview" ) , EditorStyles . miniButton ) ;
}
if ( m_PreviewOutput )
{
m_RequireConstantRepaint = true ;
float time = ( float ) EditorApplication . timeSinceStartup ;
int index = ( int ) Mathf . Floor ( ( time * 3 0 ) % outputFrameCount ) ;
var texture = AssetDatabase . LoadAssetAtPath < Texture2D > ( assets [ index ] ) ;
DrawAnimatedPreviewLayout ( texture , ( ( float ) index / outputFrameCount ) ) ;
}
else
{
m_PreviewOutput = false ;
}
}
else // Only one frame
{
var texture = AssetDatabase . LoadAssetAtPath < Texture2D > ( assets [ 0 ] ) ;
if ( texture ! = null )
DrawAnimatedPreviewLayout ( texture , 0.0f ) ;
else
EditorGUILayout . HelpBox ( "Output Texture could not be loaded, maybe the file was deleted. Please export again using the editor" , MessageType . Error ) ;
}
}
else
{
EditorGUILayout . HelpBox ( "The output sequence does not match the number of files on disk, you probably need to export your sequence again" , MessageType . Warning ) ;
}
EditorGUILayout . HelpBox ( "This asset has not yet been exported. Please open editor and export it to generate a sequence." , MessageType . None ) ;
EditorGUILayout . HelpBox ( "This asset has not yet been exported. Please open editor and export it to generate a sequence." , MessageType . None ) ;
private void DrawAnimatedPreviewLayout ( Texture2D texture , float progress )
private void DrawAnimatedPreviewLayout ( Texture texture , float progress )
float width = EditorGUIUtility . currentViewWidth - 3 2 ;
float width = EditorGUIUtility . currentViewWidth - 3 2 ;
if ( ratio > = 1 )
if ( ratio > = 1 )
texture_rect = GUILayoutUtility . GetRect ( height / ratio , height ) ;
else
texture_rect = GUILayoutUtility . GetRect ( width , width * ratio ) ;
}
}
#region PREVIEW
public int previewFrame = 0 ;
Texture previewTexture ;
public Material arrayPreviewMaterial ;
static readonly int s_ShaderColorMask = Shader . PropertyToID ( "_ColorMask" ) ;
static readonly int s_ShaderSliceIndex = Shader . PropertyToID ( "_SliceIndex" ) ;
static readonly int s_ShaderMip = Shader . PropertyToID ( "_Mip" ) ;
static readonly int s_ShaderToSrgb = Shader . PropertyToID ( "_ToSRGB" ) ;
static readonly int s_ShaderIsNormalMap = Shader . PropertyToID ( "_IsNormalMap" ) ;
void InitializePreview ( )
{
if ( HasPreviewGUI ( ) )
previewTexture = AssetDatabase . LoadAssetAtPath < Texture > ( sequence . exportSettings . fileName ) ;
arrayPreviewMaterial = ( Material ) EditorGUIUtility . LoadRequired ( "Previews/Preview2DTextureArrayMaterial.mat" ) ;
arrayPreviewMaterial . SetInt ( s_ShaderColorMask , 1 5 ) ;
arrayPreviewMaterial . SetInt ( s_ShaderMip , 0 ) ;
arrayPreviewMaterial . SetInt ( s_ShaderToSrgb , QualitySettings . activeColorSpace = = ColorSpace . Linear ? 1 : 0 ) ;
arrayPreviewMaterial . SetInt ( s_ShaderIsNormalMap , 0 ) ;
}
public override void OnPreviewGUI ( Rect r , GUIStyle background )
{
if ( previewTexture = = null )
InitializePreview ( ) ;
base . OnPreviewGUI ( r , background ) ;
if ( previewTexture is Texture2D )
{
EditorGUI . DrawTextureTransparent ( r , previewTexture , ScaleMode . ScaleToFit , ( float ) previewTexture . width / previewTexture . height ) ;
}
else if ( previewTexture is Texture2DArray )
{
EditorGUI . DrawPreviewTexture ( r , previewTexture , arrayPreviewMaterial , ScaleMode . ScaleToFit , ( float ) previewTexture . width / previewTexture . height , 0 ) ;
}
}
public override void OnPreviewSettings ( )
{
if ( previewTexture = = null )
InitializePreview ( ) ;
if ( previewTexture is Texture2DArray )
{
Texture2DArray array = previewTexture as Texture2DArray ;
GUILayout . Label ( "Frame" ) ;
previewFrame = EditorGUILayout . IntSlider ( previewFrame , 0 , array . depth - 1 ) ;
arrayPreviewMaterial . SetInt ( s_ShaderSliceIndex , previewFrame ) ;
}
}
public override bool HasPreviewGUI ( )
{
if ( serializedObject . targetObjects . Length > 1 ) // No Multiple Preview
return false ;
ImageSequence . ExportSettings exportSettings = sequence . exportSettings ;
if ( exportSettings . fileName = = null // No Preview if not exported
| | ! exportSettings . fileName . StartsWith ( "Assets/" ) // No External Preview
| | exportSettings . fileName . Contains ( "#" ) ) // No Multiple Frame Preview
return false ;
return true ;
}
#endregion
}
}