Example #1
0
        void AddToSize(string buildSizeName, long sizeToAdd)
        {
            if (sizeToAdd == 0)
            {
                return;
            }

            BuildReportTool.SizePart buildSize = BuildSizes.FirstOrDefault(part => part.Name == buildSizeName);

            if (buildSize != null)
            {
                //Debug.LogFormat("{0} size before: {1}", buildSizeName, buildSize.DerivedSize);

                AddToSize(buildSize, sizeToAdd);

                //Debug.LogFormat("{0} size after: {1}", buildSizeName, buildSize.DerivedSize);
            }
        }
Example #2
0
        void AddToTotalSize(long sizeToAdd)
        {
            if (sizeToAdd == 0)
            {
                return;
            }

            BuildReportTool.SizePart buildSize = BuildSizes.FirstOrDefault(part => part.IsTotal);

            if (buildSize != null)
            {
                //Debug.LogFormat("total size before: {0}", buildSize.DerivedSize);

                AddToSize(buildSize, sizeToAdd);

                UsedTotalSize = buildSize.Size;

                //Debug.LogFormat("total size after: {0}", buildSize.DerivedSize);
            }
        }
Example #3
0
        void ChangeTotalSize(double newSize)
        {
            if (System.Math.Abs(newSize) < 0.01)
            {
                // disallow zero total size
                return;
            }

            BuildReportTool.SizePart totalSize = BuildSizes.FirstOrDefault(part => part.IsTotal);

            if (totalSize != null)
            {
                //Debug.LogFormat("total size before: {0}", totalSize.DerivedSize);

                totalSize.DerivedSize = newSize;
                totalSize.Size        = BuildReportTool.Util.GetBytesReadable(totalSize.DerivedSize);

                UsedTotalSize = totalSize.Size;

                //Debug.LogFormat("total size after: {0}", totalSize.DerivedSize);
            }
        }
Example #4
0
        /// <summary>
        /// This is called right after generating a build report.
        /// </summary>
        public void FixReport()
        {
#if UNITY_5_2_AND_LESSER
            // this bug has already been fixed since Unity 5.2.1
            // so we only execute this for Unity 5.2.0 and below

            if (!DldUtil.UnityVersion.IsUnityVersionAtLeast(5, 2, 1))
            {
                // --------------------------------------------------------------------------------
                // fix imported sizes of Resources files

                for (int n = 0; n < UsedAssets.All.Length; ++n)
                {
                    if (BuildReportTool.Util.IsFileInAPath(UsedAssets.All[n].Name, "/Resources/"))
                    {
                        UsedAssets.All[n].ImportedSizeBytes = BRT_LibCacheUtil.GetImportedFileSize(UsedAssets.All[n].Name);
                        UsedAssets.All[n].ImportedSize      =
                            BuildReportTool.Util.GetBytesReadable(UsedAssets.All[n].ImportedSizeBytes);

                        UsedAssets.All[n].RawSizeBytes = UsedAssets.All[n].ImportedSizeBytes;
                        UsedAssets.All[n].RawSize      = UsedAssets.All[n].ImportedSize;

                        UsedAssets.All[n].DerivedSize = 0;
                        UsedAssets.All[n].Percentage  = -1;
                    }
                }

                UsedAssets.ResortDefault(BuildReportTool.Options.NumberOfTopLargestUsedAssetsToShow);

                // --------------------------------------------------------------------------------
                // recalculate percentages

                var totalSizePart = BuildSizes.FirstOrDefault(part => part.IsTotal);
                if (totalSizePart != null && System.Math.Abs(totalSizePart.DerivedSize) < 0.01)
                {
                    var totalSize = GetTotalSize();
                    ChangeTotalSize(totalSize);
                }

                // add textures, meshes, sounds, and animations that are in resources folder to the build size
                // since they are not included anymore in Unity 5

                var resourcesTextureSizeSum =
                    GetSizeSumForUsedAssets("/Resources/", BuildReportTool.Util.IsTextureFile);
                AddToSize("Textures", resourcesTextureSizeSum);

                var resourcesMeshSizeSum = GetSizeSumForUsedAssets("/Resources/", BuildReportTool.Util.IsMeshFile);
                AddToSize("Meshes", resourcesMeshSizeSum);

                var resourcesSoundsSizeSum = GetSizeSumForUsedAssets("/Resources/", BuildReportTool.Util.IsSoundFile);
                AddToSize("Sounds", resourcesSoundsSizeSum);

                var resourcesAnimationsSizeSum =
                    GetSizeSumForUsedAssets("/Resources/", BuildReportTool.Util.IsAnimationFile);
                AddToSize("Animations", resourcesAnimationsSizeSum);

                AddToTotalSize(resourcesTextureSizeSum);
                AddToTotalSize(resourcesMeshSizeSum);
                AddToTotalSize(resourcesSoundsSizeSum);
                AddToTotalSize(resourcesAnimationsSizeSum);

                RecalculatePercentages();

                // sort sizes again since we modified them
                SortSizes();
            }
#else
            // newer versions of Unity (2017 and up)
            // has a bug where the total size reported is actually the final build's size,
            // instead of the total of the sizes indicated in the build log.
            // so we recalculate the percentages.
            // this is most noticeable when the percentages
            // indicated don't really total up to 100, not even close to 90
            RecalculatePercentages();

            // sort sizes again since we modified them
            SortSizes();
#endif
        }