void OnPreprocessTexture() { //自动设置类型; VideoClipImporter clipImporter = (VideoClipImporter)assetImporter; clipImporter.keepAlpha = true; }
public static APMovieTexture GetAPMovieTextureFromAssetGuid(string guid) { #if UNITY_5_6_OR_NEWER VideoClipImporter movieImporter = GetAssetImporterFromAssetGuid <VideoClipImporter>(guid); #else MovieImporter movieImporter = GetAssetImporterFromAssetGuid <MovieImporter>(guid); #endif Debug.Log(movieImporter); // 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); } #if UNITY_5_6_OR_NEWER var texture = AssetDatabase.LoadAssetAtPath(path, typeof(VideoClip)) as VideoClip; #else var texture = AssetDatabase.LoadAssetAtPath(path, typeof(MovieTexture)) as MovieTexture; #endif Debug.Log(texture); if (texture == null) { return(null); } APMovieTexture apMovieTexture = new APMovieTexture(); apMovieTexture.Icon = GetIconID(path); #if UNITY_5_6_OR_NEWER apMovieTexture.Size = (long)movieImporter.outputFileSize; double approx = 0; #else apMovieTexture.Size = TextureUtillity.GetStorageMemorySize(texture); double approx = (GetVideoBitrateForQuality(movieImporter.quality) + GetAudioBitrateForQuality(movieImporter.quality)) * movieImporter.duration / 8; #endif 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); #if UNITY_5_6_OR_NEWER TimeSpan duration = TimeSpan.FromSeconds(texture.length); #else TimeSpan duration = TimeSpan.FromSeconds(texture.duration); #endif apMovieTexture.Duration = Utility.GetTimeDurationString(duration); apMovieTexture.Id = guid; UnloadAsset(texture); return(apMovieTexture); }
/// <summary> /// Grabs the data from the clip and serializes it into objects /// </summary> public void Initialize() { #if UNITY_EDITOR importer = (VideoClipImporter)AssetImporter.GetAtPath(clip.originalPath); clipEventData = importer.userData; GetVideoClipEvents(); #endif IsDirty = false; }
private static void OverwriteImportSettings(VideoClipImporter target, VideoClipImporter reference) { target.defaultTargetSettings = reference.defaultTargetSettings; target.deinterlaceMode = reference.deinterlaceMode; target.flipHorizontal = reference.flipHorizontal; target.flipVertical = reference.flipVertical; target.importAudio = reference.importAudio; target.keepAlpha = reference.keepAlpha; #if !UNITY_2019_3_OR_NEWER target.linearColor = reference.linearColor; target.quality = reference.quality; target.useLegacyImporter = reference.useLegacyImporter; #endif foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups) { var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g, BuildTargetUtility.PlatformNameType.VideoClipImporter); try { var setting = reference.GetTargetSettings(platformName); if (setting != null) { target.SetTargetSettings(platformName, setting); } else { target.ClearTargetSettings(platformName); } } catch (Exception e) { LogUtility.Logger.LogWarning("VideoClipImporter", $"Failed to set override setting for platform {platformName}: file :{target.assetPath} \\nreason:{e.Message}"); } } /* read only */ /* * importer.frameCount * importer.frameRate * importer.isPlayingPreview * importer.outputFileSize * importer.sourceAudioTrackCount * importer.sourceFileSize * importer.sourceHasAlpha * importer.pixelAspectRatioDenominator * importer.pixelAspectRatioNumerator */ }
public void OnBeforeSerialize() { if (videoClip == null) { return; } VideoClipImporter importer = (VideoClipImporter)AssetImporter.GetAtPath(videoClip.originalPath); userData = importer.userData; bakedMethods = new VideoClipBakedMethods(videoClip, userData); if (calllingPrefab != null) { bakedMethods.AssignEvents(calllingPrefab.GetComponentsInChildren <Component>()); } }
private void OverwriteImportSettings(VideoClipImporter importer) { var reference = referenceImporter as VideoClipImporter; UnityEngine.Assertions.Assert.IsNotNull(reference); /* * defaultTargetSettings Default values for the platform-specific import settings. * deinterlaceMode Images are deinterlaced during transcode. This tells the importer how to interpret fields in the source, if any. * flipHorizontal Apply a horizontal flip during import. * flipVertical Apply a vertical flip during import. * frameCount Number of frames in the clip. * frameRate Frame rate of the clip. * importAudio Import audio tracks from source file. * isPlayingPreview Whether the preview is currently playing. * keepAlpha Whether to keep the alpha from the source into the transcoded clip. * linearColor Used in legacy import mode. Same as MovieImport.linearTexture. * outputFileSize Size in bytes of the file once imported. * quality Used in legacy import mode. Same as MovieImport.quality. * sourceAudioTrackCount Number of audio tracks in the source file. * sourceFileSize Size in bytes of the file before importing. * sourceHasAlpha True if the source file has a channel for per-pixel transparency. * useLegacyImporter Whether to import a MovieTexture (legacy) or a VideoClip. */ importer.defaultTargetSettings = reference.defaultTargetSettings; importer.deinterlaceMode = reference.deinterlaceMode; importer.flipHorizontal = reference.flipHorizontal; importer.flipVertical = reference.flipVertical; importer.importAudio = reference.importAudio; importer.keepAlpha = reference.keepAlpha; importer.linearColor = reference.linearColor; importer.quality = reference.quality; importer.useLegacyImporter = reference.useLegacyImporter; #if UNITY2017_2_OR_NEWER importer.pixelAspectRatioDenominator = reference.pixelAspectRatioDenominator; importer.pixelAspectRatioNumerator = reference.pixelAspectRatioNumerator; #endif foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups) { var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g, BuildTargetUtility.PlatformNameType.VideoClipImporter); try { var setting = reference.GetTargetSettings(platformName); if (setting != null) { importer.SetTargetSettings(platformName, setting); } else { importer.ClearTargetSettings(platformName); } } catch (Exception e) { LogUtility.Logger.LogWarning("VideoClipImporter", string.Format("Failed to set override setting for platform {0}: file :{1} \\nreason:{2}", platformName, importer.assetPath, e.Message)); } } /* read only */ /* * importer.frameCount * importer.frameRate * importer.isPlayingPreview * importer.outputFileSize * importer.sourceAudioTrackCount * importer.sourceFileSize * importer.sourceHasAlpha */ }
public bool IsEqual(VideoClipImporter target) { VideoClipImporter reference = referenceImporter as VideoClipImporter; UnityEngine.Assertions.Assert.IsNotNull(reference); if (!IsEqual(target.defaultTargetSettings, reference.defaultTargetSettings)) { return(false); } /* read only properties. ImportSettingConfigurator will not use these properties for diff. */ /* * importer.frameCount * importer.frameRate * importer.isPlayingPreview * importer.outputFileSize * importer.sourceAudioTrackCount * importer.sourceFileSize * importer.sourceHasAlpha */ if (target.deinterlaceMode != reference.deinterlaceMode) { return(false); } if (target.flipHorizontal != reference.flipHorizontal) { return(false); } if (target.flipVertical != reference.flipVertical) { return(false); } if (target.importAudio != reference.importAudio) { return(false); } if (target.keepAlpha != reference.keepAlpha) { return(false); } if (target.linearColor != reference.linearColor) { return(false); } if (target.quality != reference.quality) { return(false); } if (target.useLegacyImporter != reference.useLegacyImporter) { return(false); } #if UNITY2017_2_OR_NEWER if (target.pixelAspectRatioDenominator != reference.pixelAspectRatioDenominator) { return(false); } if (target.pixelAspectRatioNumerator != reference.pixelAspectRatioNumerator) { return(false); } #endif foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups) { var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g, BuildTargetUtility.PlatformNameType.VideoClipImporter); try { var r = reference.GetTargetSettings(platformName); var t = target.GetTargetSettings(platformName); if (!IsEqual(r, t)) { return(false); } } catch (Exception e) { LogUtility.Logger.LogWarning("VideoClipImporter", string.Format("Failed to set override setting for platform {0}: file :{1} \\nreason:{2}", platformName, target.assetPath, e.Message)); } } return(true); }
public bool IsEqual(VideoClipImporter target, VideoClipImporter reference) { if (!CompareVideoImporterTargetSettings(target.defaultTargetSettings, reference.defaultTargetSettings)) { return(false); } /* read only properties. ImportSettingConfigurator will not use these properties for diff. */ /* * importer.frameCount * importer.frameRate * importer.isPlayingPreview * importer.outputFileSize * importer.sourceAudioTrackCount * importer.sourceFileSize * importer.sourceHasAlpha */ if (target.deinterlaceMode != reference.deinterlaceMode) { return(false); } if (target.flipHorizontal != reference.flipHorizontal) { return(false); } if (target.flipVertical != reference.flipVertical) { return(false); } if (target.importAudio != reference.importAudio) { return(false); } if (target.keepAlpha != reference.keepAlpha) { return(false); } if (target.linearColor != reference.linearColor) { return(false); } if (target.quality != reference.quality) { return(false); } if (target.useLegacyImporter != reference.useLegacyImporter) { return(false); } #if UNITY_2017_2_OR_NEWER if (target.pixelAspectRatioDenominator != reference.pixelAspectRatioDenominator) { return(false); } if (target.pixelAspectRatioNumerator != reference.pixelAspectRatioNumerator) { return(false); } #endif foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups) { var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g, BuildTargetUtility.PlatformNameType.VideoClipImporter); try { var r = reference.GetTargetSettings(platformName); var t = target.GetTargetSettings(platformName); // if both targets are null - keep going if (r == null && t == null) { continue; } if (r == null || t == null) { return(false); } if (!CompareVideoImporterTargetSettings(r, t)) { return(false); } } catch (Exception e) { LogUtility.Logger.LogError("VideoClipImporter", string.Format("Failed to test equality setting for {0}: file :{1} type:{3} reason:{2}", platformName, target.assetPath, e.Message, e.GetType().ToString())); } } return(true); }
public void Apply(AssetImporter originalImporter, string assetPath, Property[] properties) { VideoClipImporter importer = (VideoClipImporter)originalImporter; for (int i = 0; i < properties.Length; i++) { var property = properties [i]; switch (property.name) { case "quality": importer.quality = float.Parse(property.value); break; case "linearColor": importer.linearColor = bool.Parse(property.value); break; case "useLegacyImporter": importer.useLegacyImporter = bool.Parse(property.value); break; case "keepAlpha": importer.keepAlpha = bool.Parse(property.value); break; case "deinterlaceMode": importer.deinterlaceMode = (VideoDeinterlaceMode)System.Enum.Parse(typeof(VideoDeinterlaceMode), property.value, true); break; case "flipVertical": importer.flipVertical = bool.Parse(property.value); break; case "flipHorizontal": importer.flipHorizontal = bool.Parse(property.value); break; case "importAudio": importer.importAudio = bool.Parse(property.value); break; case "userData": importer.userData = property.value; break; case "assetBundleName": importer.assetBundleName = property.value; break; case "assetBundleVariant": importer.assetBundleVariant = property.value; break; case "name": importer.name = property.value; break; case "hideFlags": importer.hideFlags = (HideFlags)System.Enum.Parse(typeof(HideFlags), property.value, true); break; } } }