tuyoogame / YooAsset

unity3d resources management system
https://www.yooasset.com/
Apache License 2.0
2.42k stars 473 forks source link

原生文件收集那里有一个问题 #95

Open rrtt2323 opened 1 year ago

rrtt2323 commented 1 year ago

image 如图,因为我有一个对.ini文件的扩展功能,所以这里依赖不会为0,就无法被收集了,所以我把这里的代码修改了一下,大佬看看是不是合并一下。

AssetBundleCollector.cs 263 行处

`// 注意:原生文件只支持无依赖关系的资源 string[] depends = AssetDatabase.GetDependencies(assetPath, true); if (depends.Length != 1) { // 检查依赖的是不是代码 bool dependCode = true; foreach (var item in depends) { // 排除资源本身 if(item == assetPath) continue;

                    // 通过扩展名判断是不是都是代码
                    string dependExtension = StringUtility.RemoveFirstChar(System.IO.Path.GetExtension(item));
                    dependCode &= dependExtension == EAssetFileExtension.cs.ToString();
                }

                if (!dependCode)
                {
                    UnityEngine.Debug.LogWarning($"Raw file pack rule can not support estension : {extension}");
                    return false;
                }
            }`
gmhevinci commented 1 year ago

这里显示ini文件对CS脚本文件有依赖关系。我本地复现看看

rrtt2323 commented 1 year ago

有依赖的原因是我对.ini文件做了编辑器扩展,在资源导入时,给转换成 ScriptableObject 那种序列化文件了,所以会有依赖了。 原则上任意后缀名的文本资源都能这么扩展,所以最好是排除一下有对.cs文件依赖的。

rrtt2323 commented 1 year ago

`[UnityEditor.AssetImporters.ScriptedImporter(1, "ini")] public class IniFileImporter : UnityEditor.AssetImporters.ScriptedImporter { public string filePath;

public override void OnImportAsset(UnityEditor.AssetImporters.AssetImportContext ctx)
{
    filePath = ctx.assetPath;
    // 读取文件
    var textContent = File.ReadAllText(filePath);
    // 序列化文件
    var iniObject = IniFileAsset.ParseIniContent(textContent);
    // 把对象设置给编辑器
    ctx.AddObjectToAsset(nameof(IniFileAsset), iniObject);
    ctx.SetMainObject(iniObject);
}

}`

核心代码就是这样

gmhevinci commented 1 year ago

如果是这样的话,ScriptableObject序列化的文件是不能作为原生文件的。

gmhevinci commented 1 year ago

如果只是ini格式的纯文本,作为原生文件是没任何问题的。

rrtt2323 commented 1 year ago

如果只是ini格式的纯文本,作为原生文件是没任何问题的。

是纯文本的,只是在导入时序列化到内存里,也不产生实体的.asset文件

gmhevinci commented 1 year ago

明白了。1.4.10版本已经注释了相关代码,你可以试一下。该问题请不要关闭。