Example #1
0
        internal void AddPrefabs(List <string> usedPrefabsInScenes)
        {
            foreach (string path in usedPrefabsInScenes)
            {
                EditorUtility.DisplayProgressBar(
                    "Adding prefabs",
                    "Analyzing scenes to get prefabs",
                    (float)usedPrefabsInScenes.IndexOf(path) / (float)usedPrefabsInScenes.Count);
                //Early out
                if (m_BuildSizeList.Exists(val => val.Path == path))
                {
                    continue;
                }

                UnityEngine.Object obj = UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));

                if (obj != null)
                {
                    BuildReportAsset newAsset = new BuildReportAsset();

                    newAsset.SetAssetInfo(obj, path);
                    newAsset.SetSize(0.0f, "--");
                    m_BuildSizeList.Add(newAsset);
                }
                else
                {
                    Debug.LogWarning(path + " is not a valid asset");
                }
            }

            EditorUtility.ClearProgressBar();
        }
Example #2
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>();

            splash.Add(UnityEditor.PlayerSettings.xboxSplashScreen);

            //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);
                }
                AssetHunterHelper.UnloadUnused();
            }

            EditorUtility.ClearProgressBar();
        }
Example #3
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>();

            splash.Add(UnityEditor.PlayerSettings.xboxSplashScreen);

            //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);
            }

            //TODO And the icons from METRO as well

#if !UNITY_5
            List <string> targetResourcePaths = new List <string>();
            targetResourcePaths.Add(UnityEditor.PlayerSettings.Metro.certificatePath);
            targetResourcePaths.AddRange(getWin8AssetPaths());

            //Loop the paths
            foreach (string path in targetResourcePaths)
            {
                //Early out if it already exist
                if (string.IsNullOrEmpty(path) || m_BuildSizeList.Exists(val => val.Path == path))
                {
                    continue;
                }

                UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));

                if (obj != null)
                {
                    BuildReportAsset newAsset = new BuildReportAsset();
                    newAsset.SetAssetInfo(AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object)), path);
                    newAsset.SetSize(0.0f, "--");
                    m_BuildSizeList.Add(newAsset);
                }
            }
#endif

            //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);
                }
                AssetHunterHelper.UnloadUnused();
            }

            EditorUtility.ClearProgressBar();
        }
Example #4
0
 internal void AddAsset(BuildReportAsset asset)
 {
     m_BuildSizeList.Add(asset);
 }
        internal static AssetBuildReport AnalyzeBuildLog()
        {
            AssetBuildReport buildReport        = new AssetBuildReport();
            string           UnityEditorLogfile = GetLogFolderPath();

            try
            {
                // Have to use FileStream to get around sharing violations!
                FileStream   FS = new FileStream(UnityEditorLogfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                StreamReader SR = new StreamReader(FS);

                string line;
                int    linesRead = 0;
                int    lineIndex = 0;

                while (!SR.EndOfStream)
                {
                    line = SR.ReadLine();
                    linesRead++;
                    if ((line).Contains("Mono dependencies included in the build"))
                    {
                        lineIndex = linesRead;
                    }
                }

                FS.Position = 0;
                SR.DiscardBufferedData();

                //Start reading from log at the right line
                for (int i = 0; i < lineIndex - 1; i++)
                {
                    SR.ReadLine();
                }

                while (!SR.EndOfStream && !(line = SR.ReadLine()).Contains("Mono dependencies included in the build"))
                {
                    ;
                }
                while (!SR.EndOfStream && (line = SR.ReadLine()) != "")
                {
                    int stringLength = line.Length;
                    int startIndex   = line.LastIndexOf(" ");
                    buildReport.AddDependency(line.Substring(startIndex, stringLength - startIndex));
                }
                while (!SR.EndOfStream && !(line = SR.ReadLine()).Contains("Used Assets,"))
                {
                    ;
                }
                bool assetAnalysisComplete = false;
                while (!SR.EndOfStream && !assetAnalysisComplete)
                {
                    string curLine = SR.ReadLine();

                    if (curLine == "" || curLine.Contains("System memory in use before") || !curLine.Contains("% "))
                    {
                        assetAnalysisComplete = true;
                    }
                    else
                    {
                        if (!curLine.Contains("Built-in"))
                        {
                            string str = curLine.Substring(curLine.IndexOf("% ") + 2);
                            if (str.StartsWith("Assets/"))
                            {
                                EditorUtility.DisplayProgressBar(
                                    "Parsing build log",
                                    "Parsing build log to retrieve info",
                                    (float)SR.BaseStream.Position / (float)SR.BaseStream.Length);

                                UnityEngine.Object obj = UnityEditor.AssetDatabase.LoadAssetAtPath(str, typeof(UnityEngine.Object));

                                if (obj != null)
                                {
                                    BuildReportAsset asset = new BuildReportAsset();

                                    asset.SetAssetInfo(obj, str);
                                    //Split on whitespace
                                    string[] splitstring = curLine.Split(null);
                                    asset.SetSize(float.Parse(splitstring[1]), splitstring[2]);
                                    buildReport.AddAsset(asset);
                                }
                                else
                                {
                                    Debug.LogWarning(str + " is not a valid asset");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception E)
            {
                Debug.LogError("Error: " + E);
            }
            EditorUtility.ClearProgressBar();

            //TODO FIND AND ADD ICONS FOR BUILDTARGETS AND CERTIFICATES AND WHATEVER ELSE
            return(buildReport);
        }