private void DrawToolbar()
    {
        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);

        if (GUILayout.Button("Add new rule", EditorStyles.toolbarButton))
        {
            ImporterRulesEditorWindow.OpenWindow();
        }

        if (GUILayout.Button("Options", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
        {
            GenericMenu menu = new GenericMenu();
            menu.AddItem(new GUIContent("Disable all rules"), false, DisableAllRules);
            menu.AddItem(new GUIContent("Delete all rules"), false, DeleteAllRules);
            menu.AddItem(new GUIContent("Export rules"), false, ExportRules);
            menu.AddItem(new GUIContent("Import rules"), false, ImportRules);
            menu.ShowAsContext();
        }

        if (GUILayout.Button("Help", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
        {
            GenericMenu menu = new GenericMenu();
            menu.AddItem(new GUIContent("Documentation"), false, OnViewDocs);
            menu.AddItem(new GUIContent("Product Page"), false, OnProductPage);
            menu.AddItem(new GUIContent("Support"), false, OnSendMail);
            menu.AddItem(new GUIContent("About"), false, ImporterRulesAboutWindow.OpenWindow);
            menu.ShowAsContext();
        }

        EditorGUILayout.EndHorizontal();
    }
    public static void CreateRuleFromAsset()
    {
        Object[] selections = Selection.GetFiltered(typeof(Object), SelectionMode.Assets);

        if (selections.Length != 1)
        {
            EditorUtility.DisplayDialog("Failed", "Select one asset", "OK");
            return;
        }

        Object selection = selections[0];

        bool allowCreate = false;

        if (selection is Texture)
        {
            allowCreate = true;
        }
        else if (selection is Font)
        {
            allowCreate = true;
        }
        else if (selection is AudioClip)
        {
            allowCreate = true;
        }
        else if (selection is GameObject)
        {
            string        assetPath     = AssetDatabase.GetAssetPath(selection);
            AssetImporter assetImporter = AssetImporter.GetAtPath(assetPath);
            if (assetImporter is ModelImporter)
            {
                allowCreate = true;
            }
        }
        else
        {
            string         assetPath = AssetDatabase.GetAssetPath(selection);
            FileAttributes attr      = File.GetAttributes(assetPath);
            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            {
                allowCreate = true;
            }
        }

        if (!allowCreate)
        {
            EditorUtility.DisplayDialog("Failed", "Unknown importer", "OK");
            return;
        }

        if (wnd == null)
        {
            OpenWindow();
        }
        ImporterRulesEditorWindow.OpenWindow(selection);
    }
    public static void DuplicateRule(ImporterRule rule)
    {
        ImporterRule newRule = ImporterRulesEditorWindow.OpenWindow();

        newRule.CopyFrom(rule);
        string name  = newRule.name;
        Regex  regex = new Regex(@"\d+$", RegexOptions.IgnoreCase);

        if (regex.IsMatch(name))
        {
            newRule.name = regex.Replace(name, match => (int.Parse(match.Value) + 1).ToString());
        }
        else
        {
            newRule.name += " 2";
        }
    }
Beispiel #4
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();
        }