public void OverwriteImportSettings(AssetImporter importer) { // avoid touching asset if there is no need to. if (IsEqual(importer)) { return; } if (importer.GetType() != referenceImporter.GetType()) { throw new AssetBundleGraphException("Importer type does not match."); } if (importer.GetType() == typeof(UnityEditor.TextureImporter)) { OverwriteImportSettings(importer as UnityEditor.TextureImporter); } else if (importer.GetType() == typeof(UnityEditor.AudioImporter)) { OverwriteImportSettings(importer as UnityEditor.AudioImporter); } else if (importer.GetType() == typeof(UnityEditor.ModelImporter)) { OverwriteImportSettings(importer as UnityEditor.ModelImporter); } else { throw new AssetBundleGraphException("Unknown importer type found:" + importer.GetType()); } }
public bool IsEqual(AssetImporter importer, bool ignorePackingTagDifference = false) { if (importer.GetType() != referenceImporter.GetType()) { throw new AssetBundleGraphException("Importer type does not match."); } if (importer.GetType() == typeof(UnityEditor.TextureImporter)) { return(IsEqual(importer as UnityEditor.TextureImporter, ignorePackingTagDifference)); } else if (importer.GetType() == typeof(UnityEditor.AudioImporter)) { return(IsEqual(importer as UnityEditor.AudioImporter)); } else if (importer.GetType() == typeof(UnityEditor.ModelImporter)) { return(IsEqual(importer as UnityEditor.ModelImporter)); } #if UNITY_5_6 || UNITY_5_6_OR_NEWER else if (importer.GetType() == typeof(UnityEditor.VideoClipImporter)) { return(IsEqual(importer as UnityEditor.VideoClipImporter)); } #endif else { throw new AssetBundleGraphException("Unknown importer type found:" + importer.GetType()); } }
private void DrawPresetManager() { using (new GUILayout.HorizontalScope()) { GUILayout.Space(-8); EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Assets Preset Manager", EditorStyles.toolbarDropDown); EditorGUI.indentLevel++; for (var i = 0; i < assetImportersType.Length; i++) { AssetImporter assetImporter = assetImportersType[i]; assetImportersTypeFoldout[i] = EditorGUILayout.Foldout(assetImportersTypeFoldout[i], assetImporter.GetType().Name, EditorStyles.foldout); if (assetImportersTypeFoldout[i]) { ShowOptionsForImporter(assetImporter); } } EditorGUI.indentLevel--; DrawOptions(); EditorGUILayout.EndVertical(); } }
private static void SetABName(List <string> files, bool setName = true) { GLog.Log("BuildAssets Count " + files.Count, true); for (int i = 0; i < files.Count; i++) { string filePath = files[i]; string assetPath = filePath.Substring(Application.dataPath.Length - "assets".Length); AssetImporter ai = AssetImporter.GetAtPath(assetPath); GemaEditor.ShowProgress(i, files.Count, "SetAssetLabels", ai.assetPath); string abName = AanalyzeAssetLabels(assetPath); GLog.Log(string.Format("No.{0} abName:{1} assetPath:{2}", i + 1, abName, assetPath), true); if (setName) { ai.assetBundleName = abName; ai.assetBundleVariant = "ab"; } else { ai.assetBundleName = null; //ai.assetBundleVariant = null; } string fileName = Path.GetFileName(ai.assetPath); fileName = fileName.Split('.')[0]; string importerName = ai.GetType().ToString().Split('.')[1]; string typename = importerName.Substring(0, importerName.Length - 8); List <string> listAsset; if (!typeAssets.TryGetValue(typename, out listAsset)) { listAsset = new List <string>(); typeAssets.Add(typename, listAsset); } if (listAsset.IndexOf(fileName) != -1) { GLog.Error("Repeat name " + fileName + " type " + typename, true); return; } listAsset.Add(fileName); ABConfigInfo abConfigInfo = abConfig.GetInfoByAB(abName); if (abConfigInfo == null) { abConfigInfo = new ABConfigInfo(); abConfig.AddInfo(abConfigInfo); resourceCount++; abConfigInfo.id = resourceCount; abConfigInfo.ab = abName; abConfigInfo.type = typename; } abConfigInfo.names.Add(fileName); } EditorUtility.ClearProgressBar(); }
public override bool CanProcess(AssetImporter item) { if (m_ImporterReference == null || ReferenceAssetImporter == item) { return(false); } return(item.GetType() == ReferenceAssetImporter.GetType()); }
public static void ImportedAsset(AssetImporter importer) { AssetImporterOperatorInterface importerOperator = null; if (OperatorDict.TryGetValue(importer.GetType(), out importerOperator)) { importerOperator.ImportedAsset(importer); } }
public static Dictionary <string, T> GenerateAssets <T>(List <string> files) where T : Object { if (files.Count <= 0) { return(new Dictionary <string, T>(0)); } Dictionary <string, T> assets = new Dictionary <string, T>(); foreach (string file in files) { AssetImporter assetImporter = AssetImporter.GetAtPath(file); //assetImporter.SupportsRemappedAssetType(typeof(TextureImporter)) if (assetImporter.GetType() == typeof(TextureImporter)) { TextureImporter textureImporter = assetImporter as TextureImporter; if (textureImporter.textureType == TextureImporterType.Sprite) { if (textureImporter.spriteImportMode == SpriteImportMode.Single) { T asset = AssetDatabase.LoadAssetAtPath <T>(file); if (asset == null) { Debug.LogError(string.Format("asset {0} is null", file)); continue; } AddAssets(assets, asset); } else if (textureImporter.spriteImportMode == SpriteImportMode.Multiple) { T[] subAssets = AssetDatabase.LoadAllAssetsAtPath(file).OfType <T>().ToArray(); foreach (T subAsset in subAssets) { AddAssets(assets, subAsset); } } } } else { T asset = AssetDatabase.LoadAssetAtPath <T>(file); if (asset == null) { Debug.LogError(string.Format("asset {0} is null", file)); continue; } AddAssets(assets, asset); } } return(assets); }
private void ReadFolder() { string[] files = GetAllFiles(absoluteFolderPath); HashSet <AssetImporter> assetImporters = new HashSet <AssetImporter>(); HashSet <Type> assetImportersTypes = new HashSet <Type>(); for (var i = 0; i < files.Length; i++) { string absoluteFilePath = files[i]; if (absoluteFilePath.EndsWith(".meta")) { continue; } string relativeFilePath = PresetManagerUtils.AbsoluteToRelativePath(absoluteFilePath); AssetImporter assetImporter = AssetImporter.GetAtPath(relativeFilePath); if (assetImporter == null) { continue; } if (!PresetManagerUtils.HasPresetFor(assetImporter)) { continue; } if (assetImportersTypes.Contains(assetImporter.GetType())) { continue; } assetImporters.Add(assetImporter); assetImportersTypes.Add(assetImporter.GetType()); } assetImportersType = assetImporters.ToArray(); if (assetImportersTypeFoldout == null || assetImportersTypeFoldout.Length != assetImportersType.Length) { assetImportersTypeFoldout = new bool[assetImportersType.Length]; } }
public static MethodInfo GetMethodForProperty(AssetImporter importer, SerializedProperty prop) { Type t = importer.GetType(); string methodName = null; if (propertyMethodHash.TryGetValue(prop.propertyPath, out methodName)) { MethodInfo m = t.GetMethod(methodName); return(m); } return(null); }
public static void Process(AssetImporter importer) { if (!extensionProcessesMap.TryGetValue(importer.GetType(), out var processes)) { return; } foreach (var process in processes) { process.Process(importer, m_processWriter); } }
public bool IsEqual(AssetImporter importer) { if (importer.GetType() != referenceImporter.GetType()) { throw new AssetBundleGraphException("Importer type does not match."); } if (importer.GetType() == typeof(UnityEditor.TextureImporter)) { return(IsEqual(importer as UnityEditor.TextureImporter)); } else if (importer.GetType() == typeof(UnityEditor.AudioImporter)) { return(IsEqual(importer as UnityEditor.AudioImporter)); } else if (importer.GetType() == typeof(UnityEditor.ModelImporter)) { return(IsEqual(importer as UnityEditor.ModelImporter)); } else { throw new AssetBundleGraphException("Unknown importer type found:" + importer.GetType()); } }
public void OverwriteImportNGSettings(AssetImporter importer) { // avoid touching asset if there is no need to. if (IsEqual(importer)) { return; } if (importer.GetType() != referenceImporter.GetType()) { throw new NodeGraph.DataModelException("Importer type does not match."); } if (importer.GetType() == typeof(UnityEditor.TextureImporter)) { OverwriteImportNGSettings(importer as UnityEditor.TextureImporter); } else if (importer.GetType() == typeof(UnityEditor.AudioImporter)) { OverwriteImportNGSettings(importer as UnityEditor.AudioImporter); } else if (importer.GetType() == typeof(UnityEditor.ModelImporter)) { OverwriteImportNGSettings(importer as UnityEditor.ModelImporter); } #if UNITY_5_6 || UNITY_5_6_OR_NEWER else if (importer.GetType() == typeof(UnityEditor.VideoClipImporter)) { OverwriteImportNGSettings(importer as UnityEditor.VideoClipImporter); } #endif else { throw new NodeGraph.DataModelException("Unknown importer type found:" + importer.GetType()); } }
public static void CheckPluginImportSettings() { string[] guids = AssetDatabase.FindAssets("", new[] { "Packages/com.unity.webrtc/Runtime/Plugins" }); foreach (string guid in guids) { string path = AssetDatabase.GUIDToAssetPath(guid); AssetImporter assetImporter = AssetImporter.GetAtPath(path); Assert.IsNotNull(assetImporter); if (assetImporter.GetType() != typeof(PluginImporter)) { continue; } PluginImporter pluginImporter = assetImporter as PluginImporter; Assert.IsNotNull(pluginImporter); Assert.IsTrue(pluginImporter.isPreloaded); } }
private static bool IsFontAsset(string patch) { AssetImporter ap = AssetImporter.GetAtPath(patch); if (!ap) { return(false); } if (!patch.Contains(FontPatch)) { return(false); } if (ap.GetType() == typeof(TrueTypeFontImporter) || patch.EndsWith(".fontsettings")) { return(true); } return(false); }
public static bool GetHumanDescription(GameObject target, ref HumanDescription des) { if (target != null) { AssetImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(target)); if (importer != null) { Debug.Log("AssetImporter Type: " + importer.GetType()); ModelImporter modelImporter = importer as ModelImporter; if (modelImporter != null) { des = modelImporter.humanDescription; Debug.Log("## Cool stuff data by ModelImporter ##"); foreach (var VARIABLE in des.skeleton) { //Debug.Log(VARIABLE); } //Debug.LogError(des.skeleton); return(true); } else { Debug.LogError("## Please Select Imported Model in Project View not prefab or other things ##"); } } else { Debug.LogError("importer is null"); } } else { Debug.LogError("target is null"); } return(false); }
public bool GetHumanDescription(Avatar target, ref HumanDescription des) { if (target != null) { AssetImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(target.GetInstanceID())); if (importer != null) { Debug.Log("AssetImporter Type: " + importer.GetType()); ModelImporter modelImporter = importer as ModelImporter; if (modelImporter != null) { des = modelImporter.humanDescription; Debug.Log("## Cool stuff data by ModelImporter ##"); return(true); } else { Debug.LogError("## Please Select Imported Model in Project View not prefab or other things ##"); } } } return(false); }
private static bool ImportAsset(AssetImporter import, AssetConfig config) { var ret = false; var importType = import.GetType(); var fields = config.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); foreach (var field in fields) { var targetConfigType = field.FieldType.GetCustomAttributes(typeof(AssetConfigTarget), true); if (targetConfigType.Length == 0) { continue; } var targetType = (AssetConfigTarget)targetConfigType[0]; if (targetType.TargetType != importType) { continue; } var configField = (AssetConfigApply)field.GetValue(config); ret = configField.SetAssetConfig(import); break; } return(ret); }
public static bool Conforms(AssetImporter importer, IList <Filter> filters) { if (importer == null || filters == null || filters.Count == 0) { return(true); } FileInfo fi = new FileInfo(importer.assetPath); DirectoryInfo di = new DirectoryInfo(importer.assetPath); Assert.IsTrue(fi.Exists || di.Exists); for (int i = 0; i < filters.Count; ++i) { switch (filters[i].m_Target) { case ConditionTarget.Filename: string name = fi.Name; if (!string.IsNullOrEmpty(fi.Extension)) { name = name.Remove(name.Length - fi.Extension.Length); } if (!Target(name, filters[i])) { return(false); } break; case ConditionTarget.FullFilename: if (!Target(importer.assetPath, filters[i])) { return(false); } break; case ConditionTarget.FolderName: if (fi.Directory == null || !Target(fi.Directory.Name, filters[i])) { return(false); } break; case ConditionTarget.Directory: string path = importer.assetPath; if (!Target(path.Remove(path.Length - fi.Name.Length - 1), filters[i])) { return(false); } break; case ConditionTarget.Extension: if (!Target(fi.Extension, filters[i])) { return(false); } break; case ConditionTarget.FileSize: if (!Target(fi.Length, filters[i])) { return(false); } break; case ConditionTarget.AssetBundleName: if (!Target(importer.assetBundleName, filters[i])) { return(false); } break; case ConditionTarget.Labels: string[] wildLabels = filters[i].m_Wildcard.Split(','); string[] labels = AssetDatabase.GetLabels(AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(importer.assetPath)); switch (filters[i].m_Condition) { case Condition.Equals: if (wildLabels.Length != labels.Length) { return(false); } for (int wlId = 0; wlId < wildLabels.Length; ++wlId) { bool contains = false; for (int lId = 0; lId < labels.Length; ++lId) { if (wildLabels[wlId].Equals(labels[lId], StringComparison.OrdinalIgnoreCase)) { contains = true; break; } } if (contains == false) { return(false); } } return(true); case Condition.Contains: for (int wlId = 0; wlId < wildLabels.Length; ++wlId) { bool contains = false; for (int lId = 0; lId < labels.Length; ++lId) { if (wildLabels[wlId].Equals(labels[lId], StringComparison.OrdinalIgnoreCase)) { contains = true; break; } } if (contains == false) { return(false); } } return(true); case Condition.DoesNotContain: for (int wlId = 0; wlId < wildLabels.Length; ++wlId) { for (int lId = 0; lId < labels.Length; ++lId) { if (wildLabels[wlId].Equals(labels[lId], StringComparison.OrdinalIgnoreCase)) { return(false); } } } return(true); } break; case ConditionTarget.ImporterType: if (!Target(importer.GetType().Name, filters[i])) { return(false); } break; default: throw new ArgumentOutOfRangeException(); } } return(true); }
/// <summary> /// Attempt to apply the given settings to the asset found at the path /// </summary> /// <param name="assetPath">Path to the asset</param> /// <param name="importSettings">Settings to apply</param> public static void ApplyImportSettingsToAsset(string assetPath, ImportSettings importSettings) { if (importSettings != null) { AssetImporter importer = AssetImporter.GetAtPath(assetPath); #region Apply Texture Import Settings if (importer.GetType() == typeof(TextureImporter) && importSettings.UseTextureSettings == true) { TextureImporter textureImporter = (TextureImporter)importer; //User wants to override the Android texture settings, create the appropriate settings and override them for Android if (importSettings.OverrideAndroidTextureSettings == true) { TextureImporterPlatformSettings androidTextureSettings = new TextureImporterPlatformSettings() { name = "Android", maxTextureSize = (int)importSettings.AndroidMaxTextureSize, overridden = true }; textureImporter.SetPlatformTextureSettings(androidTextureSettings); } else { //Make sure to stop overriding the Android settings, if they're disabled textureImporter.ClearPlatformTextureSettings("Android"); } textureImporter.filterMode = importSettings.TetxureFilterMode; textureImporter.maxTextureSize = (int)importSettings.MaxTextureSize; textureImporter.anisoLevel = importSettings.FilterLevel; s_validAssetCount++; } #endregion #region Apply Audio Import Settings if (importer.GetType() == typeof(AudioImporter) && importSettings.UseAudioSettings == true) { AudioImporter audioImporter = (AudioImporter)importer; AudioImporterSampleSettings audioImportSettings = new AudioImporterSampleSettings() { sampleRateSetting = importSettings.AudioSampleRate, sampleRateOverride = (uint)importSettings.SampleRateOverride, compressionFormat = importSettings.CompressionFormat, loadType = importSettings.AudioLoadType }; //User wants to override the Android audio settings, create the appropriate settings and override them for Android if (importSettings.OverrideAndroidAudioSettings == true) { AudioImporterSampleSettings androidAudioImportSettings = new AudioImporterSampleSettings() { sampleRateSetting = importSettings.AndroidAudioSampleRate, sampleRateOverride = (uint)importSettings.AndroidSampleRateOverride, compressionFormat = importSettings.AndroidCompressionFormat, loadType = importSettings.AndroidAudioClipLoadType }; audioImporter.SetOverrideSampleSettings("Android", androidAudioImportSettings); } else { //Make sure to stop overriding the Android settings, if they're disabled audioImporter.ClearSampleSettingOverride("Android"); } audioImporter.defaultSampleSettings = audioImportSettings; s_validAssetCount++; } #endregion AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate); } else { Debug.Log($"No import settings found for asset { assetPath } "); } }
public static TextureImporter getTextureImporter(String path, String errorLabel) { if (path.Length == 0) { Debug.LogError(errorLabel + " needs an asset path (empty string provided)."); return(null); } AssetImporter ai = AssetImporter.GetAtPath(path); if (ai == null) { Debug.LogError(errorLabel + " failed to fetch any asset importer for path '" + path + "'."); return(null); } TextureImporter ti = ai as TextureImporter; if (ti == null) { Debug.LogError(errorLabel + " failed to cast AssetImporter of type " + ai.GetType() + " to TextureImporter at path '" + path + "'."); return(null); } return(ti); }