Exemplo n.º 1
0
        private static void ImportAsset(string assetPath, AssetConfig config)
        {
            var i = AssetImporter.GetAtPath(assetPath);

            if (ImportAsset(i, config))
            {
                i.SaveAndReimport();
            }
        }
Exemplo n.º 2
0
 public static void ApplyConfigToAllFileUnderConfig(string configPath, AssetConfig config)
 {
     var dicPath  = Path.GetDirectoryName(configPath);
     var guidList = AssetDatabase.FindAssets(AssetTypes, new[] { dicPath });
     var filePath = (from file in guidList select AssetDatabase.GUIDToAssetPath(file));
     var all      = filePath.All(f =>
     {
         var c = GetConfigByAssetName(f);
         if (object.ReferenceEquals(config, c))
         {
             ImportAsset(f, config);
         }
         return(true);
     });
 }
        public static void CreateConfig()
        {
            string selectionpath = "Assets";

            foreach (Object obj in Selection.GetFiltered(typeof(Object), SelectionMode.Assets))
            {
                selectionpath = AssetDatabase.GetAssetPath(obj);
                if (File.Exists(selectionpath))
                {
                    selectionpath = Path.GetDirectoryName(selectionpath);
                }
                break;
            }
            string newRuleFileName = (Path.Combine(selectionpath, AssetImportPostProcessor.DefaultAssetConfigName));

            if (File.Exists(newRuleFileName))
            {
                EditorUtility.DisplayDialog("Config is there for you", "Can't have to configs in one folder", "OK", "Cancel");
                return;
            }
            var         tree         = AssetImportPostProcessor.tree;
            var         parentConfig = tree.GetAssetConfig(selectionpath, true);
            AssetConfig newRule      = null;

            if (null == parentConfig)
            {
                newRule         = CreateInstance <AssetConfig>();
                newRuleFileName = newRuleFileName.Replace("\\", "/");
                AssetDatabase.CreateAsset(newRule, newRuleFileName);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
            else
            {
                var parentPath = AssetDatabase.GetAssetPath(parentConfig);
                File.Copy(parentPath, newRuleFileName);
                AssetDatabase.ImportAsset(newRuleFileName);
                AssetDatabase.Refresh();
                newRule = AssetDatabase.LoadAssetAtPath <AssetConfig>(newRuleFileName);
            }
            Selection.activeObject = newRule;
            EditorUtility.FocusProjectWindow();
        }
        public AssetConfig GetAssetConfig(string path, bool hirachy)
        {
            var folder = GetFolderInfo(path);

            if (null == folder)
            {
                return(null);
            }

            if (false == hirachy)
            {
                return(folder.Config);
            }

            AssetConfig ret = null;

            while (ret == null && folder != null)
            {
                ret    = folder.Config;
                folder = folder.Parent;
            }
            return(ret);
        }
Exemplo n.º 5
0
        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);
        }
 private void ApplyAssetConfig(AssetConfig config)
 {
     EditorUtility.SetDirty(config);
     AssetDatabase.SaveAssets();
 }
 public void SetAssetConfig(AssetConfig config)
 {
     Config = config;
 }
 public Folder(string name, string path, Folder parent, AssetConfig config)
 {
     Path   = path;
     Parent = parent;
     Config = config;
 }