Exemplo n.º 1
0
        private void loadEditorLog()
        {
            m_newBuildReady = false;

            m_ProjectFolderList.Clear();
            m_BuildLog = AHHelper.AnalyzeBuildLog();

            if (m_BuildLog.IsEmpty())
            {
                m_BuildLogLoaded = false;
                return;
            }
            else
            {
                m_BuildLogLoaded = true;
            }


            List <string> usedPrefabsInScenes = AHReader.GetPrefabsFromSceneFiles(AHHelper.GetEnabledSceneNamesInBuild(), out m_assetSceneDependencies);

            m_BuildLog.AddPrefabs(usedPrefabsInScenes);
            m_BuildLog.AddPlatformSpecificAssets();
            m_BuildLog.SortUsed();

            AHHelper.PopulateUnusedList(m_BuildLog, m_unusedTypeDict);

            refreshUnusedAssets();
        }
Exemplo n.º 2
0
        private int calcAssetsInChildren(AHProjectFolderInfo assetFolderInfo, SortedDictionary <AHSerializableSystemType, bool> validTypeList, out long folderFileSize)
        {
            assetFolderInfo.m_fileSize = assetFolderInfo.GetUnusedAssetSize();

            long childrenSizeAccumulated = 0;

            int value = 0;

            foreach (int indexer in assetFolderInfo.m_childFolderIndexers)
            {
                long childSize = 0;
                value += AHMainWindow.Instance.GetFolderList()[indexer].m_assetsInChildren = calcAssetsInChildren(AHMainWindow.Instance.GetFolderList()[indexer], validTypeList, out childSize);

                childrenSizeAccumulated += childSize;
            }

            List <AssetObjectInfo> assetInfoList = (assetFolderInfo.AssetList.Where(val => (validTypeList.ContainsKey(val.m_Type) && validTypeList[val.m_Type]) == true)).ToList <AssetObjectInfo>();

            assetFolderInfo.m_fileSizeString      = AHHelper.BytesToString(assetFolderInfo.m_fileSize);
            assetFolderInfo.m_fileSizeAccumulated = assetFolderInfo.m_fileSize + childrenSizeAccumulated;

            assetFolderInfo.m_fileSizeAccumulatedString = AHHelper.BytesToString(assetFolderInfo.m_fileSizeAccumulated);

            folderFileSize = assetFolderInfo.m_fileSizeAccumulated;

            return(value + assetInfoList.Count());
        }
Exemplo n.º 3
0
 private void GetSceneInfo()
 {
     m_allScenesInProject               = AHHelper.GetAllSceneNames().ToList <string>();
     m_allScenesInBuildSettings         = AHHelper.GetAllSceneNamesInBuild().ToList <string>();
     m_allEnabledScenesInBuildSettings  = AHHelper.GetEnabledSceneNamesInBuild().ToList <string>();
     m_allDisabledScenesInBuildSettings = SubtractSceneArrays(m_allScenesInBuildSettings, m_allEnabledScenesInBuildSettings);
     m_allUnreferencedScenes            = SubtractSceneArrays(m_allScenesInProject, m_allScenesInBuildSettings);
 }
Exemplo n.º 4
0
        internal void AddPlatformSpecificAssets()
        {
            int counter = 0;
            int countTo = Enum.GetValues(typeof(BuildTargetGroup)).Length;

            //TODO Get all the different splash screens and config files somehow
            List <UnityEngine.Object> splash = new List <UnityEngine.Object>();

#if UNITY_5_5_OR_NEWER
            //Dont add splashscreen in this version
#else
            splash.Add(UnityEditor.PlayerSettings.xboxSplashScreen);
#endif
            //Loop the entries
            foreach (UnityEngine.Object obj in splash)
            {
                //Early out if it already exist
                if (obj == null || m_BuildSizeList.Exists(val => val.Path == AssetDatabase.GetAssetPath(obj)))
                {
                    continue;
                }

                BuildReportAsset newAsset = new BuildReportAsset();

                newAsset.SetAssetInfo(obj, AssetDatabase.GetAssetPath(obj));
                //newAsset.SetSize(0.0f, "--");
                m_BuildSizeList.Add(newAsset);
            }

            //Loop icons in buildtargetgroups
            foreach (BuildTargetGroup btg in (BuildTargetGroup[])Enum.GetValues(typeof(BuildTargetGroup)))
            {
                EditorUtility.DisplayProgressBar(
                    "Add Target Specifics for " + btg.ToString(),
                    "Looking at icons and splash screens for targetgroups",
                    (float)counter / (float)countTo);

                Texture2D[] buildTargetGroupTextures = UnityEditor.PlayerSettings.GetIconsForTargetGroup(btg);

                foreach (Texture2D curIcon in buildTargetGroupTextures)
                {
                    //Early out if it already exist
                    if (curIcon == null || m_BuildSizeList.Exists(val => val.Path == AssetDatabase.GetAssetPath(curIcon)))
                    {
                        continue;
                    }

                    BuildReportAsset newAsset = new BuildReportAsset();

                    newAsset.SetAssetInfo(curIcon, AssetDatabase.GetAssetPath(curIcon));
                    //newAsset.SetSize(0.0f, "--");
                    m_BuildSizeList.Add(newAsset);
                }
                AHHelper.UnloadUnused();
            }

            EditorUtility.ClearProgressBar();
        }
