Example #1
0
        public static void ExcludeIndividualAssetWithID(string guid)
        {
            AHSettings settings = LoadSettings();

            if (!settings.m_AssetGUIDExcludes.Contains(guid))
            {
                settings.m_AssetGUIDExcludes.Add(guid);
                setDirty(settings);
            }
        }
Example #2
0
        public static void ExcludeDirectory(UnityEngine.Object newDir)
        {
            AHSettings settings = LoadSettings();

            if (!settings.m_DirectoryExcludes.Contains(newDir))
            {
                settings.m_DirectoryExcludes.Add(newDir);
                setDirty(settings);
            }
        }
Example #3
0
        public static void ExcludeSubstring(string newSubstring)
        {
            AHSettings settings = LoadSettings();

            if (!settings.m_AssetSubstringExcludes.Contains(newSubstring))
            {
                settings.m_AssetSubstringExcludes.Add(newSubstring);
                setDirty(settings);
            }
        }
Example #4
0
        public static void ExcludeType(AHSerializableSystemType newtype)
        {
            AHSettings settings = LoadSettings();

            if (!settings.m_AssetTypeExcludes.Contains(newtype))
            {
                settings.m_AssetTypeExcludes.Add(newtype);
                setDirty(settings);
            }
        }
Example #5
0
        public static void ExcludeIndividualAssetWithpath(string path)
        {
            AHSettings settings = LoadSettings();
            string     guid     = AssetDatabase.AssetPathToGUID(path);

            if (!settings.m_AssetGUIDExcludes.Contains(guid))
            {
                if (!string.IsNullOrEmpty(guid))
                {
                    settings.m_AssetGUIDExcludes.Add(guid);
                    setDirty(settings);
                }
            }
        }
Example #6
0
        internal static string GetAssetPath()
        {
            //SettingsData
            string[] scriptableAssetsFound = AssetDatabase.FindAssets("AHSettingsData t:ScriptableObject", null);
            if (scriptableAssetsFound.Length >= 1)
            {
                return(AssetDatabase.GUIDToAssetPath(scriptableAssetsFound[0]));
            }
            //If the scriptableObject does not exist
            else
            {
                string[] allPaths = Directory.GetDirectories(Application.dataPath, "Settings", SearchOption.AllDirectories);
                foreach (string path in allPaths)
                {
                    if (path.Contains(string.Format("{0}AH{1}Editor{2}Settings", Path.DirectorySeparatorChar, Path.DirectorySeparatorChar, Path.DirectorySeparatorChar)))
                    {
                        string relativepath = "";

                        if (path.StartsWith(Application.dataPath))
                        {
                            relativepath = "Assets" + path.Substring(Application.dataPath.Length) + Path.DirectorySeparatorChar;
                        }

                        AHSettings asset            = ScriptableObject.CreateInstance <AHSettings>();
                        string     assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(relativepath + NAME + ".asset");

                        AssetDatabase.CreateAsset(asset, assetPathAndName);

                        AssetDatabase.SaveAssets();

                        return(assetPathAndName);
                    }
                }
            }
            return(null);
        }
