Exemplo n.º 1
0
 public AssetObjectInfo(string path, SerializableSystemType type)
 {
     this.m_Path = path;
     string[] parts = path.Split('/');
     this.m_Name = parts[parts.Length - 1];
     this.m_Type = type;
 }
Exemplo n.º 2
0
 public AssetObjectInfo(string path, SerializableSystemType type)
 {
     this.m_Path = path;
     string[] parts = path.Split('/');
     this.m_Name = parts[parts.Length - 1];
     this.m_Type = type;
     System.IO.FileInfo fileInfo = new System.IO.FileInfo(path);
     this.m_FileSize       = fileInfo.Length;
     this.m_FileSizeString = AssetHunterHelper.BytesToString(m_FileSize);
 }
Exemplo n.º 3
0
        internal void SetAssetInfo(UnityEngine.Object obj, string path)
        {
            this.m_path = path;
            string[] parts = path.Split('/');
            this.m_name = parts[parts.Length - 1];

            m_assetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(path);
            m_type      = new SerializableSystemType(obj.GetType());

            AssetHunterHelper.UnloadUnused();
        }
        internal void SetAssetInfo(UnityEngine.Object obj, string path)
        {
            this.m_path = path;
            string[] parts = path.Split('/');
            this.m_name = parts[parts.Length - 1];

            m_assetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(path);

            //TODO Make sure we are doing proper garbage collection
            m_type = new SerializableSystemType(obj.GetType());

            //TODO Memory leak management (Perhaps should be a toggle value in window, or automatically detect if needed
            EditorUtility.UnloadUnusedAssets();
        }
