protected bool DrawSidePanelHeader()
        {
            bool bHasChanged     = false;
            bool previousEnabled = Enabled;

            Enabled = VFXToolboxGUIUtility.ToggleableHeader(Enabled, false, GetName());

            if (previousEnabled != Enabled)
            {
                SerializedObject o = new SerializedObject(m_ProcessorInfo);
                o.FindProperty("Enabled").boolValue = Enabled;
                o.ApplyModifiedProperties();
                m_ProcessingNodeStack.Invalidate(this);
                bHasChanged = true;
            }
            return(bHasChanged);
        }
Esempio n. 2
0
        private void DrawExportPanelContent()
        {
            VFXToolboxGUIUtility.ToggleableHeader(true, false, "Export Frames");
            EditorGUI.indentLevel++;
            int length = m_processorStack.outputSequence.length;

            if (length > 0)
            {
                m_CurrentAssetSerializedObject.Update();
                EditorGUI.BeginChangeCheck();

                ImageSequence.ExportSettings prevState = m_CurrentAsset.exportSettings;

                ImageSequence.ExportMode prevMode = m_CurrentAsset.exportSettings.exportMode;

                m_CurrentAsset.exportSettings.exportMode   = (ImageSequence.ExportMode)EditorGUILayout.Popup(VFXToolboxGUIUtility.Get("Export Format"), (int)m_CurrentAsset.exportSettings.exportMode, GetExportModeFriendlyNames());
                m_CurrentAsset.exportSettings.dataContents = (ImageSequence.DataContents)EditorGUILayout.EnumPopup(VFXToolboxGUIUtility.Get("Import as|Sets the importer mode"), m_CurrentAsset.exportSettings.dataContents);



                if (m_CurrentAsset.exportSettings.dataContents == ImageSequence.DataContents.Sprite)
                {
                    FrameProcessor p = m_processorStack.processors[m_processorStack.processors.Count - 1];
                    if (((float)p.OutputWidth % p.NumU) != 0 || ((float)p.OutputHeight % p.NumV) != 0)
                    {
                        EditorGUILayout.HelpBox("Warning : texture size is not a multiplier of rows (" + p.NumU + ") and columns (" + p.NumV + ") count, this will lead to incorrect rendering of the sprite animation", MessageType.Warning);
                    }
                }


                if (prevMode != m_CurrentAsset.exportSettings.exportMode)
                {
                    m_CurrentAsset.exportSettings.fileName = "";
                }

                switch (m_CurrentAsset.exportSettings.exportMode)
                {
                case ImageSequence.ExportMode.EXR:
                    m_CurrentAsset.exportSettings.highDynamicRange = true;
                    m_CurrentAsset.exportSettings.sRGB             = false;
                    break;

                case ImageSequence.ExportMode.PNG:
                case ImageSequence.ExportMode.Targa:
                    m_CurrentAsset.exportSettings.highDynamicRange = false;
                    break;
                }

                switch (m_CurrentAsset.exportSettings.dataContents)
                {
                case ImageSequence.DataContents.NormalMapFromGrayscale:
                case ImageSequence.DataContents.NormalMap:
                    m_CurrentAsset.exportSettings.sRGB        = false;
                    m_CurrentAsset.exportSettings.exportAlpha = false;
                    break;

                default: break;
                }

                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.TextField(VFXToolboxGUIUtility.Get("File Name|File name or pattern of the export sequence, using # characters will add frame number to the file name, use multiple ### to ensure leading zeroes."), m_CurrentAsset.exportSettings.fileName);
                EditorGUI.EndDisabledGroup();
                Rect r = GUILayoutUtility.GetLastRect();
                r.width += EditorGUIUtility.fieldWidth;
                if (Event.current.rawType == EventType.mouseDown && r.Contains(Event.current.mousePosition))
                {
                    PingOutputTexture();
                }


                if (!m_CurrentAsset.exportSettings.highDynamicRange)
                {
                    m_CurrentAsset.exportSettings.sRGB = EditorGUILayout.Toggle(VFXToolboxGUIUtility.Get("sRGB (Color Data)|Whether the texture contains color (or not), HDR Data is always non sRGB."), m_CurrentAsset.exportSettings.sRGB);
                }

                EditorGUI.BeginDisabledGroup(m_CurrentAsset.exportSettings.compress && m_CurrentAsset.exportSettings.highDynamicRange);
                m_CurrentAsset.exportSettings.exportAlpha = EditorGUILayout.Toggle(VFXToolboxGUIUtility.Get("Export Alpha|Whether to export the alpha channel"), m_CurrentAsset.exportSettings.exportAlpha);
                EditorGUI.EndDisabledGroup();

                m_CurrentAsset.exportSettings.exportSeparateAlpha = EditorGUILayout.Toggle(VFXToolboxGUIUtility.Get("Separate Alpha|Export the alpha channel as a separate TGA Grayscale file with a \"_alpha\" suffix."), m_CurrentAsset.exportSettings.exportSeparateAlpha);

                m_CurrentAsset.exportSettings.compress        = EditorGUILayout.Toggle(VFXToolboxGUIUtility.Get("Compress|Whether to apply texture compression (HDR Compressed Data does not support alpha channel)"), m_CurrentAsset.exportSettings.compress);
                m_CurrentAsset.exportSettings.generateMipMaps = EditorGUILayout.Toggle(VFXToolboxGUIUtility.Get("Generate MipMaps|Whether generate mipmaps."), m_CurrentAsset.exportSettings.generateMipMaps);
                m_CurrentAsset.exportSettings.wrapMode        = (TextureWrapMode)EditorGUILayout.EnumPopup(VFXToolboxGUIUtility.Get("Wrap Mode|Texture Wrap mode"), m_CurrentAsset.exportSettings.wrapMode);
                m_CurrentAsset.exportSettings.filterMode      = (FilterMode)EditorGUILayout.EnumPopup(VFXToolboxGUIUtility.Get("Filter Mode|Texture Filter mode"), m_CurrentAsset.exportSettings.filterMode);

                if (m_CurrentAsset.exportSettings.compress && m_CurrentAsset.exportSettings.highDynamicRange)
                {
                    m_CurrentAsset.exportSettings.exportAlpha = false;
                }

                if (GUILayout.Button("Export as New...", GUILayout.Height(24)))
                {
                    string fileName = "";

                    fileName = ExportToFile(false);

                    if (fileName != "")
                    {
                        m_CurrentAsset.exportSettings.fileName   = fileName;
                        m_CurrentAsset.exportSettings.frameCount = (ushort)m_processorStack.outputSequence.frames.Count;
                    }
                }
                // Export Again
                if (m_CurrentAsset.exportSettings.fileName != null &&
                    ((m_CurrentAsset.exportSettings.fileName.EndsWith(".tga") && m_CurrentAsset.exportSettings.exportMode == ImageSequence.ExportMode.Targa) ||
                     (m_CurrentAsset.exportSettings.fileName.EndsWith(".exr") && m_CurrentAsset.exportSettings.exportMode == ImageSequence.ExportMode.EXR) ||
                     (m_CurrentAsset.exportSettings.fileName.EndsWith(".png") && m_CurrentAsset.exportSettings.exportMode == ImageSequence.ExportMode.PNG)
                    ))
                {
                    if (GUILayout.Button("Update Exported Assets", GUILayout.Height(24)))
                    {
                        UpdateExportedAssets();
                    }
                }

                if (m_CurrentAsset.exportSettings.dataContents == ImageSequence.DataContents.NormalMap)
                {
                    EditorGUILayout.HelpBox("The selected import mode assumes that the frame data is a normal map. To generate a normal map from grayscale, use Normal Map From Grayscale instead.", MessageType.Info);
                }

                if (EditorGUI.EndChangeCheck())
                {
                    ImageSequence.ExportSettings curState = m_CurrentAsset.exportSettings;
                    m_CurrentAsset.exportSettings = prevState;
                    Undo.RecordObject(m_CurrentAsset, "Update Export Settings");
                    m_CurrentAsset.exportSettings = curState;
                    m_CurrentAssetSerializedObject.ApplyModifiedProperties();
                    EditorUtility.SetDirty(m_CurrentAsset);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
            }
            else
            {
                EditorGUILayout.HelpBox("You do not have any frames to export.", MessageType.Warning);
            }
            EditorGUI.indentLevel--;
        }
Esempio n. 3
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            m_RequireConstantRepaint = false;

            using (new EditorGUILayout.VerticalScope())
            {
                if (GUILayout.Button(VFXToolboxGUIUtility.Get("Edit Sequence"), GUILayout.Height(40)))
                {
                    ImageSequencer toolbox = EditorWindow.GetWindow <ImageSequencer>();
                    toolbox.LoadAsset((ImageSequence)Selection.activeObject);
                }

                VFXToolboxGUIUtility.ToggleableHeader(true, false, "Input Frames");
                {
                    var inputFrames     = serializedObject.FindProperty("inputFrameGUIDs");
                    int inputFrameCount = inputFrames.arraySize;
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        GUILayout.Label("Input sequence contains " + inputFrameCount + " frame(s).");
                        GUILayout.FlexibleSpace();
                        m_PreviewInput = GUILayout.Toggle(m_PreviewInput, VFXToolboxGUIUtility.Get("Preview"), EditorStyles.miniButton);
                    }

                    if (inputFrameCount > 0 && m_PreviewInput)
                    {
                        int index;

                        if (inputFrameCount > 1)
                        {
                            m_RequireConstantRepaint = true;
                            float time = (float)EditorApplication.timeSinceStartup;
                            index = (int)Mathf.Floor((time * 30) % inputFrameCount);
                        }
                        else
                        {
                            index = 0;
                        }

                        var    frame   = inputFrames.GetArrayElementAtIndex(index);
                        string guid    = frame.stringValue;
                        var    texture = AssetDatabase.LoadAssetAtPath <Texture2D>(AssetDatabase.GUIDToAssetPath(guid));
                        DrawAnimatedPreviewLayout(texture, ((float)index / inputFrameCount));
                    }
                    else
                    {
                        m_PreviewInput = false;
                    }
                }

                GUILayout.Space(24);
                VFXToolboxGUIUtility.ToggleableHeader(true, false, "Processors");
                {
                    var processors      = serializedObject.FindProperty("processorInfos");
                    int processorsCount = processors.arraySize;
                    EditorGUILayout.LabelField("Asset contains " + processorsCount + " Processor (s).");
                    EditorGUI.indentLevel++;
                    for (int i = 0; i < processorsCount; i++)
                    {
                        var item = processors.GetArrayElementAtIndex(i).objectReferenceValue as ProcessorInfo;
                        EditorGUILayout.LabelField("#" + i + " - " + item.Settings.label + (item.Enabled ? "" : " (Disabled)"));
                    }
                    EditorGUI.indentLevel--;
                }


                GUILayout.Space(24);
                VFXToolboxGUIUtility.ToggleableHeader(true, false, "Export Settings");

                var exportSettings = serializedObject.FindProperty("exportSettings");

                string fileName   = exportSettings.FindPropertyRelative("fileName").stringValue;
                var    mode       = (ImageSequence.ExportMode)exportSettings.FindPropertyRelative("exportMode").enumValueIndex;
                var    frameCount = exportSettings.FindPropertyRelative("frameCount");

                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.EnumPopup(VFXToolboxGUIUtility.Get("Export Format"), mode);
                EditorGUI.EndDisabledGroup();
                if (fileName != "")
                {
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUILayout.TextField("Export Path", fileName);
                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    EditorGUILayout.HelpBox("This asset has not yet been exported. Please open editor and export it to generate a sequence.", MessageType.None);
                }
            }
        }