Example #7
0
        private void OnGUI()
        {
            if (settings == null)
            {
                settings = AHSettings.LoadSettings();
            }

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            //Show all used types
            EditorGUILayout.BeginVertical();
            string selectedPath = AssetDatabase.GetAssetPath(Selection.activeObject);

            //Make sure this window has focus to update contents
            AHSettingsWindow.Instance.Repaint();

            EditorGUILayout.Separator();
            GUILayout.Label("This is the settingswindow for Asset Helper! " + System.Environment.NewLine + "-Choose folders, types or filenames to exclude when scanning the project", EditorStyles.boldLabel);
            GUILayout.Label("NB: If your project window is in \"Two column layout\" you need to select folders in the right hand side of that window", EditorStyles.miniLabel);

            GUILayout.Label("----------------------------------------------------------------------------", EditorStyles.boldLabel);
            //Force memorycleanup
            settings.m_MemoryCleanupActive = GUILayout.Toggle(settings.m_MemoryCleanupActive, "Force memory cleanup");
            GUILayout.Label("Enable this if you experience memory crashes (Much slower)", EditorStyles.miniLabel);
            GUILayout.Label("----------------------------------------------------------------------------", EditorStyles.boldLabel);

            EditorGUILayout.Separator();
            EditorGUILayout.Separator();

            //Do we have a folder selected
            bool bFolderSelected = System.IO.Directory.Exists(selectedPath);
            //Is it valid
            bool validSelection = (/*bFolderSelected && */ settings.ValidateDirectory(Selection.activeObject));

            //Select folder to exclude
            EditorGUILayout.BeginHorizontal();

            GUI.color = (validSelection ? AHHelper.AH_BLUE : AHHelper.AH_GREY);

            if (GUILayout.Button(validSelection ? "Exclude selected folder" : "No valid folder selected", GUILayout.Width(btnMinWidthLarge)))
            {
                if (validSelection)
                {
                    AHSettings.ExcludeDirectory(Selection.activeObject);
                }
            }

            GUI.color = m_IntialGUIColor;

            if (validSelection)
            {
                GUILayout.Label(selectedPath, EditorStyles.miniBoldLabel);
            }

            GUI.color = m_IntialGUIColor;
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();

            //Select type to exclude
            EditorGUILayout.BeginHorizontal();
            AHSerializableSystemType selectedType = null;

            if (Selection.activeObject)
            {
                selectedType = new AHSerializableSystemType(Selection.activeObject.GetType());
            }

            //Do we have a valid asset selected
            validSelection = (selectedType != null && !bFolderSelected && settings.ValidateType(selectedType));

            GUI.color = (validSelection ? AHHelper.AH_BLUE : AHHelper.AH_GREY);

            if (GUILayout.Button(validSelection ? "Exclude selected type" : "No valid type selected", GUILayout.Width(btnMinWidthLarge)))
            {
                if (validSelection)
                {
                    AHSettings.ExcludeType(selectedType);
                }
            }

            if (validSelection)
            {
                GUILayout.Label(selectedType.SystemType.ToString(), EditorStyles.miniBoldLabel);
            }

            GUI.color = m_IntialGUIColor;

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();

            //Exluded filename substrings
            EditorGUILayout.BeginHorizontal();

            validSelection = !string.IsNullOrEmpty(m_excludeSubstringInput) && settings.ValidateSubstring(m_excludeSubstringInput);
            GUI.color      = (validSelection ? AHHelper.AH_BLUE : AHHelper.AH_GREY);

            bool bHasHitEnter = false;

            Event e = Event.current;

            if (e.keyCode == KeyCode.Return)
            {
                bHasHitEnter = true;
            }

            if (bHasHitEnter || GUILayout.Button(validSelection ? "Exclude substring" : "No valid search string", GUILayout.Width(btnMinWidthLarge)))
            {
                if (validSelection)
                {
                    AHSettings.ExcludeSubstring(m_excludeSubstringInput);
                    //settings.ExcludeSubstring(m_excludeSubstringInput);
                    m_excludeSubstringInput = string.Empty;
                }
            }

            GUI.color = m_IntialGUIColor;
            m_excludeSubstringInput = GUILayout.TextField(m_excludeSubstringInput);

            //GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            if (validSelection)
            {
                GUILayout.Label(string.Format("Will exclude any asset with \"{0}\" in its path/name (might make asset Helper perform slower)", m_excludeSubstringInput));
            }

            EditorGUILayout.Separator();
            EditorGUILayout.Separator();

            //Select type to exclude
            EditorGUILayout.BeginHorizontal();

            //Do we have a valid asset selected
            validSelection = Selection.activeObject != null && (settings.ValidateAssetGUID(Selection.activeObject));

            GUI.color = (validSelection ? AHHelper.AH_BLUE : AHHelper.AH_GREY);

            if (GUILayout.Button(validSelection ? "Exclude selected asset" : "No project asset selected", GUILayout.Width(btnMinWidthLarge)))
            {
                if (validSelection)
                {
                    AHSettings.ExcludeIndividualAssetWithObject(Selection.activeObject);
                }
            }

            if (validSelection)
            {
                GUILayout.Label(Selection.activeObject.name, EditorStyles.miniBoldLabel);
            }

            GUI.color = m_IntialGUIColor;

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();

            GUILayout.Label("---------------------------Excluded Folders------------------------------", EditorStyles.boldLabel);

            if (settings.m_DirectoryExcludes.Count >= 1)
            {
                for (int i = settings.m_DirectoryExcludes.Count - 1; i >= 0; i--)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUI.color = AHHelper.AH_RED;

                    if (GUILayout.Button("Remove", GUILayout.Width(btnMinWidthSmall)))
                    {
                        settings.RemoveDirectoryAtIndex(i);
                        continue;
                    }
                    GUI.color = m_IntialGUIColor;
                    EditorGUILayout.ObjectField(settings.m_DirectoryExcludes[i], typeof(UnityEngine.Object), false);
                    EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                EditorGUILayout.LabelField("No folders are currently excluded");
            }

            EditorGUILayout.Separator();
            GUILayout.Label("---------------------------Excluded Types--------------------------------", EditorStyles.boldLabel);

            if (settings.m_AssetTypeExcludes.Count >= 1)
            {
                for (int i = settings.m_AssetTypeExcludes.Count - 1; i >= 0; i--)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUI.color = AHHelper.AH_RED;
                    if (GUILayout.Button("Remove", GUILayout.Width(btnMinWidthSmall)))
                    {
                        settings.RemoveTypeAtIndex(i);
                        continue;
                    }
                    GUI.color = m_IntialGUIColor;
                    GUILayout.Label(settings.m_AssetTypeExcludes[i].Name);
                    EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                EditorGUILayout.LabelField("No types are currently excluded");
            }

            EditorGUILayout.Separator();

            GUILayout.Label("---------------------------Excluded Substrings---------------------------", EditorStyles.boldLabel);
            if (settings.m_AssetSubstringExcludes.Count >= 1)
            {
                for (int i = settings.m_AssetSubstringExcludes.Count - 1; i >= 0; i--)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUI.color = AHHelper.AH_RED;
                    if (GUILayout.Button("Remove", GUILayout.Width(btnMinWidthSmall)))
                    {
                        settings.RemoveSubstringAtIndex(i);
                        continue;
                    }
                    GUI.color = m_IntialGUIColor;
                    GUILayout.Label(string.Format("\"{0}\"", settings.m_AssetSubstringExcludes[i]));
                    EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                EditorGUILayout.LabelField("No substrings are currently excluded");
            }


            GUILayout.Label("-----------------------Individually excluded assets----------------------", EditorStyles.boldLabel);
            if (settings.m_AssetGUIDExcludes.Count >= 1)
            {
                bool isDirty = false;
                for (int i = settings.m_AssetGUIDExcludes.Count - 1; i >= 0; i--)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUI.color = AHHelper.AH_RED;
                    if (GUILayout.Button("Remove", GUILayout.Width(btnMinWidthSmall)))
                    {
                        settings.RemoveAssetIDAtIndex(i);
                        continue;
                    }
                    GUI.color = m_IntialGUIColor;

                    string path = AssetDatabase.GUIDToAssetPath(settings.m_AssetGUIDExcludes[i]);
                    Object obj  = AssetDatabase.LoadAssetAtPath(path, typeof(Object));

                    if (obj != null)
                    {
                        EditorGUILayout.ObjectField(obj, typeof(UnityEngine.Object), false);
                    }
                    else
                    {
                        isDirty = true;
                    }
                    //GUILayout.Label(string.Format("\"{0}\"", "Asset cannot be found"));

                    EditorGUILayout.EndHorizontal();
                }

                if (Event.current.type != EventType.Layout && isDirty)
                {
                    settings.CleanExcludedAssets();
                }
            }
            else
            {
                EditorGUILayout.LabelField("No project assets are currently excluded");
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }
Example #8
0
 private static void setDirty(AHSettings settings)
 {
     EditorUtility.SetDirty(settings);
 }