Exemplo n.º 5
0
 public AssetObjectInfo(string path, AHSerializableSystemType 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 = AHHelper.BytesToString(m_FileSize);
 }
Exemplo n.º 6
0
        private static AHMainWindow initializeWindow()
        {
            m_IntialGUIColor = GUI.color;

            m_window = EditorWindow.GetWindow <AHMainWindow>();
            m_window.Show();
            loadEditorResources();

            m_window.m_BuildLogExists = AHHelper.HasBuildLogAvaliable();

            return(m_window);
        }
Exemplo n.º 7
0
        internal void SetAssetInfo(UnityEngine.Object obj, string path)
        {
            long fileSize;

#if UNITY_2017_1_OR_NEWER
            fileSize = Profiler.GetRuntimeMemorySizeLong(obj);
#else
            fileSize = Profiler.GetRuntimeMemorySize(obj);
#endif
            SetSize(fileSize);

            this.m_path = path;
            //string[] parts = path.Split('/');
            this.m_name = obj.name;// parts[parts.Length - 1];

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

            AHHelper.UnloadUnused();
        }
Exemplo n.º 8
0
        private void showDefaultBody()
        {
            EditorGUILayout.BeginVertical();

            //Draw excluded types foldout
            if (bShowExcludeFoldout)
            {
                GUILayout.Label("-------------------------------------------------------------------------");
                if (settings.HasDirectoryExcludes())
                {
                    GUI.color             = AHHelper.AH_BLUE;
                    EditorGUI.indentLevel = 1;
                    EditorGUILayout.LabelField("Excluded Directories", EditorStyles.whiteBoldLabel);
                    GUI.color             = m_IntialGUIColor;
                    EditorGUI.indentLevel = 2;
                    foreach (UnityEngine.Object obj in settings.m_DirectoryExcludes)
                    {
                        EditorGUILayout.LabelField(AssetDatabase.GetAssetPath(obj), EditorStyles.miniLabel);
                    }
                }
                if (settings.HasTypeExcludes())
                {
                    GUI.color             = AHHelper.AH_BLUE;
                    EditorGUI.indentLevel = 1;
                    EditorGUILayout.LabelField("Excluded Types", EditorStyles.whiteBoldLabel);
                    GUI.color             = m_IntialGUIColor;
                    EditorGUI.indentLevel = 2;
                    foreach (AHSerializableSystemType sType in settings.m_AssetTypeExcludes)
                    {
                        EditorGUILayout.LabelField(sType.Name);
                    }
                }
                if (settings.HasSubStringExcludes())
                {
                    GUI.color             = AHHelper.AH_BLUE;
                    EditorGUI.indentLevel = 1;
                    EditorGUILayout.LabelField("Excluded Strings", EditorStyles.whiteBoldLabel);
                    GUI.color             = m_IntialGUIColor;
                    EditorGUI.indentLevel = 2;
                    foreach (string substring in settings.m_AssetSubstringExcludes)
                    {
                        EditorGUILayout.LabelField(substring);
                    }
                }
                GUILayout.Label("-------------------------------------------------------------------------");
                GUILayout.Space(10);
            }

            //If there is no valid build log
            if (!m_BuildLogExists)
            {
                m_BuildLogExists = AHHelper.HasBuildLogAvaliable();

                if (!m_BuildLogExists)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label(m_UIWarning);
                    GUILayout.Label("Asset Helper needs a recent build in order to work", EditorStyles.boldLabel);
                    EditorGUILayout.EndHorizontal();

                    GUILayout.Label("Create a build (Ctrl+Shift+B)");

                    //requires unity 5 to work
                    if (GUILayout.Button("Open Build Settings"))
                    {
                        EditorWindow.GetWindow(Type.GetType("UnityEditor.BuildPlayerWindow,UnityEditor"));
                    }

                    GUILayout.FlexibleSpace();
                    return;
                }
            }

            string buildLogButtonText;

            EditorGUI.indentLevel = 0;
            EditorGUILayout.EndVertical();

            GUILayout.Label("-------------------------------Build Info--------------------------------");

            //If build log up to date
            if (!m_newBuildReady)
            {
                buildLogButtonText = m_BuildLogLoaded ? "Log updated (refresh)" : "Load Build Log (Required)";
                GUI.color          = m_BuildLogLoaded ? AHHelper.AH_GREEN : AHHelper.AH_RED;
            }

            //If build log outdated
            else
            {
                buildLogButtonText = "Log outdated(Refresh)";
                GUI.color          = AHHelper.AH_YELLOW1;
            }

            //Load the Editor build log
            if (GUILayout.Button(buildLogButtonText, GUILayout.Width(375)))
            {
                loadEditorLog();
                return;
            }
            //GUILayout.FlexibleSpace();
            EditorGUILayout.Space();

            GUILayout.Label("------------------------------Select Mode------------------------------");
            EditorGUILayout.BeginHorizontal();

            //Choose window state
            GUI.color = (m_WindowState == AHWindowState.UnusedAssets) ? AHHelper.AH_GREY : m_IntialGUIColor;
            if (GUILayout.Button(AHWindowState.UnusedAssets.ToString(), GUILayout.MinWidth(btnMinWidth)))
            {
                changeState(AHWindowState.UnusedAssets);
            }
            EditorGUILayout.Space();

            GUI.color = (m_WindowState == AHWindowState.BuildReport) ? AHHelper.AH_GREY : m_IntialGUIColor;
            if (GUILayout.Button(AHWindowState.BuildReport.ToString(), GUILayout.MinWidth(btnMinWidth)))
            {
                //Shot buildreport
                changeState(AHWindowState.BuildReport);
            }

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

            #region scriptdetection

            /*EditorGUILayout.BeginHorizontal();
             *
             * GUI.color = AHHelper.AH_RED;
             * if (GUILayout.Button(AHWindowState.UnusedScripts.ToString() + " (WIP - USE WITH CONSIDERATION)", GUILayout.MinWidth(btnMinWidth * 2 + 14)))
             * {
             *
             *  GUI.color = m_IntialGUIColor;
             *  //Get added scripts
             *  //List<Type> scriptAssemblyTypes = AHHelper.GetScriptAssembly();
             *
             *  //Find all enabled scenes in buildsettings
             *  EditorBuildSettingsScene[] activeScenes = EditorBuildSettings.scenes.Where(val => val.enabled == true).ToArray<EditorBuildSettingsScene>();
             *
             *
             *  //All script dependencies for all enabled levels in buildsettings
             *  m_UsedScriptList = AHHelper.GetScriptLevelDependencies(activeScenes);
             *
             *  //Find ALL scripts in scriptAssembly
             *  //TODO ADD THIS TO ATTEMPT TO LOCATE UNUSED CODE
             *  //m_UnusedScriptList = AHHelper.GetAddedComponents();
             *
             *  //Remove "Used Scripts" from list
             *  m_UnusedScriptList.RemoveAll(val => m_UsedScriptList.Contains(val));
             *
             *  changeState(AHWindowState.UnusedScripts);
             * }
             *
             * GUILayout.FlexibleSpace();
             * EditorGUILayout.EndHorizontal();
             * EditorGUILayout.Space();*/

            #endregion

            //Reset GUI Color
            GUI.color = m_IntialGUIColor;
        }