Exemplo n.º 5
0
        private static void traverseDirectory(int parentIndex, string path, List <BuildReportAsset> usedAssets, int heirarchyDepth, ref int directoriesTraversed, SortedDictionary <SerializableSystemType, bool> validTypeList)
        {
            directoriesTraversed++;

            EditorUtility.DisplayProgressBar(
                "Traversing Directories",
                "(" + directoriesTraversed + " of " + m_NumberOfDirectories + ") Analyzing " + path.Substring(path.IndexOf("/Assets") + 1),
                (float)directoriesTraversed / (float)m_NumberOfDirectories);

            //Get the settings to exclude vertain folders or suffixes
            foreach (UnityEngine.Object dir in AssetHunterMainWindow.Instance.settings.m_DirectoryExcludes)
            {
                //TODO Can this be done more elegantly
                int                startingIndex = Application.dataPath.Length - 6;
                string             relativePath  = path.Substring(startingIndex, path.Length - startingIndex);
                UnityEngine.Object obj           = AssetDatabase.LoadAssetAtPath(relativePath, typeof(UnityEngine.Object));

                if (dir == obj)
                {
                    //This folder was exluded
                    return;
                }
            }

            string[] assetsInDirectory = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly)
                                         .Where(name => !name.ToLowerInvariant().EndsWith(".meta") &&
                                                (!name.ToLowerInvariant().EndsWith(".unity")) &&
                                                (!name.ToLowerInvariant().EndsWith("thumbs.db")) &&
                                                (!name.ToLowerInvariant().EndsWith(".orig")) &&
                                                (!name.ToLowerInvariant().Contains(Path.DirectorySeparatorChar + "heureka" + Path.DirectorySeparatorChar)) &&
                                                (!name.ToLowerInvariant().Contains(Path.DirectorySeparatorChar + "plugins" + Path.DirectorySeparatorChar)) &&
                                                (!name.ToLowerInvariant().Contains(Path.DirectorySeparatorChar + "streamingassets" + Path.DirectorySeparatorChar)) &&
                                                (!name.ToLowerInvariant().Contains(Path.DirectorySeparatorChar + "resources" + Path.DirectorySeparatorChar)) &&
                                                (!name.ToLowerInvariant().Contains(Path.DirectorySeparatorChar + "editor default resources" + Path.DirectorySeparatorChar)) &&
                                                (!name.ToLowerInvariant().Contains(Path.DirectorySeparatorChar + "editor" + Path.DirectorySeparatorChar)) &&
                                                (!name.ToLowerInvariant().Contains(@".ds_store")) &&
                                                (!name.ToLowerInvariant().Contains(@".workspace.mel")) &&
                                                (!name.ToLowerInvariant().Contains(@".mayaswatches")))
                                         .ToArray();

            for (int i = 0; i < assetsInDirectory.Length; i++)
            {
                assetsInDirectory[i] = assetsInDirectory[i].Substring(assetsInDirectory[i].IndexOf("/Assets") + 1);
                assetsInDirectory[i] = assetsInDirectory[i].Replace(@"\", "/");
            }

            //Find any assets that does not live in UsedAssets List
            var result = assetsInDirectory.Where(p => !usedAssets.Any(p2 => UnityEditor.AssetDatabase.GUIDToAssetPath(p2.GUID) == p));

            //Create new folder object
            ProjectFolderInfo afInfo = new ProjectFolderInfo();

            afInfo.DirectoryName = path.Substring(path.IndexOf("/Assets") + 1).Replace(@"\", "/");
            afInfo.ParentIndex   = parentIndex;

            if (heirarchyDepth == 0)
            {
                afInfo.FoldOut = true;
            }

            //Add to static list
            AssetHunterMainWindow.Instance.AddProjectFolderInfo(afInfo);

            if (parentIndex != -1)
            {
                AssetHunterMainWindow.Instance.GetFolderList()[parentIndex].AddChildFolder(afInfo);
            }

            UnityEngine.Object objToFind;
            foreach (string assetName in result)
            {
                objToFind = AssetDatabase.LoadAssetAtPath(assetName, typeof(UnityEngine.Object));

                if (objToFind == null)
                {
                    Debug.LogWarning("Couldnt find " + assetName);
                    continue;
                }

                SerializableSystemType assetType = new SerializableSystemType(objToFind.GetType());

                if (assetType.SystemType != typeof(MonoScript) && (!AssetHunterMainWindow.Instance.settings.m_AssetTypeExcludes.Contains(assetType)))
                {
                    AssetObjectInfo newAssetInfo = new AssetObjectInfo(assetName, assetType);
                    afInfo.AddAsset(newAssetInfo);
                }

                objToFind = null;

                //Memory leak safeguard
                UnloadUnused();
            }

            string[] nextLevelDirectories = System.IO.Directory.GetDirectories(path, "*.*", System.IO.SearchOption.TopDirectoryOnly);

            foreach (string nld in nextLevelDirectories)
            {
                traverseDirectory(AssetHunterMainWindow.Instance.GetFolderList().IndexOf(afInfo), nld, usedAssets, (heirarchyDepth + 1), ref directoriesTraversed, validTypeList);
            }
        }
Exemplo n.º 6
0
 internal void ExcludeType(SerializableSystemType newtype)
 {
     m_AssetTypeExcludes.Add(newtype);
 }
Exemplo n.º 7
0
 internal bool ValidateType(SerializableSystemType newtype)
 {
     return(!m_AssetTypeExcludes.Contains(newtype));
 }
Exemplo n.º 8
0
        private static void traverseDirectory(int parentIndex, string path, List <BuildReportAsset> usedAssets, int heirarchyDepth, ref int directoriesTraversed, SortedDictionary <SerializableSystemType, bool> validTypeList)
        {
            directoriesTraversed++;

            EditorUtility.DisplayProgressBar(
                "Traversing Directories",
                "(" + directoriesTraversed + " of " + m_NumberOfDirectories + ") Analyzing " + path.Substring(path.IndexOf("/Assets") + 1),
                (float)directoriesTraversed / (float)m_NumberOfDirectories);

            //Get the settings to exclude vertain folders or suffixes
            foreach (UnityEngine.Object dir in AssetHunterMainWindow.Instance.settings.m_DirectoryExcludes)
            {
                //TODO Can this be done more elegantly
                int                startingIndex = Application.dataPath.Length - 6;
                string             relativePath  = path.Substring(startingIndex, path.Length - startingIndex);
                UnityEngine.Object obj           = AssetDatabase.LoadAssetAtPath(relativePath, typeof(UnityEngine.Object));

                if (dir == obj)
                {
                    //This folder was exluded
                    return;
                }
            }

            //Exclude types and folders that should not be reviewed
            //TODO perhaps improve performance of this step (Also use String.Contains(excluder, StringComparison.OrdinalIgnoreCase)) might be better not to use LINQ
            string[] assetsInDirectory = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly)
                                         .Where(name => !name.ToLowerInvariant().EndsWith(".meta") &&
                                                (!name.ToLowerInvariant().EndsWith(".unity")) &&
                                                (!name.ToLowerInvariant().EndsWith("thumbs.db")) &&
                                                (!name.ToLowerInvariant().EndsWith(".orig")) &&
                                                (!name.ToLowerInvariant().Contains(Path.DirectorySeparatorChar + "heureka" + Path.DirectorySeparatorChar)) &&
                                                (!name.ToLowerInvariant().Contains(Path.DirectorySeparatorChar + "plugins" + Path.DirectorySeparatorChar)) &&
                                                (!name.ToLowerInvariant().Contains(Path.DirectorySeparatorChar + "streamingassets" + Path.DirectorySeparatorChar)) &&
                                                (!name.ToLowerInvariant().Contains(Path.DirectorySeparatorChar + "resources" + Path.DirectorySeparatorChar)) &&
                                                (!name.ToLowerInvariant().Contains(Path.DirectorySeparatorChar + "editor default resources" + Path.DirectorySeparatorChar)) &&
                                                (!name.ToLowerInvariant().Contains(Path.DirectorySeparatorChar + "editor" + Path.DirectorySeparatorChar)) &&
                                                (!name.ToLowerInvariant().EndsWith(@".ds_store")) &&
                                                (!name.ToLowerInvariant().EndsWith(@".workspace.mel")) &&
                                                (!name.ToLowerInvariant().EndsWith(@".mayaswatches")))
                                         .ToArray();

            //TODO this could also be improved for performance
            for (int i = 0; i < assetsInDirectory.Length; i++)
            {
                assetsInDirectory[i] = assetsInDirectory[i].Substring(assetsInDirectory[i].IndexOf("/Assets") + 1);
                assetsInDirectory[i] = assetsInDirectory[i].Replace(@"\", "/");
            }

            //Find any assets that does not live in UsedAssets List
            //TODO for performance reasons, perhaps dont to this for each folder, but just once, when finished?
            //That would mean to do folder creation and populating unused assets lists after all folders are traversed
            var result = assetsInDirectory.Where(p => !usedAssets.Any(p2 => UnityEditor.AssetDatabase.GUIDToAssetPath(p2.GUID) == p));

            //Create new folder object
            ProjectFolderInfo afInfo = new ProjectFolderInfo();

            //TODO this could also be improved for performance
            afInfo.DirectoryName = path.Substring(path.IndexOf("/Assets") + 1).Replace(@"\", "/");
            afInfo.ParentIndex   = parentIndex;

            if (heirarchyDepth == 0)
            {
                afInfo.FoldOut = true;
            }

            //Add to static list
            AssetHunterMainWindow.Instance.AddProjectFolderInfo(afInfo);

            if (parentIndex != -1)
            {
                AssetHunterMainWindow.Instance.GetFolderList()[parentIndex].AddChildFolder(afInfo);
            }

            UnityEngine.Object objToFind;
            foreach (string assetName in result)
            {
                bool bExclude = false;

                foreach (string excluder in AssetHunterMainWindow.Instance.settings.m_AssetSubstringExcludes)
                {
                    //Exlude Asset Exclude substrings from settings
                    //If we find an excluded asset just continue to next iteration in loop
                    if (assetName.Contains(excluder, StringComparison.OrdinalIgnoreCase))
                    {
                        bExclude = true;
                    }
                }
                if (bExclude)
                {
                    continue;
                }

                objToFind = AssetDatabase.LoadAssetAtPath(assetName, typeof(UnityEngine.Object));

                if (objToFind == null)
                {
                    Debug.LogWarning("Couldnt find " + assetName);
                    continue;
                }

                SerializableSystemType assetType = new SerializableSystemType(objToFind.GetType());

                if (assetType.SystemType != typeof(MonoScript) && (!AssetHunterMainWindow.Instance.settings.m_AssetTypeExcludes.Contains(assetType)))
                {
                    AssetObjectInfo newAssetInfo = new AssetObjectInfo(assetName, assetType);
                    afInfo.AddAsset(newAssetInfo);
                }

                objToFind = null;

                //Memory leak safeguard
                //This have heavy performance implications
                if (AssetHunterMainWindow.Instance.settings.m_MemoryCleanupActive)
                {
                    UnloadUnused();
                }
            }

            string[] nextLevelDirectories = System.IO.Directory.GetDirectories(path, "*.*", System.IO.SearchOption.TopDirectoryOnly);

            //Memory leak safeguard per folder
            if (!AssetHunterMainWindow.Instance.settings.m_MemoryCleanupActive)
            {
                UnloadUnused();
            }

            foreach (string nld in nextLevelDirectories)
            {
                traverseDirectory(AssetHunterMainWindow.Instance.GetFolderList().IndexOf(afInfo), nld, usedAssets, (heirarchyDepth + 1), ref directoriesTraversed, validTypeList);
            }
        }