Exemple #1
0
        public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
                                                  string[] movedFromAssetPaths)
        {
            var helpers   = AssetImportHelperBase.GetAllAssetImportHelper();
            var allConfig = AssetImportConfig.LoadConfig();

            foreach (string path in importedAssets)
            {
                var assetType = Match(helpers, path);
                if (assetType != AssetType.None)
                {
                    object config;
                    bool   idDefault;
                    config = helpers[assetType].GetAssetConfig(allConfig, path, out idDefault);
                    helpers[assetType].SetImporterByConfig(AssetImporter.GetAtPath(path), (AssetItemConfigBase)config);
                }
            }
            if (deletedAssets.Length == 0 && movedAssets.Length == 0)
            {
                return;
            }
            bool dirty = false;

            //删除资源后 删除配置表对应项目
            foreach (string path in deletedAssets)
            {
                var assetType = Match(helpers, path);
                if (assetType != AssetType.None)
                {
                    dirty = allConfig.GetAtlasConfig(assetType).Remove(Path.GetFileNameWithoutExtension(path));
                }
            }
            //移动资源后 修改配置表对应路径
            for (int i = 0; i < movedAssets.Length; i++)
            {
                var movePath     = movedAssets[i];
                var moveFromPath = movedFromAssetPaths[i];
                var assetType    = Match(helpers, moveFromPath);
                if (assetType != AssetType.None)
                {
                    object config;
                    Dictionary <string, object> configDic = allConfig.GetAtlasConfig(assetType);
                    if (configDic.TryGetValue(moveFromPath, out config))
                    {
                        dirty = true;
                        configDic.Remove(Path.GetFileNameWithoutExtension(moveFromPath));
                        configDic.Add(movePath, config);
                    }
                }
            }
            if (dirty)
            {
                allConfig.SaveConfig();
            }
        }
        public override AssetItemConfigBase GetAssetConfig(AssetImportConfig assetImportConfig, string assetPath, out bool isDefault)
        {
            AnimationConfig config;

            isDefault = false;
            string fileName = Path.GetFileNameWithoutExtension(assetPath);

            if (!assetImportConfig.GetAtlasConfig <AnimationConfig>().TryGetValue(fileName, out config))
            {
                config    = GetDefault();
                isDefault = true;
            }
            return(config);
        }
        public override AssetItemConfigBase GetAssetConfig(AssetImportConfig assetImportConfig, string assetPath, out bool isDefault)
        {
            AtlasOrFontConfig config;

            isDefault = false;
            string fileName = Path.GetFileNameWithoutExtension(assetPath);

            if (!assetImportConfig.GetAtlasConfig <AtlasOrFontConfig>().TryGetValue(fileName, out config))
            {
                //找不到则遍历匹配文件名
                foreach (var pair in assetImportConfig.GetAtlasConfig <AtlasOrFontConfig>())
                {
                    if (fileName.Contains(pair.Key))
                    {
                        return(pair.Value);
                    }
                }
                config    = (AtlasOrFontConfig)GetDefaultConfig(assetPath);
                isDefault = true;
            }
            return(config);
        }
Exemple #4
0
 public abstract AssetItemConfigBase GetAssetConfig(AssetImportConfig assetImportConfig, string assetPath, out bool isDefault);
 private void Setup()
 {
     assetImportConfig  = AssetImportConfig.LoadConfig();
     changeConfigAssets = new HashSet <string>();
 }