예제 #1
0
        void OnGUI()
        {
            if (m_pathButtonStyle == null)
            {
                m_pathButtonStyle = "minibutton";
            }

            m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos, GUILayout.Height(position.height));
            float cachedWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 100;
            EditorGUILayout.BeginVertical(m_contentStyle);

            string buildButtonStr = m_tex3DMode ? BuildTexture3DMessage : BuildArrayMessage;

            // build button
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginDisabledGroup(m_allTextures.Count <= 0);
            if (GUILayout.Button(buildButtonStr, "prebutton", GUILayout.Height(20)))
            {
                bool showWarning = false;
                for (int i = 0; i < m_allTextures.Count; i++)
                {
                    if (m_allTextures[i].width != m_sizes[m_selectedSizeX] || m_allTextures[i].height != m_sizes[m_selectedSizeY])
                    {
                        showWarning = true;
                    }
                }

                if (!showWarning)
                {
                    m_message = string.Empty;
                    if (m_tex3DMode)
                    {
                        BuildTexture3D();
                    }
                    else
                    {
                        BuildArray();
                    }
                }
                else if (EditorUtility.DisplayDialog("Warning!", "Some textures need to be resized to fit the selected size. Do you want to continue?", "Yes", "No"))
                {
                    m_message = string.Empty;
                    if (m_tex3DMode)
                    {
                        BuildTexture3D();
                    }
                    else
                    {
                        BuildArray();
                    }
                }
            }
            EditorGUI.EndDisabledGroup();
            EditorGUI.BeginDisabledGroup(m_lastSaved == null);
            GUIContent icon = EditorGUIUtility.IconContent("icons/d_ViewToolZoom.png");

            if (GUILayout.Button(icon, "prebutton", GUILayout.Width(28), GUILayout.Height(20)))
            {
                EditorGUIUtility.PingObject(m_lastSaved);
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();

            // message
            if (!string.IsNullOrEmpty(m_message))
            {
                if (GUILayout.Button("BUILD REPORT (click to hide):\n\n" + m_message, "helpbox"))
                {
                    m_message = string.Empty;
                }
            }

            // options
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Size");
            EditorGUIUtility.labelWidth = 16;
            m_selectedSizeX             = EditorGUILayout.Popup("X", m_selectedSizeX, m_sizesStr);
            EditorGUI.BeginDisabledGroup(m_lockRatio);
            m_selectedSizeY = EditorGUILayout.Popup("Y", m_lockRatio ? m_selectedSizeX : m_selectedSizeY, m_sizesStr);
            EditorGUI.EndDisabledGroup();
            EditorGUIUtility.labelWidth = 100;
            m_lockRatio = GUILayout.Toggle(m_lockRatio, "L", "minibutton", GUILayout.Width(18));
            EditorGUILayout.EndHorizontal();
            EditorGUI.BeginChangeCheck();
            m_tex3DMode = EditorGUILayout.Toggle("Texture 3D", m_tex3DMode);
            if (EditorGUI.EndChangeCheck())
            {
                if (!m_filenameChanged)
                {
                    m_fileName = m_tex3DMode ? Texture3DFilename:ArrayFilename;
                }
            }

            m_linearMode = EditorGUILayout.Toggle("Linear", m_linearMode);
            m_mipMaps    = EditorGUILayout.Toggle("Mip Maps", m_mipMaps);
            m_wrapMode   = (TextureWrapMode)EditorGUILayout.EnumPopup("Wrap Mode", m_wrapMode);
            m_filterMode = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", m_filterMode);
            m_anisoLevel = EditorGUILayout.IntSlider("Aniso Level", m_anisoLevel, 0, 16);

            m_selectedFormatEnum = (TextureFormat)EditorGUILayout.EnumPopup("Format", m_selectedFormatEnum);
            if (m_selectedFormatEnum == TextureFormat.DXT1Crunched)
            {
                m_selectedFormatEnum = TextureFormat.DXT1;
                Debug.Log("Texture Array does not support crunched DXT1 format. Changing to DXT1...");
            }
            else if (m_selectedFormatEnum == TextureFormat.DXT5Crunched)
            {
                m_selectedFormatEnum = TextureFormat.DXT5;
                Debug.Log("Texture Array does not support crunched DXT5 format. Changing to DXT5...");
            }

            m_quality = EditorGUILayout.IntSlider("Format Quality", m_quality, 0, 100);
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Path and Name");
            EditorGUILayout.BeginHorizontal();
            m_pathButtonContent.text = m_folderPath;
            Vector2 buttonSize = m_pathButtonStyle.CalcSize(m_pathButtonContent);

            if (GUILayout.Button(m_pathButtonContent, m_pathButtonStyle, GUILayout.MaxWidth(Mathf.Min(position.width * 0.5f, buttonSize.x))))
            {
                string folderpath = EditorUtility.OpenFolderPanel("Save Texture Array to folder", "Assets/", "");
                folderpath = FileUtil.GetProjectRelativePath(folderpath);
                if (string.IsNullOrEmpty(folderpath))
                {
                    m_folderPath = "Assets/";
                }
                else
                {
                    m_folderPath = folderpath + "/";
                }
            }
            EditorGUI.BeginChangeCheck();
            m_fileName = EditorGUILayout.TextField(m_fileName, GUILayout.ExpandWidth(true));
            if (EditorGUI.EndChangeCheck())
            {
                m_filenameChanged = true;
            }
            EditorGUILayout.LabelField(".asset", GUILayout.MaxWidth(40));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();

            // list
            EditorGUILayout.Separator();
            if (GUILayout.Button(ClearButtonStr))
            {
                m_allTextures.Clear();
            }

            if (m_listTextures != null)
            {
                m_listTextures.DoLayoutList();
            }

            GUILayout.Space(20);
            EditorGUILayout.EndVertical();
            EditorGUIUtility.labelWidth = cachedWidth;
            EditorGUILayout.EndScrollView();
            m_draggableArea.size = position.size;
            m_dragAndDropTool.TestDragAndDrop(m_draggableArea);
        }
        public override void OnInspectorGUI()
        {
            m_so.Update();

            if (m_pathButtonStyle == null)
            {
                m_pathButtonStyle = "minibutton";
            }

            EditorGUILayout.BeginHorizontal();
            var cache = EditorGUIUtility.labelWidth;

            EditorGUILayout.PrefixLabel("Size");
            EditorGUIUtility.labelWidth = 16;
            if (m_lockRatio.boolValue)
            {
                m_selectedSize.intValue = EditorGUILayout.Popup("X", m_selectedSize.intValue, m_sizesStr);
                EditorGUI.BeginDisabledGroup(m_lockRatio.boolValue);
                EditorGUILayout.Popup("Y", m_selectedSize.intValue, m_sizesStr);
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                EditorGUILayout.PropertyField(m_sizeX, new GUIContent("X"));
                EditorGUILayout.PropertyField(m_sizeY, new GUIContent("Y"));
            }
            EditorGUIUtility.labelWidth = 100;
#if UNITY_2017_1_OR_NEWER
            m_lockRatio.boolValue = GUILayout.Toggle(m_lockRatio.boolValue, "L", "minibutton", GUILayout.Width(18));
#else
            GUILayout.Toggle(m_lockRatio.boolValue, "L", "minibutton", GUILayout.Width(18));
            m_lockRatio.boolValue = true;
#endif
            if (m_lockRatio.boolValue)
            {
                m_sizeX.intValue = m_sizes[m_selectedSize.intValue];
                m_sizeY.intValue = m_sizes[m_selectedSize.intValue];
            }
            EditorGUIUtility.labelWidth = cache;
            EditorGUILayout.EndHorizontal();
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(m_tex3DMode, new GUIContent("Texture 3D"));
            if (EditorGUI.EndChangeCheck())
            {
                if (!m_filenameChanged.boolValue)
                {
                    m_fileName.stringValue = m_tex3DMode.boolValue ? Texture3DFilename : ArrayFilename;
                }
            }
            EditorGUILayout.PropertyField(m_linearMode, new GUIContent("Linear"));
            EditorGUILayout.PropertyField(m_mipMaps);
            EditorGUILayout.PropertyField(m_wrapMode);
            EditorGUILayout.PropertyField(m_filterMode);
            m_anisoLevel.intValue = EditorGUILayout.IntSlider("Aniso Level", m_anisoLevel.intValue, 0, 16);
            EditorGUILayout.PropertyField(m_selectedFormatEnum, new GUIContent("Format"));

            if (m_selectedFormatEnum.intValue == (int)TextureFormat.DXT1Crunched)
            {
                m_selectedFormatEnum.intValue = (int)TextureFormat.DXT1;
                Debug.Log("Texture Array does not support crunched DXT1 format. Changing to DXT1...");
            }
            else if (m_selectedFormatEnum.intValue == (int)TextureFormat.DXT5Crunched)
            {
                m_selectedFormatEnum.intValue = (int)TextureFormat.DXT5;
                Debug.Log("Texture Array does not support crunched DXT5 format. Changing to DXT5...");
            }

            m_quality.intValue = EditorGUILayout.IntSlider("Format Quality", m_quality.intValue, 0, 100);
            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("Path and Name");
            EditorGUILayout.BeginHorizontal();
            m_pathButtonContent.text = m_folderPath.stringValue;
            Vector2 buttonSize = m_pathButtonStyle.CalcSize(m_pathButtonContent);
            if (GUILayout.Button(m_pathButtonContent, m_pathButtonStyle, GUILayout.MaxWidth(Mathf.Min(Screen.width * 0.5f, buttonSize.x))))
            {
                string folderpath = EditorUtility.OpenFolderPanel("Save Texture Array to folder", "Assets/", "");
                folderpath = FileUtil.GetProjectRelativePath(folderpath);
                if (string.IsNullOrEmpty(folderpath))
                {
                    m_folderPath.stringValue = "Assets/";
                }
                else
                {
                    m_folderPath.stringValue = folderpath + "/";
                }
            }
            EditorGUI.BeginChangeCheck();
            m_fileName.stringValue = EditorGUILayout.TextField(m_fileName.stringValue, GUILayout.ExpandWidth(true));
            if (EditorGUI.EndChangeCheck())
            {
                m_filenameChanged.boolValue = m_fileName.stringValue == ArrayFilename ? false : true;
            }
            EditorGUILayout.LabelField(".asset", GUILayout.MaxWidth(40));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();

            if (GUILayout.Button("Clear"))
            {
                m_allTextures.ClearArray();
            }

            if (m_listTextures != null)
            {
                m_listTextures.DoLayoutList();
            }

            EditorGUILayout.Separator();

            m_dragAndDropTool.TestDragAndDrop(new Rect(0, 0, Screen.width, Screen.height));

            m_so.ApplyModifiedProperties();
        }