Exemplo n.º 9
0
        private void showDefaultHeader()
        {
            EditorGUILayout.LabelField("Asset Helper", EditorStyles.boldLabel);
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();

            //BUTTON Settings
            EditorGUILayout.Space();
            // GUI.color = AHHelper.AH_BLUE;
            if (GUILayout.Button(new GUIContent("Edit settings", m_UISettings), GUILayout.Width(btnMinWidth - 70), GUILayout.Height(20)))
            {
                EditorWindow.GetWindow <AHSettingsWindow>(true, "Asset Helper Settings");
            }

            //BUTTON Open Log
            EditorGUILayout.Space();
            //GUI.color = AHHelper.AH_RED;
            if (GUILayout.Button("Open log", GUILayout.MinWidth(100)))
            {
                System.Diagnostics.Process.Start(AHHelper.GetLogFolderPath());
            }

            //BUTTON delete empty folders
            EditorGUILayout.Space();
            //GUI.color = AHHelper.AH_BLUE;
            if (GUILayout.Button("Delete empty folders", GUILayout.MinWidth(120)))
            {
                if (EditorUtility.DisplayDialog("Delete empty folder", "Are you sure you want to delete all empty folders", "Yes", "No"))
                {
                    string path        = Application.dataPath;
                    int    deleteCount = 0;
                    deleteEmptyDirectories(path, ref deleteCount);

                    Debug.LogWarning(deleteCount + " empty folders was deleted by Asset Helper");
                }
            }

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

            GUILayout.Space(5);

            EditorGUILayout.BeginHorizontal();

            //BUTTON Settings
            EditorGUILayout.Space();
            if (GUILayout.Button("Scene overview", GUILayout.Width(btnMinWidth - 70), GUILayout.Height(20)))
            {
                EditorWindow.GetWindow <AHSceneOverview>(true, "Asset Helper Scene Overview");
            }

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

            EditorGUILayout.Space();

            GUI.color = m_IntialGUIColor;

            //Show logo
            if (m_window && m_window.m_UIWideLogo)
            {
                GUILayout.Label(m_window.m_UIWideLogo);
            }

            //Only show the foldout if we actually have any manually excluded folders or types
            if (settings != null && settings.HasExcludes())
            {
                bShowExcludeFoldout = EditorGUILayout.Foldout(bShowExcludeFoldout, "Show manual excludes");
            }

            EditorGUILayout.EndVertical();
        }