public static APMovieTexture GetAPMovieTextureFromAssetGuid(string guid) { MovieImporter movieImporter = GetAssetImporterFromAssetGuid <MovieImporter>(guid); // if texture is render texture or others, tImporter will to set to null. // if (movieImporter == null) { return(null); } string path = AssetDatabase.GUIDToAssetPath(guid); if (string.IsNullOrEmpty(path)) { return(null); } var texture = AssetDatabase.LoadAssetAtPath(path, typeof(MovieTexture)) as MovieTexture; if (texture == null) { return(null); } APMovieTexture apMovieTexture = new APMovieTexture(); apMovieTexture.Icon = GetIconID(path); apMovieTexture.Size = TextureUtillity.GetStorageMemorySize(texture); double approx = (GetVideoBitrateForQuality(movieImporter.quality) + GetAudioBitrateForQuality(movieImporter.quality)) * movieImporter.duration / 8; apMovieTexture.Approx = approx; apMovieTexture.Name = Utility.GetFileName(path); apMovieTexture.Path = path; apMovieTexture.Hash = Utility.GetFileMd5(path); apMovieTexture.Quality = movieImporter.quality; apMovieTexture.FileSize = Utility.GetFileSize(path); TimeSpan duration = TimeSpan.FromSeconds(texture.duration); apMovieTexture.Duration = Utility.GetTimeDurationString(duration); apMovieTexture.Id = guid; UnloadAsset(texture); return(apMovieTexture); }
public static APTexture GetAPTextureFromAssetGuid(string guid) { string path = AssetDatabase.GUIDToAssetPath(guid); if (string.IsNullOrEmpty(path)) { return(null); } var texture = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object)); if (texture == null || texture is MovieTexture) { return(null); } APTexture apTexture = new APTexture(); apTexture.Icon = GetIconID(path); if (texture is RenderTexture) { var renderTexture = texture as RenderTexture; apTexture.StorageSize = TextureUtillity.GetStorageMemorySize(renderTexture); #if UNITY_5 && !UNITY_5_6 apTexture.RuntimeSize = Profiler.GetRuntimeMemorySize(renderTexture); #else apTexture.RuntimeSize = Profiler.GetRuntimeMemorySizeLong(renderTexture); #endif apTexture.Width = renderTexture.width; apTexture.Height = renderTexture.height; apTexture.TextureType = "Render"; apTexture.Path = path; apTexture.Hash = Utility.GetFileMd5(path); apTexture.Name = Utility.GetFileName(path); apTexture.FileSize = Utility.GetFileSize(path); apTexture.Id = guid; UnloadAsset(texture); return(apTexture); } TextureImporter tImporter = GetAssetImporterFromAssetGuid <TextureImporter>(guid); if (tImporter == null) { return(null); } var tex = texture as Texture; int maxTextureSize = tImporter.maxTextureSize; #if UNITY_5_5_OR_NEWER TextureImporterFormat importerFormat; TextureImporterCompression importerCompression = tImporter.textureCompression; #else TextureImporterFormat importerFormat = tImporter.textureFormat; #endif int compressQuality = tImporter.compressionQuality; // Get texture settings for different platform // tImporter.GetPlatformTextureSettings(Utility.BuildTargetToPlatform(EditorUserBuildSettings.activeBuildTarget), out maxTextureSize, out importerFormat, out compressQuality); apTexture.StorageSize = TextureUtillity.GetStorageMemorySize(tex); apTexture.RuntimeSize = TextureUtillity.GetRuntimeMemorySize(tex); apTexture.Name = Utility.GetFileName(path); apTexture.ReadWrite = tImporter.isReadable; #if UNITY_5_5_OR_NEWER if ((int)importerFormat > 0) { apTexture.TextureFormat = importerFormat.ToString(); } else { apTexture.TextureFormat = "Auto"; } #else apTexture.TextureFormat = importerFormat.ToString(); #endif apTexture.TextureType = tImporter.textureType.ToString(); apTexture.Path = path; apTexture.Hash = Utility.GetFileMd5(path); apTexture.MipMap = tImporter.mipmapEnabled; apTexture.MaxSize = maxTextureSize; apTexture.Width = tex.width; apTexture.Height = tex.height; apTexture.FileSize = Utility.GetFileSize(path); int widthInPixel = 0; int heightInPixel = 0; TextureUtillity.GetImageSize(texture as Texture2D, out widthInPixel, out heightInPixel); apTexture.WidthInPixel = widthInPixel; apTexture.HeightInPixel = heightInPixel; apTexture.Id = guid; UnloadAsset(texture); return(apTexture); }