예제 #3
0
        void OnGUI()
        {
            if (m_pathButtonStyle == null)
            {
                m_pathButtonStyle = "minibutton";
            }

            m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos, GUILayout.Height(position.height));

            EditorGUILayout.BeginVertical(m_contentStyle);
            EditorGUI.BeginChangeCheck();
            m_currentShader = EditorGUILayout.ObjectField("Shader", m_currentShader, typeof(Shader), false) as Shader;
            if (EditorGUI.EndChangeCheck())
            {
                GetInitialInfo(m_currentShader);
            }

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Path and Filename");
            EditorGUILayout.BeginHorizontal();
            m_pathButtonContent.text = m_folderPath;
            Vector2 buttonSize = m_pathButtonStyle.CalcSize(m_pathButtonContent);

            if (GUILayout.Button(m_pathButtonContent, m_pathButtonStyle, GUILayout.MaxWidth(Mathf.Min(position.width * 0.5f, buttonSize.x))))
            {
                string folderpath = EditorUtility.OpenFolderPanel("Save Texture Array to folder", "Assets/", "");
                folderpath = FileUtil.GetProjectRelativePath(folderpath);
                if (string.IsNullOrEmpty(folderpath))
                {
                    m_folderPath = "Assets/";
                }
                else
                {
                    m_folderPath = folderpath + "/";
                }
            }

            m_settingsClassName = EditorGUILayout.TextField(m_settingsClassName, GUILayout.ExpandWidth(true));

            EditorGUILayout.LabelField(".cs", GUILayout.MaxWidth(40));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();

            m_menuEntry = EditorGUILayout.TextField("Name", m_menuEntry);

            EditorGUILayout.Separator();

            m_eventType = (PostProcessEvent)EditorGUILayout.EnumPopup("Event Type", m_eventType);

            EditorGUILayout.Separator();

            m_tooltipsFoldout = EditorGUILayout.Foldout(m_tooltipsFoldout, "Tooltips");
            if (m_tooltipsFoldout)
            {
                EditorGUI.indentLevel++;
                for (int i = 0; i < m_tooltips.Count; i++)
                {
                    m_tooltips[i].Tooltip = EditorGUILayout.TextField(m_tooltips[i].Name, m_tooltips[i].Tooltip);
                }
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Separator();

            if (GUILayout.Button("Build"))
            {
                string propertiesDecl = string.Empty;
                string propertiesSet  = string.Empty;
                GetShaderInfoFromShaderAsset(ref propertiesDecl, ref propertiesSet);
                string template = PPSFullTemplate;
                template = template.Replace(PPSRendererClass, m_rendererClassName);
                template = template.Replace(PPSSettingsClass, m_settingsClassName);
                template = template.Replace(PPSEventType, m_eventType.ToString());
                template = template.Replace(PPSPropertiesDecl, propertiesDecl);
                template = template.Replace(PPSPropertySet, propertiesSet);
                template = template.Replace(PPSMenuEntry, m_menuEntry);
                template = template.Replace(PPSShader, m_currentShader.name);
                string path = m_folderPath + m_settingsClassName + ".cs";
                IOUtils.SaveTextfileToDisk(template, path, false);
                AssetDatabase.Refresh();
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
            m_draggableArea.size = position.size;
            m_dragAndDropTool.TestDragAndDrop(m_draggableArea);
        }
        void OnGUI()
        {
            if (m_pathButtonStyle == null)
            {
                m_pathButtonStyle = "minibutton";
            }

            m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos, GUILayout.Height(position.height));

            EditorGUILayout.BeginVertical(m_contentStyle);
            EditorGUI.BeginChangeCheck();
            m_currentShader = EditorGUILayout.ObjectField("Shader", m_currentShader, typeof(Shader), false) as Shader;
            if (EditorGUI.EndChangeCheck())
            {
                GetInitialInfo(m_currentShader);
            }

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Path and Filename");
            EditorGUILayout.BeginHorizontal();
            m_pathButtonContent.text = m_folderPath;
            Vector2 buttonSize = m_pathButtonStyle.CalcSize(m_pathButtonContent);

            if (GUILayout.Button(m_pathButtonContent, m_pathButtonStyle, GUILayout.MaxWidth(Mathf.Min(position.width * 0.5f, buttonSize.x))))
            {
                string folderpath = EditorUtility.OpenFolderPanel("Save Texture Array to folder", "Assets/", "");
                folderpath = FileUtil.GetProjectRelativePath(folderpath);
                if (string.IsNullOrEmpty(folderpath))
                {
                    m_folderPath = "Assets/";
                }
                else
                {
                    m_folderPath = folderpath + "/";
                }
            }

            m_settingsClassName = EditorGUILayout.TextField(m_settingsClassName, GUILayout.ExpandWidth(true));

            EditorGUILayout.LabelField(".cs", GUILayout.MaxWidth(40));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.HelpBox("The path for the generated script should be outside of Amplify Shader Editor folder structure due to use of Assembly Definition files which will conflict and prevent to compile correctly.", MessageType.Warning);

            EditorGUILayout.Separator();

            m_menuEntry = EditorGUILayout.TextField("Name", m_menuEntry);

            EditorGUILayout.Separator();

            m_allowInSceneView = EditorGUILayout.Toggle("Allow In Scene View", m_allowInSceneView);

            EditorGUILayout.Separator();

            m_eventType = (ASEPostProcessEvent)EditorGUILayout.EnumPopup("Event Type", m_eventType);

            EditorGUILayout.Separator();

            m_tooltipsFoldout = EditorGUILayout.Foldout(m_tooltipsFoldout, "Tooltips");
            if (m_tooltipsFoldout)
            {
                EditorGUI.indentLevel++;
                for (int i = 0; i < m_tooltips.Count; i++)
                {
                    m_tooltips[i].Tooltip = EditorGUILayout.TextField(m_tooltips[i].Name, m_tooltips[i].Tooltip);
                }
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Separator();

            if (GUILayout.Button("Build"))
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
                string propertiesDecl = string.Empty;
                string propertiesSet  = string.Empty;
                GetShaderInfoFromShaderAsset(ref propertiesDecl, ref propertiesSet);
                string template = PPSFullTemplate;
                template = template.Replace(PPSRendererClass, m_rendererClassName);
                template = template.Replace(PPSSettingsClass, m_settingsClassName);
                template = template.Replace(PPSEventType, m_eventType.ToString());
                template = template.Replace(PPSPropertiesDecl, propertiesDecl);
                template = template.Replace(PPSPropertySet, propertiesSet);
                template = template.Replace(PPSMenuEntry, m_menuEntry);
                template = template.Replace(PPSAllowInSceneView, m_allowInSceneView?"true":"false");
                template = template.Replace(PPSShader, m_currentShader.name);
                string path = m_folderPath + m_settingsClassName + ".cs";
                IOUtils.SaveTextfileToDisk(template, path, false);
                System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
                AssetDatabase.Refresh();
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
            m_draggableArea.size = position.size;
            m_dragAndDropTool.TestDragAndDrop(m_draggableArea);
        }