Пример #1
0
        public static void OnPostprocessAllAssets(string[] importedAsset, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            foreach (string str in importedAsset)
            {
                //Debug.Log("importedAsset = " + str);
            }

            foreach (string str in deletedAssets)
            {
                //Debug.Log("deletedAssets = " + str);
            }

            foreach (string str in movedAssets)
            {
                AssetImporter assetImporter = AssetImporter.GetAtPath(str);
                PresetRule    rule          = FindRuleForAsset(assetImporter.assetPath);

                if (rule == null)
                {
                    return;
                }
                rule.Apply(assetImporter);
            }

            foreach (string str in movedFromAssetPaths)
            {
                //Debug.Log("movedFromAssetPaths = " + str);
            }
        }
Пример #2
0
        private void OnPreprocessModel()
        {
            PresetRule rule = FindRuleForAsset(assetImporter.assetPath);

            if (rule == null)
            {
                return;
            }
            rule.Apply(assetImporter);
        }
Пример #3
0
        private List <PresetRule> GetPresetRules()
        {
            List <PresetRule> rules = new List <PresetRule>();

            string[] guids = AssetDatabase.FindAssets("t:PresetRule");
            foreach (var guid in guids)
            {
                string     path = AssetDatabase.GUIDToAssetPath(guid);
                PresetRule rule = AssetDatabase.LoadAssetAtPath <PresetRule>(path);
                rules.Add(rule);
            }
            return(rules);
        }
Пример #4
0
        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);
        }
Пример #5
0
        private void DrawRule(PresetRule rule)
        {
            EditorGUILayout.BeginVertical("box");
            GUI.enabled = false;
            EditorGUILayout.TextField("Path", rule.path);
            GUI.enabled = true;
            //rule.preset = (Preset)EditorGUILayout.ObjectField("Preset", rule.preset, typeof(Preset), false);
            //rule.recursive = EditorGUILayout.Toggle("Recursive", rule.recursive);
            //rule.regex = EditorGUILayout.TextField("Regex", rule.regex);
            //rule.extension = EditorGUILayout.TextField("Extension", rule.extension);

            Color origin = GUI.color;

            GUI.color = Color.green;
            if (GUILayout.Button("Reimport"))
            {
                AssetDatabase.ImportAsset(rule.path, ImportAssetOptions.DontDownloadFromCacheServer | ImportAssetOptions.ImportRecursive);
            }
            GUI.color = origin;
            EditorGUILayout.EndVertical();
        }