如何使点文件夹/文件在unity中可见?

2024-05-18 11:40:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我在unity中使用ironpython运行一些脚本和一些python包,在运行我得到的项目时:

OSException: cannot load library C:\Users\Sai\Documents\Work\Unity\Unity-Python-Demo-master\Assets\StreamingAssets\Lib\site-packages\numpy\.libs\libopenblas.SVHFG5YE3RK3Z27NVFUDAPL2O3W6IMXW.gfortran-win32.dll

问题是unity隐藏了以点“.”开头的文件夹和文件。我怎样才能解决这个问题?其中一个包需要一个位于“.lib”文件夹中的文件,但它是隐藏的,我只能在资源管理器窗口中看到该文件夹,而不能在unity项目中看到

这是我的密码:

        var engine = Python.CreateEngine();
        ICollection<string> searchPaths = engine.GetSearchPaths();
#if UNITY_STANDALONE_WIN
        searchPaths.Add(Application.dataPath);
        searchPaths.Add(Application.dataPath + @"\StreamingAssets" + @"\Lib\");
        searchPaths.Add(Application.dataPath + @"\StreamingAssets" + @"\Lib\site-packages\");
        engine.SetSearchPaths(searchPaths);
        dynamic py = engine.ExecuteFile(Application.dataPath + @"\StreamingAssets" + @"\Python\pt.py");
        test = py.CTScan("Codemaker");

如下图所示,.lib文件夹在项目中不可见:

in the unity projectexplorer window


Tags: 文件项目py文件夹addapplicationlibpackages
1条回答
网友
1楼 · 发布于 2024-05-18 11:40:27

显然没有办法

Unity Manual - Special folder names

Hidden Assets

During the import process, Unity completely ignores the following files and folders in the Assets folder (or a sub-folder within it):

  • Hidden folders.
  • Files and folders which start with ‘.’.
  • Files and folders which end with ‘~’.
  • Files and folders named cvs.
  • Files with the extension .tmp.

This is used to prevent importing special and temporary files created by the operating system or other applications.

这些文件不会进入Unity导入,因此也不会进入构建


我想解决这个问题的办法应该是

  • 将其预编译为插件DLL,在内部存储和提供这些文件,并使用它们

  • 那么,请使用不同的文件夹名称

  • 找到另一种向应用程序提供不在Assets文件夹中的文件的方法(例如,尝试改用persistenDataPath或使用zip并在运行时解压缩)


只是一个一般性的旁注:

不要将字符串concat(+ "\")用于系统文件路径

而是直接使用^{}和更通用的^{},根据设备的操作系统插入正确的路径分隔符,例如

searchPaths.Add(Path.Combine(Application.streamingAssetsPath, "Lib", "site-packages"));
 

相关问题 更多 >