Tencent / xLua

xLua is a lua programming solution for C# ( Unity, .Net, Mono) , it supports android, ios, windows, linux, osx, etc.
Other
9.39k stars 2.46k forks source link

Generator.ClearAll 报错 Invalid AssetDatabase path: /XLua/Gen/ ,但是似乎并不影响最终结果 #968

Open ganlvtech opened 2 years ago

ganlvtech commented 2 years ago

Unity 版本: 2018.4.28f1

https://github.com/Tencent/xLua/blob/8eeb4ee803d14880be0a245b43b28d9e62941a8e/Assets/XLua/Src/Editor/Generator.cs#L29 https://github.com/Tencent/xLua/blob/8eeb4ee803d14880be0a245b43b28d9e62941a8e/Assets/XLua/Src/Editor/Generator.cs#L1043-L1052 https://github.com/Tencent/xLua/blob/8eeb4ee803d14880be0a245b43b28d9e62941a8e/Assets/XLua/Src/Editor/Generator.cs#L1734-L1738

  1. 删除 Assets/XLua/Gen/ 应该同时删除 Assets/XLua/Gen.meta
  2. path 实际上为 C:/path/to/project/Assets/XLua/Gen/,而 AssetDatabase.DeleteAsset 要求传入 Assets/XLua/Gen/。原来的写法会报错。
Invalid AssetDatabase path: /XLua/Gen/. Use path relative to the project folder.
UnityEditor.AssetDatabase:DeleteAsset(String)
CSObjectWrapEditor.Generator:clear(String) (at Assets\XLua\Src\Editor\Generator.cs:1048)
CSObjectWrapEditor.Generator:ClearAll() (at Assets\XLua\Src\Editor\Generator.cs:1737)
XLuaEditor:GeneratorHotFix() (at Assets\XLua\Editor\XLuaEditor.cs:65)

[E:\unity\artifacts/generated/bindings_old/common/Editor/AssetDatabaseBindings.gen.cpp line 29] 
(Filename: Assets/XLua/Src/Editor/Generator.cs Line: 1048)

Can not delete asset. /XLua/Gen/ is not a valid path.
UnityEditor.AssetDatabase:DeleteAsset(String)
CSObjectWrapEditor.Generator:clear(String) (at Assets\XLua\Src\Editor\Generator.cs:1048)
CSObjectWrapEditor.Generator:ClearAll() (at Assets\XLua\Src\Editor\Generator.cs:1737)
XLuaEditor:GeneratorHotFix() (at Assets\XLua\Editor\XLuaEditor.cs:65)

[E:\unity\Modules/AssetDatabase/Editor/Public/AssetDatabase.cpp line 449] 
(Filename: Assets/XLua/Src/Editor/Generator.cs Line: 1048)

Refresh: detecting if any assets need to be imported or removed ...
A meta data file (.meta) exists but its asset 'Assets/XLua/Gen' can't be found. When moving or deleting files outside of Unity, please ensure that the corresponding .meta file is moved or deleted along with it.
UnityEditor.AssetDatabase:Refresh(ImportAssetOptions)
UnityEditor.AssetDatabase:Refresh() (at E:\unity\artifacts\generated\bindings_old\common\Editor\AssetDatabaseBindings.gen.cs:306)
CSObjectWrapEditor.Generator:clear(String) (at Assets\XLua\Src\Editor\Generator.cs:1050)
CSObjectWrapEditor.Generator:ClearAll() (at Assets\XLua\Src\Editor\Generator.cs:1737)
XLuaEditor:GeneratorHotFix() (at Assets\XLua\Editor\XLuaEditor.cs:65)

[E:\unity\Modules/AssetDatabase/Editor/V1/RefreshAssets.cpp line 83] 
(Filename: Assets/XLua/Src/Editor/Generator.cs Line: 1050)

可以修改为

        static void clear(string path)
        {
            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
                string metaFilePath = path.TrimEnd('/') + ".meta";
                if (File.Exists(metaFilePath))
                {
                    File.Delete(metaFilePath);
                }
                if (path.StartsWith(Application.dataPath))
                {
                    path = "Assets" + path.Substring(Application.dataPath.Length);
                }
                AssetDatabase.DeleteAsset(path);

                AssetDatabase.Refresh();
            }
        }
LJLCarrien commented 1 year ago

Unity 版本: 2021.3.18f1 也遇到同样的情况,按照上述修改后,警告消失,感谢