コード例 #1
0
ファイル: TextureInfo.cs プロジェクト: FTD2012/AssetViewer
        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);
        }