Esempio n. 1
0
        private static string GetOutputPath(string pattern, DateTime time, BuildTarget target, string buildPath)
        {
            var fullPath = pattern;

            fullPath = fullPath.Replace(DateKey, time.ToString("yyyy-MM-dd"));
            fullPath = fullPath.Replace(TimeKey, time.ToString("HH-mm-ss"));
            fullPath = fullPath.Replace(BuildTargetKey, target.ToString());
            fullPath = fullPath.Replace(BuildDirKey, ReliablePath.GetDirectoryName(buildPath));

            fullPath = ReplaceKeySafe(fullPath, SvnRevisionKey, VersionControlUtils.GetSVNRevision, "svn revision");
            fullPath = ReplaceKeySafe(fullPath, GitShortHashKey, VersionControlUtils.GetGitShortCommitHash, "git commit short hash");
            fullPath = ReplaceKeySafe(fullPath, GitHashKey, VersionControlUtils.GetGitCommitHash, "git commit hash");

            var expandedResult = Environment.ExpandEnvironmentVariables(fullPath);

            return(expandedResult);
        }
Esempio n. 2
0
            public static string RichifyFileName(string path)
            {
                try
                {
                    var directory = ReliablePath.GetDirectoryName(path);
                    if (!string.IsNullOrEmpty(directory))
                    {
                        directory += '/';
                    }

                    return(directory + "<b>" + ReliablePath.GetFileName(path) + "</b>");
                }
                catch (System.Exception ex)
                {
                    Debug.LogError(string.Format("Error {0} for path {1}", ex, path));
                    return(path);
                }
            }
