Ejemplo n.º 1
0
        public ImporterRule(XmlNode node)
        {
            node.TryGetValue("Name", ref name);
            node.TryGetValue("Enabled", ref enabled);

            string typeString = "";

            if (node.TryGetValue("Type", ref typeString))
            {
                type = (ImporterRulesTypes)Enum.Parse(typeof(ImporterRulesTypes), typeString);
            }

            string pathComparerString = "";

            if (node.TryGetValue("PathComparer", ref pathComparerString))
            {
                pathComparer = (ImporterRulesPathComparer)Enum.Parse(typeof(ImporterRulesPathComparer), pathComparerString);
            }

            node.TryGetValue("Path", ref path);
            node.TryGetValue("Pattern", ref pattern);

            XmlNode propsNode = node["Props"];

            InitSettings();

            UpdateActiveSettings();

            activeSettings.Load(propsNode);
        }
Ejemplo n.º 2
0
 public void CopyFrom(ImporterRule rule)
 {
     name            = rule.name;
     path            = rule.path;
     pattern         = rule.pattern;
     pathComparer    = rule.pathComparer;
     type            = rule.type;
     audioSettings   = rule.audioSettings;
     fontSettings    = rule.fontSettings;
     modelSettings   = rule.modelSettings;
     movieSettings   = rule.movieSettings;
     textureSettings = rule.textureSettings;
     UpdateActiveSettings();
 }
Ejemplo n.º 3
0
        public void LoadFromAsset(Object obj)
        {
            string assetPath = AssetDatabase.GetAssetPath(obj);

            FileAttributes attr = File.GetAttributes(assetPath);

            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            {
                path         = assetPath.Substring(7) + "/";
                pathComparer = ImporterRulesPathComparer.startWith;
                return;
            }

            AssetImporter importer = AssetImporter.GetAtPath(assetPath);

            if (importer == null)
            {
                return;
            }

            if (importer is TextureImporter)
            {
                type = ImporterRulesTypes.texture;
            }
            else if (importer is ModelImporter)
            {
                type = ImporterRulesTypes.model;
            }
            else if (importer is MovieImporter)
            {
                type = ImporterRulesTypes.movie;
            }
            else if (importer is AudioImporter)
            {
                type = ImporterRulesTypes.audio;
            }
            else if (importer is TrueTypeFontImporter)
            {
                type = ImporterRulesTypes.trueTypeFont;
            }

            UpdateActiveSettings();
            activeSettings.GetSettingsFromImporter(importer);
        }
Ejemplo n.º 4
0
        public void DrawEditor(bool useScroll = true)
        {
            name = EditorGUILayout.TextField("Name: ", name);

            EditorGUI.BeginChangeCheck();
            type = (ImporterRulesTypes)EditorGUILayout.EnumPopup("Type: ", type);
            if (EditorGUI.EndChangeCheck())
            {
                UpdateActiveSettings();
            }

            pathComparer = (ImporterRulesPathComparer)EditorGUILayout.EnumPopup("Path comparer: ", pathComparer);

            if (pathComparer == ImporterRulesPathComparer.contains || pathComparer == ImporterRulesPathComparer.startWith || pathComparer == ImporterRulesPathComparer.notContains)
            {
                GUILayout.BeginHorizontal();
                path = EditorGUILayout.TextField("Path: ", path);
                DrawPathBrowse();

                GUILayout.EndHorizontal();
            }
            else if (pathComparer == ImporterRulesPathComparer.regex)
            {
                pattern = EditorGUILayout.TextField("Pattern: ", pattern);
            }

            EditorGUILayout.Space();

            if (useScroll)
            {
                scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            }

            activeSettings.DrawEditor();

            if (useScroll)
            {
                EditorGUILayout.EndScrollView();
            }
        }
Ejemplo n.º 5
0
        public bool CheckPath(string assetPath)
        {
            if (string.IsNullOrEmpty(assetPath))
            {
                return(false);
            }
            ImporterRulesPathComparer comparer = pathComparer;

            if (comparer == ImporterRulesPathComparer.allAssets)
            {
                return(true);
            }
            if (comparer != ImporterRulesPathComparer.regex && string.IsNullOrEmpty(path))
            {
                return(true);
            }

            string curPattern = pattern;

            if (comparer == ImporterRulesPathComparer.regex && string.IsNullOrEmpty(curPattern))
            {
                return(true);
            }

            assetPath = FixPath(assetPath).Substring(7);

            if (comparer != ImporterRulesPathComparer.regex)
            {
                if (path.Contains("*") || path.Contains("?"))
                {
                    comparer   = ImporterRulesPathComparer.regex;
                    curPattern = PathToRegexp(path);
                    if (comparer == ImporterRulesPathComparer.startWith)
                    {
                        curPattern = "^" + curPattern;
                    }
                }
                else if (path.Length > assetPath.Length)
                {
                    if (comparer == ImporterRulesPathComparer.notContains)
                    {
                        return(true);
                    }
                    return(false);
                }
            }

            if (comparer == ImporterRulesPathComparer.regex)
            {
                Regex regex   = new Regex(curPattern);
                bool  isMatch = regex.IsMatch(assetPath);
                if (pathComparer == ImporterRulesPathComparer.notContains)
                {
                    return(!isMatch);
                }
                return(isMatch);
            }

            string curPath = FixPath(path);

            if (comparer == ImporterRulesPathComparer.startWith)
            {
                return(assetPath.Substring(0, path.Length) == curPath);
            }
            if (comparer == ImporterRulesPathComparer.contains)
            {
                return(assetPath.Contains(curPath));
            }
            if (comparer == ImporterRulesPathComparer.notContains)
            {
                return(!assetPath.Contains(curPath));
            }

            return(false);
        }