Ejemplo n.º 1
0
        public static TextureInfo CreateTextureInfo(string assetPath)
        {
            TextureInfo tInfo = null;

            if (!m_dictTexInfo.TryGetValue(assetPath, out tInfo))
            {
                tInfo = new TextureInfo();
                m_dictTexInfo.Add(assetPath, tInfo);
            }
            TextureImporter tImport = AssetImporter.GetAtPath(assetPath) as TextureImporter;
            Texture         texture = AssetDatabase.LoadAssetAtPath <Texture>(assetPath);

            if (tImport == null || texture == null)
            {
                return(null);
            }

            tInfo.Path            = tImport.assetPath;
            tInfo.ImportType      = tImport.textureType;
            tInfo.ImportShape     = tImport.textureShape;
            tInfo.ReadWriteEnable = tImport.isReadable;
            tInfo.MipmapEnable    = tImport.mipmapEnabled;
            tInfo.WrapMode        = tImport.wrapMode;
            tInfo.FilterMode      = tImport.filterMode;
            TextureImporterPlatformSettings settingAndroid = tImport.GetPlatformTextureSettings(EditorConst.PlatformAndroid);

            tInfo.AndroidFormat = settingAndroid.format;
            TextureImporterPlatformSettings settingIos = tImport.GetPlatformTextureSettings(EditorConst.PlatformIos);

            tInfo.IosFormat = settingIos.format;
            tInfo.MemSize   = Mathf.Max(
                EditorCommon.CalculateTextureSizeBytes(texture, tInfo.AndroidFormat),
                EditorCommon.CalculateTextureSizeBytes(texture, tInfo.IosFormat));

            if (Selection.activeObject != texture)
            {
                Resources.UnloadAsset(texture);
            }

            if (++m_loadCount % 256 == 0)
            {
                Resources.UnloadUnusedAssets();
            }

            return(tInfo);
        }
Ejemplo n.º 2
0
        public static long CalcPathFileSize(string path, BundleType type)
        {
            path = PathConfig.FormatAssetPath(path);
            path = PathConfig.NormalizePathSplash(path);

            long ret = 0;

            if (m_pathFileSize.TryGetValue(path, out ret))
            {
                return(ret);
            }

            UnityEngine.Object[] objs = null;

            switch (type)
            {
            case BundleType.Texture:
                objs = AssetDatabase.LoadAllAssetsAtPath(path);
                for (int i = 0; i < objs.Length; ++i)
                {
                    if (objs[i] is Texture)
                    {
#pragma warning disable 0618
                        ret += Profiler.GetRuntimeMemorySize(objs[i]);
#pragma warning restore 0618
                    }
                }
                ret /= 4;

                break;

            case BundleType.Material:
                string[] deps = AssetDepend.GetDependenciesCache(path);
                for (int i = 0; i < deps.Length; ++i)
                {
                    if (PathConfig.IsTexture(deps[i]))
                    {
                        BundleImportData data = m_dataControl.GetPathSelectData(deps[i]);
                        if (data == null || data.SkipData)
                        {
                            ret += EditorCommon.CalculateTextureSizeBytes(deps[i]) / 4;
                        }
                    }
                }
                ret += 512;
                break;

            case BundleType.FBX:
            case BundleType.Controller:
            case BundleType.Animation:
                objs = AssetDatabase.LoadAllAssetsAtPath(path);
                List <UnityEngine.Object> list = new List <Object>();
                BuildHelper.FilterObjectByType(objs, list, type, path);
                for (int i = 0; i < list.Count; ++i)
                {
#pragma warning disable 0618
                    ret += Profiler.GetRuntimeMemorySize(list[i]);
#pragma warning restore 0618
                }
                ret /= 6;
                break;

            default:
                FileInfo fileInfo = new FileInfo(path);
                ret = fileInfo.Length;
                break;
            }

            if (objs != null)
            {
                _ProcessClear();
            }

            for (int i = 0; objs != null && i < objs.Length; ++i)
            {
                if ((!(objs[i] is GameObject)) && (!(objs[i] is Component)))
                {
                    Resources.UnloadAsset(objs[i]);
                }
            }

            m_pathFileSize.Add(path, ret);
            return(ret);
        }