Exemplo n.º 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();
        }
Exemplo n.º 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>();

#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.º 3
0
        private void showBuildAssetInfoUI()
        {
            EditorGUILayout.BeginVertical();
            EditorGUI.indentLevel = 0;

            GUILayout.Label("--------------------------------LEGEND--------------------------------");

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label(m_UISceneSelect, GUILayout.Width(25), GUILayout.Height(25));
            GUILayout.Label("Select all scenes that reference this asset: ", GUILayout.Width(300));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label(m_UIFolderSelect, GUILayout.Width(25), GUILayout.Height(25));
            GUILayout.Label("Locate asset in project view: ", GUILayout.Width(300));
            EditorGUILayout.EndHorizontal();

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

            GUILayout.Space(15);
            EditorGUILayout.LabelField("Assets included in build", EditorStyles.boldLabel);

            EditorGUI.indentLevel = 1;
            for (int i = 0; i < m_BuildLog.AssetCount; i++)
            {
                if (m_usedTypeDict[m_BuildLog.GetAssetAtIndex(i).Type] == true)
                {
                    BuildReportAsset asset = m_BuildLog.GetAssetAtIndex(i);
                    EditorGUILayout.BeginHorizontal();

                    GUILayout.Space(10);
                    if (GUILayout.Button(m_UISceneSelect, GUIStyle.none, GUILayout.Width(btnImageSize), GUILayout.Height(btnImageSize)))
                    {
                        //Toggle if we should show scene dependency
                        asset.ToggleShowSceneDependency();

                        if (m_assetSceneDependencies.ContainsKey(asset.Path))
                        {
                            List <string> scenes = m_assetSceneDependencies[asset.Path];

                            UnityEngine.Object[] selectedObjects = new UnityEngine.Object[scenes.Count];

                            for (int j = 0; j < scenes.Count; j++)
                            {
                                selectedObjects[j] = AssetDatabase.LoadAssetAtPath(scenes[j], typeof(UnityEngine.Object));
                            }

                            Selection.activeObject = null;
                            Selection.objects      = selectedObjects;
                            asset.SetSceneDependencies(selectedObjects);
                        }
                    }
                    GUILayout.Space(10);

                    if (GUILayout.Button(m_UIFolderSelect, GUIStyle.none, GUILayout.Width(btnImageSize), GUILayout.Height(btnImageSize)))
                    {
                        Selection.activeObject = AssetDatabase.LoadAssetAtPath(asset.Path, asset.Type.SystemType);
                        EditorGUIUtility.PingObject(Selection.activeObject);
                    }

                    EditorGUILayout.LabelField(asset.Name, GUILayout.Width(350));

                    EditorGUILayout.LabelField(asset.SizeString, GUILayout.Width(75));
                    GUILayout.Label(EditorGUIUtility.ObjectContent(null, asset.Type.SystemType).image, GUILayout.Width(btnImageSize), GUILayout.Height(btnImageSize));
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();

                    if (asset.ShouldShowDependencies)
                    {
                        EditorGUI.indentLevel = 2;
                        //If the asset is actually reference in scenes
                        if (asset.GetSceneDependencies() != null && asset.GetSceneDependencies().Length >= 1)
                        {
                            asset.FoldOut = EditorGUILayout.Foldout(asset.FoldOut, "View scenes with dependency");
                            if (asset.FoldOut)
                            {
                                foreach (string sceneGUID in asset.GetSceneDependencies())
                                {
                                    if (sceneGUID != null)
                                    {
                                        string path = AssetDatabase.GUIDToAssetPath(sceneGUID);

                                        // Load the asset into reference
                                        UnityEngine.Object sceneObj = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));

                                        EditorGUILayout.ObjectField(sceneObj, typeof(UnityEngine.Object), false);
                                    }
                                }
                            }
                        }
                        //If no scenes reference the asset
                        else
                        {
                            Color initialColor = GUI.color;
                            GUI.color = AHHelper.AH_RED;
                            EditorGUILayout.LabelField("Asset not referenced in any scene, most likely a part of the \"resources\" foldes", EditorStyles.whiteLabel);
                            GUI.color = initialColor;
                        }
                    }
                    EditorGUI.indentLevel = 1;
                }
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();
        }
Exemplo n.º 4
0
        internal static AHBuildReport AnalyzeBuildLog()
        {
            AHBuildReport buildReport        = new AHBuildReport();
            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/", true, null))
                            {
                                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);
                                    buildReport.AddAsset(asset);
                                }
                                else
                                {
                                    Debug.Log(str + " does not seem to be a valid asset (Maybe its a \"terrain folder\"");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception E)
            {
                Debug.LogError("Error: " + E);
            }
            EditorUtility.ClearProgressBar();

            return(buildReport);
        }
Exemplo n.º 5
0
 internal void AddAsset(BuildReportAsset asset)
 {
     m_BuildSizeList.Add(asset);
 }