Esempio n. 3
0
        private void PostProcessBuild(BuildTarget target, string path, Func <Dictionary <string, long>, Dictionary <string, long> > assetsGetter)
        {
            toolOverheadTimer.Start();

            try
            {
                EditorUtility.DisplayProgressBar("Better Build Info", "Analyzing build...", 1.0f);

                List <AssetInfo>          infos = new List <AssetInfo>();
                Dictionary <string, long> scenesSizesFromLog = new Dictionary <string, long>();

                {
                    Dictionary <string, long> assetsFromLog = assetsGetter(scenesSizesFromLog);
                    infos = GetAssetsAndSizes(assetsUsedByScenes, assetsFromLog);
                }

                BuildInfoProcessorUtils.DiscoverDependenciesAndMissingAtlases(infos, assetsUsedByScenes, detailsCollector);

                if (detailsCollector != null)
                {
                    BuildInfoProcessorUtils.FinishCollectingDetails(infos, detailsCollector);
                }

                BuildArtifactsInfo artifactsInfo = null;
                try
                {
                    artifactsInfo = BuildArtifactsInfo.Create(target, path);
                }
                catch (Exception ex)
                {
                    Log.Warning("Unable to obtain build artifacts info: {0}", ex);
                }

                BuildInfoProcessorUtils.RefreshScenesInfo(scenesSizesFromLog, infos, artifactsInfo, processedScenes, scenesDetails, detailsCollector);

                if (artifactsInfo != null)
                {
                    BuildInfoProcessorUtils.RefreshModulesInfo(infos, artifactsInfo);
                }

                // sort infos based on paths (easier diffs)
                infos.Sort(BuildInfoProcessorUtils.PathComparer);

                if (artifactsInfo != null)
                {
                    BuildInfoProcessorUtils.RefreshOtherArtifacts(infos, artifactsInfo);
                }

                if (detailsCollector != null)
                {
                    EditorUtility.DisplayProgressBar("Better Build Info", "Analyzing build... (compressed sizes)", 1.0f);
                    BuildInfoProcessorUtils.FinishCalculatingCompressedSizes(infos, detailsCollector);
                    BuildInfoProcessorUtils.CalculateScriptReferences(infos, detailsCollector);
                }

                var settings = BuildInfoProcessorUtils.GetPlayerSettings(typeof(PlayerSettings))
                               .Concat(BuildInfoProcessorUtils.GetPlayerSettings(typeof(EditorUserBuildSettings)));

#if UNITY_ANDROID
                settings = settings.Concat(BuildInfoProcessorUtils.GetPlayerSettings(typeof(PlayerSettings.Android)));
#elif UNITY_IOS
                settings = settings.Concat(BuildInfoProcessorUtils.GetPlayerSettings(typeof(PlayerSettings.iOS)));
#endif

                var buildInfo = new BuildInfo()
                {
                    dateUTC      = DateTime.UtcNow.Ticks,
                    buildTarget  = target.ToString(),
                    projectPath  = Environment.CurrentDirectory.Replace('\\', '/'),
                    outputPath   = path,
                    unityVersion = Application.unityVersion,

                    buildTime    = buildTimer.ElapsedMilliseconds / 1000.0f,
                    overheadTime = toolOverheadTimer.ElapsedMilliseconds / 1000.0f,

                    assets               = infos,
                    scenes               = processedScenes.Distinct().ToList(),
                    buildSettings        = settings.GroupBy(x => x.name).OrderBy(x => x.Key).Select(x => x.FirstOrDefault()).ToList(),
                    environmentVariables = System.Environment.GetEnvironmentVariables().Cast <DictionaryEntry>().Select(x => new BuildSetting()
                    {
                        name  = x.Key.ToString(),
                        value = x.Value.ToString()
                    }).OrderBy(x => x.name).ToList(),
                };

                if (artifactsInfo != null)
                {
                    buildInfo.totalSize             = artifactsInfo.totalSize.uncompressed;
                    buildInfo.compressedSize        = artifactsInfo.totalSize.compressed;
                    buildInfo.streamingAssetsSize   = artifactsInfo.streamingAssetsSize;
                    buildInfo.runtimeSize           = artifactsInfo.runtimeSize.uncompressed;
                    buildInfo.compressedRuntimeSize = artifactsInfo.runtimeSize.compressed;
                }
                ;

                var serializer = new System.Xml.Serialization.XmlSerializer(typeof(BuildInfo));

                var outputPath = string.Empty;

                try
                {
                    outputPath = BuildInfoSettings.Instance.GetOutputPath(DateTime.Now, target, path);

                    var dirName = ReliablePath.GetDirectoryName(outputPath);
                    if (!string.IsNullOrEmpty(dirName) && !Directory.Exists(dirName))
                    {
                        Directory.CreateDirectory(dirName);
                    }

                    using (var writer = File.CreateText(outputPath))
                    {
                        serializer.Serialize(writer, buildInfo);
                    }

                    Log.Info("Generated report at: {0}", outputPath);

                    if (BuildInfoSettings.Instance.autoOpenReportAfterBuild)
                    {
                        BuildInfoSettings.ReportToOpen = outputPath;
                    }
                }
                catch (System.Exception ex)
                {
                    var tempPath = ReliablePath.GetTempPath() + "BBI_" + Guid.NewGuid().ToString() + ".bbi";
                    Log.Error("Error saving report at {0}, saving it temporarily at {1}. Copy it manually to a target location. Error details: {2}", outputPath, tempPath, ex);

                    using (var writer = new StreamWriter(tempPath))
                    {
                        serializer.Serialize(writer, buildInfo);
                    }
                }
            }
            catch (System.Exception ex)
            {
                Log.Error("Unexpected error: {0}", ex);
            }
            finally
            {
                if (!BuildInfoSettings.Instance.autoOpenReportAfterBuild)
                {
                    BuildInfoSettings.ReportToOpen = null;
                }

                EditorUtility.ClearProgressBar();
            }
        }
        private void ProjectWindowItemCallback(string guid, Rect selectionRect)
        {
            if (!m_skin.loaded)
            {
                return;
            }

            if (m_assetsDirectoriesInfo.IsEmpty)
            {
                return;
            }

            var path = AssetDatabase.GUIDToAssetPath(guid);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            int      usedCount, assetsCount, editorAssetsCount;
            FileSize size;

            if (Directory.Exists(path))
            {
                path = path.TrimEnd('/', '\\');

                if (m_assetsDirectoriesInfo.GetDirectoryInfo(path, out assetsCount, out usedCount, out editorAssetsCount, out size))
                {
                    Color      backgroundColor;
                    GUIContent content;

                    if (assetsCount == 0)
                    {
                        if (editorAssetsCount == 0)
                        {
                            backgroundColor = m_skin.overlayUnusedColor;
                            content         = m_skin.overlayEmptyContent;
                        }
                        else
                        {
                            backgroundColor = m_skin.overlaySpecialColor;
                            content         = m_skin.overlayHasSpecialContent;
                        }
                    }
                    else
                    {
                        backgroundColor = Color.Lerp(m_skin.overlayUnusedColor, m_skin.overlayUsedColor, (float)usedCount / assetsCount);
                        content         = new GUIContent(string.Format("{0}/{1} | {2}", usedCount, assetsCount, size));
                    }

                    using (GUIHelpers.BackgroundColor(backgroundColor))
                    {
                        GUIHelpers.StaticLabel(selectionRect, content, m_skin.projectOverlayMask, false);
                    }
                }
                else if (AssetsDirectoriesInfo.IsInSpecialEditorDirectory(path))
                {
                    using (GUIHelpers.BackgroundColor(m_skin.overlaySpecialColor))
                    {
                        GUIHelpers.StaticLabel(selectionRect, m_skin.overlaySpecialContent, m_skin.projectOverlayMask, false);
                    }
                }
            }
            else if (m_assetsByPath != null)
            {
                AssetEntry asset;
                if (m_assetsByPath.TryGetValue(path, out asset))
                {
                    using (GUIHelpers.BackgroundColor(m_skin.overlayUsedColor))
                    {
                        GUIHelpers.StaticLabel(selectionRect, asset.sizeContent, m_skin.projectOverlayMask, false);
                    }
                }
                else
                {
                    var directory = ReliablePath.GetDirectoryName(path);
                    if (m_assetsDirectoriesInfo.GetDirectoryInfo(directory, out assetsCount, out usedCount, out editorAssetsCount, out size))
                    {
                        using (GUIHelpers.BackgroundColor(m_skin.overlayUnusedColor))
                        {
                            GUIHelpers.StaticLabel(selectionRect, m_skin.overlayUnusedContent, m_skin.projectOverlayMask, false);
                        }
                    }
                    else if (AssetsDirectoriesInfo.IsInSpecialEditorDirectory(path))
                    {
                        using (GUIHelpers.BackgroundColor(m_skin.overlaySpecialColor))
                        {
                            GUIHelpers.StaticLabel(selectionRect, m_skin.overlaySpecialContent, m_skin.projectOverlayMask, false);
                        }
                    }
                }
            }
        }