Esempio n. 4
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            m_RequireConstantRepaint = false;

            using (new EditorGUILayout.VerticalScope())
            {
                if (GUILayout.Button(VFXToolboxGUIUtility.Get("Edit Sequence"), GUILayout.Height(40)))
                {
                    ImageSequencer toolbox = EditorWindow.GetWindow <ImageSequencer>();
                    toolbox.LoadAsset((ImageSequence)Selection.activeObject);
                }

                VFXToolboxGUIUtility.ToggleableHeader(true, false, "Input Frames");
                {
                    var inputFrames     = serializedObject.FindProperty("inputFrameGUIDs");
                    int inputFrameCount = inputFrames.arraySize;
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        GUILayout.Label("Input sequence contains " + inputFrameCount + " frame(s).");
                        GUILayout.FlexibleSpace();
                        m_PreviewInput = GUILayout.Toggle(m_PreviewInput, VFXToolboxGUIUtility.Get("Preview"), EditorStyles.miniButton);
                    }

                    if (inputFrameCount > 0 && m_PreviewInput)
                    {
                        int index;

                        if (inputFrameCount > 1)
                        {
                            m_RequireConstantRepaint = true;
                            float time = (float)EditorApplication.timeSinceStartup;
                            index = (int)Mathf.Floor((time * 30) % inputFrameCount);
                        }
                        else
                        {
                            index = 0;
                        }

                        var    frame   = inputFrames.GetArrayElementAtIndex(index);
                        string guid    = frame.stringValue;
                        var    texture = AssetDatabase.LoadAssetAtPath <Texture2D>(AssetDatabase.GUIDToAssetPath(guid));
                        DrawAnimatedPreviewLayout(texture, ((float)index / inputFrameCount));
                    }
                    else
                    {
                        m_PreviewInput = false;
                    }
                }


                GUILayout.Space(24);
                VFXToolboxGUIUtility.ToggleableHeader(true, false, "Processors");
                {
                    var processors      = serializedObject.FindProperty("processorInfos");
                    int processorsCount = processors.arraySize;
                    EditorGUILayout.LabelField("Asset contains " + processorsCount + " Processor (s).");
                    EditorGUI.indentLevel++;
                    for (int i = 0; i < processorsCount; i++)
                    {
                        var item = processors.GetArrayElementAtIndex(i).objectReferenceValue as ProcessorInfo;
                        EditorGUILayout.LabelField("#" + i + " - " + item.Settings.label + (item.Enabled?"":" (Disabled)"));
                    }
                    EditorGUI.indentLevel--;
                }


                GUILayout.Space(24);
                VFXToolboxGUIUtility.ToggleableHeader(true, false, "Export Settings");

                var exportSettings = serializedObject.FindProperty("exportSettings");

                string fileName   = exportSettings.FindPropertyRelative("fileName").stringValue;
                var    mode       = (ImageSequence.ExportMode)exportSettings.FindPropertyRelative("exportMode").enumValueIndex;
                var    frameCount = exportSettings.FindPropertyRelative("frameCount");

                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.EnumPopup(VFXToolboxGUIUtility.Get("Export Format"), mode);
                EditorGUI.EndDisabledGroup();

                if (fileName != "")
                {
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUILayout.TextField("Exporting to ", fileName);
                    EditorGUI.EndDisabledGroup();

                    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 * 30) % 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);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("This asset has not yet been exported. Please open editor and export it to generate a sequence.", MessageType.None);
                }
            }
        }