private void OnGUI()
    {
        if (tempRule == null)
        {
            return;
        }

        tempRule.DrawEditor();

        GUILayout.BeginHorizontal();

        if (GUILayout.Button("Save"))
        {
            if (tempRule.pathComparer == ImporterRulesPathComparer.regex && !string.IsNullOrEmpty(tempRule.pattern))
            {
                try
                {
                    new Regex(tempRule.pattern);
                }
                catch (Exception)
                {
                    Debug.LogWarning("Regex pattern contains an error.");
                    return;
                }
            }

            if (activeRule != null)
            {
                activeRule.CopyFrom(tempRule);
            }
            else
            {
                ImporterRulesWindow.AddRule(tempRule);
            }
            ImporterRulesWindow.Save();
            ImporterRulesWindow.RedrawWindow();
            Close();
        }

        if (GUILayout.Button("Cancel"))
        {
            activeRule = null;
            Close();
        }

        GUILayout.EndHorizontal();
    }
Пример #2
0
        public void DrawPreview(int index)
        {
            string[] types = { "TextureImporter", "ModelImporter", "AudioImporter", "MovieImporter", "TrueTypeFontImporter" };

            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUILayout.BeginHorizontal();
            expanded = GUILayout.Toggle(expanded, "", EditorStyles.foldout, GUILayout.ExpandWidth(false));

            EditorGUI.BeginChangeCheck();
            enabled = GUILayout.Toggle(enabled, "", GUILayout.ExpandWidth(false));
            if (EditorGUI.EndChangeCheck())
            {
                ImporterRulesWindow.Save();
            }

            GUILayout.Label(name + " [" + types[(int)type] + "]");

            if (ImporterRulesWindow.countRules > 1)
            {
                if (GUILayout.Button(new GUIContent("▲", "Move up"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    ImporterRulesWindow.SetRuleIndex(this, index - 1);
                }
                if (GUILayout.Button(new GUIContent("▼", "Move down"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                {
                    ImporterRulesWindow.SetRuleIndex(this, index + 1);
                }
            }
            if (GUILayout.Button(new GUIContent("►", "Apply the rule to the existing assets"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
            {
                ImporterRulesWindow.onlyLogRules = Event.current.shift;
                if (EditorUtility.DisplayDialog("Apply the rule", "Apply the rule to the existing assets?", "Apply", "Cancel"))
                {
                    ApplyToExists();
                }
                ImporterRulesWindow.onlyLogRules = false;
            }
            if (GUILayout.Button(new GUIContent("E", "Edit"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
            {
                ImporterRulesEditorWindow.OpenWindow(this);
            }
            if (GUILayout.Button(new GUIContent("D", "Duplicate"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
            {
                ImporterRulesWindow.DuplicateRule(this);
            }
            if (GUILayout.Button(new GUIContent("X", "Delete"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
            {
                if (EditorUtility.DisplayDialog("Delete rule", "You sure want to delete a rule?", "Delete", "Cancel"))
                {
                    deleted = true;
                }
            }
            EditorGUILayout.EndHorizontal();

            if (expanded)
            {
                EditorGUILayout.Space();
                EditorGUI.BeginDisabledGroup(true);

                DrawEditor(false);

                EditorGUI.EndDisabledGroup();
            }

            EditorGUILayout.EndVertical();
        }