Esempio n. 1
0
        public static TextureInfo CreateTextureInfo(string assetPath)
        {
            if (!EditorPath.IsTexture(assetPath))
            {
                return(null);
            }

            TextureInfo textureInfo = null;

            if (!_dictTexInfo.TryGetValue(assetPath, out textureInfo))
            {
                textureInfo = new TextureInfo();
                _dictTexInfo.Add(assetPath, textureInfo);
            }

            TextureImporter textureImport = AssetImporter.GetAtPath(assetPath) as TextureImporter;
            Texture         texture       = AssetDatabase.LoadAssetAtPath <Texture>(assetPath);

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

            textureInfo.Path                = textureImport.assetPath;
            textureInfo.ImportType          = textureImport.textureType;
            textureInfo.ImportShape         = textureImport.textureShape;
            textureInfo.ReadWriteEnable     = textureImport.isReadable;
            textureInfo.MipmapEnable        = textureImport.mipmapEnabled;
            textureInfo.WrapMode            = textureImport.wrapMode;
            textureInfo.FilterMode          = textureImport.filterMode;
            textureInfo.StandaloneFormat    = EditorTool.GetPlatformTextureSettings(textureImport, EditorConst.PlatformStandalone);
            textureInfo.AndroidFormat       = EditorTool.GetPlatformTextureSettings(textureImport, EditorConst.PlatformAndroid);
            textureInfo.IosFormat           = EditorTool.GetPlatformTextureSettings(textureImport, EditorConst.PlatformIos);
            textureInfo.StandaloneOverriden = EditorTool.IsTextureOverriden(textureImport, EditorConst.PlatformStandalone);
            textureInfo.AndroidOverriden    = EditorTool.IsTextureOverriden(textureImport, EditorConst.PlatformAndroid);
            textureInfo.IosOverriden        = EditorTool.IsTextureOverriden(textureImport, EditorConst.PlatformIos);
            textureInfo.StandaloneSize      = EditorTool.CalculateTextureSizeBytes(texture, textureInfo.StandaloneFormat);
            textureInfo.AndroidSize         = EditorTool.CalculateTextureSizeBytes(texture, textureInfo.AndroidFormat);
            textureInfo.IosSize             = EditorTool.CalculateTextureSizeBytes(texture, textureInfo.IosFormat);
            textureInfo.MemSize             = Mathf.Max(textureInfo.StandaloneSize, textureInfo.AndroidSize, textureInfo.IosSize);
            textureInfo.Width               = texture.width;
            textureInfo.Height              = texture.height;

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

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

            return(textureInfo);
        }
Esempio n. 2
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(
                EditorTool.CalculateTextureSizeBytes(texture, tInfo.AndroidFormat),
                EditorTool.CalculateTextureSizeBytes(texture, tInfo.IosFormat));

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

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

            return(tInfo);
        }
Esempio n. 3
0
        public static long CalcAssetSize(string assetPath, BundleType type)
        {
            assetPath = EditorPath.FormatAssetPath(assetPath);
            assetPath = EditorPath.NormalizePathSplash(assetPath);

            long ret = 0;

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

            BundleImportData assetImportData = BundleDataControl.Instance.GetPathImportData(assetPath);

            UnityEngine.Object[] assets = null;

            switch (type)
            {
            case BundleType.Texture:
                assets = AssetDatabase.LoadAllAssetsAtPath(assetPath);
                for (int i = 0; i < assets.Length; ++i)
                {
                    if (assets[i] is Texture)
                    {
                        ret += EditorTool.GetRuntimeMemorySize(assets[i]);
                    }
                }

                break;

            case BundleType.Material:
                string[] deps = AssetDepot.GetDependenciesCache(assetPath);
                for (int i = 0; i < deps.Length; ++i)
                {
                    if (EditorPath.IsTexture(deps[i]))
                    {
                        BundleImportData data = BundleDataControl.Instance.GetPathImportData(deps[i]);
                        if (assetImportData == null || data == null || assetImportData.Index < data.Index || data.SkipData)
                        {
                            ret += EditorTool.CalculateTextureSizeBytes(deps[i]);
                        }
                    }
                }
                ret += 512;
                break;

            case BundleType.FBX:
            case BundleType.Controller:
            case BundleType.Animation:
                assets = AssetDatabase.LoadAllAssetsAtPath(assetPath);
                List <UnityEngine.Object> list = AssetFilter.FilterObjectByType(assets, type, assetPath);
                for (int i = 0; i < list.Count; ++i)
                {
                    ret += EditorTool.GetRuntimeMemorySize(list[i]);
                }
                break;

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

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

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