public void Apply(AssetImporter importer) { PresetRuleItem preset = FindMatchRule(importer); if (preset != null) { preset.Apply(path, importer); } }
static void CreatePresetAndRule() { Object obj = Selection.activeObject; string path = AssetDatabase.GetAssetPath(obj); AssetImporter importer = AssetImporter.GetAtPath(path); Preset preset = new Preset(importer); string presetSavePath = EditorUtility.SaveFilePanel("保存Preset", Application.dataPath, "DefaultPreset", "preset"); if (string.IsNullOrEmpty(presetSavePath)) { EditorUtility.DisplayDialog("提示", "请选择一个正确的保存目录", "确定"); return; } presetSavePath = FileUtil.GetProjectRelativePath(presetSavePath); AssetDatabase.CreateAsset(preset, presetSavePath); string dir = Path.GetDirectoryName(path); PresetRuleItem ruleItem = new PresetRuleItem(); ruleItem.preset = preset; PresetRule rule = ScriptableObject.CreateInstance <PresetRule>(); rule.path = dir; rule.presets = new PresetRuleItem[] { ruleItem }; string ruleSavePath = EditorUtility.SaveFilePanel("保存PresetRule", dir, "DefaultRule", "asset"); if (string.IsNullOrEmpty(presetSavePath)) { EditorUtility.DisplayDialog("提示", "请选择一个正确的保存目录", "确定"); return; } ruleSavePath = FileUtil.GetProjectRelativePath(ruleSavePath); AssetDatabase.CreateAsset(rule, ruleSavePath); AssetDatabase.Refresh(); Debug.LogFormat("创建PresetRule成功! path={0}", ruleSavePath); }