HowTo: uPD with unity 5

本文关键字:unity with uPD HowTo | 更新日期: 2023-09-27 18:14:59

第一篇。如果我违反了任何规定,请告诉我!

我想尝试使用Pure Data和Unity 5。看来uPD是最合适的人选。我已经按照github页面上的说明加载了第一个示例场景。unity控制台报告dll的错误:

Failed to load 'Assets/Magicolo/AudioTools/PureData/Plugins/libpdcsharp.dll', expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must recompile your plugin for 64 bit architecture.

因此,我克隆了主要的libpd repo,并使用包含的批处理文件来构建x64 dll。我在unity项目中替换了libpdcsharp.dll,控制台现在报告:

DllNotFoundException: Assets/Magicolo/AudioTools/PureData/Plugins/libpdcsharp.dll
LibPDBinding.LibPD.ProcessArgs[Int32] (System.Int32[] args, System.String& debug) (at Assets/Magicolo/AudioTools/PureData/LibPD/LibPDNativeMessaging.cs:402)
LibPDBinding.LibPD.SendMessage[Int32] (System.String receiver, System.String message, System.Int32[] args) (at Assets/Magicolo/AudioTools/PureData/LibPD/LibPDNativeMessaging.cs:354)
(wrapper synchronized) LibPDBinding.LibPD:SendMessage (string,string,int[])
LibPDBinding.LibPD.ComputeAudio (Boolean state) (at Assets/Magicolo/AudioTools/PureData/LibPD/LibPDNativeMethods.cs:238)
(wrapper synchronized) LibPDBinding.LibPD:ComputeAudio (bool)
LibPDBinding.LibPD.Release () (at Assets/Magicolo/AudioTools/PureData/LibPD/LibPDNativeMethods.cs:207)
(wrapper synchronized) LibPDBinding.LibPD:Release ()
LibPDBinding.LibPD.ReInit () (at Assets/Magicolo/AudioTools/PureData/LibPD/LibPDNativeMethods.cs:79)
(wrapper synchronized) LibPDBinding.LibPD:ReInit ()
LibPDBinding.LibPD..cctor () (at Assets/Magicolo/AudioTools/PureData/LibPD/LibPDNativeMethods.cs:65)
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for LibPDBinding.LibPD
Magicolo.AudioTools.PureDataBridge.SetAudioSettings () (at Assets/Magicolo/AudioTools/PureData/PureDataBridge.cs:46)
Magicolo.AudioTools.PureDataBridge.StartLibPD () (at Assets/Magicolo/AudioTools/PureData/PureDataBridge.cs:25)
Magicolo.AudioTools.PureDataBridge.Start () (at Assets/Magicolo/AudioTools/PureData/PureDataBridge.cs:50)
PureData.StartAll () (at Assets/Magicolo/AudioTools/PureData/PureData.cs:141)
PureData.Initialize () (at Assets/Magicolo/AudioTools/PureData/PureData.cs:58)
PureData.Awake () (at Assets/Magicolo/AudioTools/PureData/PureData.cs:173)

我也试过将libpbinding .dll文件从主libpd repo复制到unity项目中,但无济于事。我缺乏理解,知道下一步该去哪里,所以任何帮助都将不胜感激!

<

进一步进展/strong>

建议尝试使用NuGet获取绑定的dll。关于这一点-我得到一个关于我的unity项目/visual studio解决方案和nuget包libpbinding版本0.10.0之间的框架不匹配的错误。这与一篇题为"在Visual Studio Tools for Unity中使用NuGet"的文章中描述的Unity配置文件有关。我不能在这里张贴链接,因为我太新了。

然而,我认为我成功地编写了自己的libPDBinding.dll。很抱歉拖了这么久,只是为了确保我做得对:在使用libPD'mingw64_build_csharp.bat编译了一个x64版本的libpdcsharp.dll之后,我在VS解决方案中引用了它和libpd'libs'mingw64'libwinthread-1.dll,并得到了用。net 3.5构建的LibPDBinding.dll。如前所述,libpdcsharp.dll是使用批处理/制作文件编译的,那么我是否可以假设该文件已使用正确的设置构建?

我继续复制这3个dll的统一资产文件夹作为参考,这是一个空白的unity项目,uPD作为唯一的包,加载到uPD示例场景中。

我仍然得到一些错误在运行时和一些visual studio警告如下。

Unity运行时错误:

EntryPointNotFoundException: libpd_safe_init
LibPDBinding.LibPD.ReInit () (at Assets/Magicolo/AudioTools/PureData/LibPD/LibPDNativeMethods.cs:81)
(wrapper synchronized) LibPDBinding.LibPD:ReInit ()
LibPDBinding.LibPD..cctor () (at Assets/Magicolo/AudioTools/PureData/LibPD/LibPDNativeMethods.cs:65)
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for LibPDBinding.LibPD
Magicolo.AudioTools.PureDataBridge.SetAudioSettings () (at Assets/Magicolo/AudioTools/PureData/PureDataBridge.cs:46)
Magicolo.AudioTools.PureDataBridge.StartLibPD () (at Assets/Magicolo/AudioTools/PureData/PureDataBridge.cs:25)
Magicolo.AudioTools.PureDataBridge.Start () (at Assets/Magicolo/AudioTools/PureData/PureDataBridge.cs:50)
PureData.StartAll () (at Assets/Magicolo/AudioTools/PureData/PureData.cs:141)
PureData.Initialize () (at Assets/Magicolo/AudioTools/PureData/PureData.cs:58)
PureData.Awake () (at Assets/Magicolo/AudioTools/PureData/PureData.cs:173)

Visual studio警告x 50左右:

Warning CS0436  The type 'LibPD' in 'D:'unity projects'libpdinunity'Assets'Magicolo'AudioTools'PureData'LibPD'LibPdNativeUnity.cs' conflicts with the imported type 'LibPD' in 'LibPDBinding, Version=0.3.0.177, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'D:'unity projects'libpdinunity'Assets'Magicolo'AudioTools'PureData'LibPD'LibPdNativeUnity.cs'.   libpdinunity.CSharp D:'unity projects'libpdinunity'Assets'Magicolo'AudioTools'PureData'PureDataCommunicator.cs  87  Active

再次感谢您的帮助。感谢。

HowTo: uPD with unity 5

查看您的错误,libpdcsharp目前位于<ProjectDirectory>/Assets/Magicolo/AudioTools/PureData/Plugins/

这个DLL文件应该放在<ProjectDirectory>/Asset .

另外,确保用编译libpdcsharp。NET 2.03.5。如果使用编译,这将不起作用。. NET 4.0及以上版本

我是LibPD c#绑定的维护者。

您还需要将链接更改为正确的libwinpthread-1.dll版本(64位而不是32位)。在你的期末项目中,你需要所有3个dll:

    libpbinding .dll(托管包装器)
  • libpdcsharp.dll(本机dll)
  • libwinpthread-1.dll(用于在Windows上启用POSIX线程)

还有:你试过NuGet的版本吗?无需编译自己的绑定版本。

EDIT:您的警告来自不同的来源:您有两个名为LibPD的类,并且c#编译器不知道该使用哪个。

我不确定这些类型是否在同一个命名空间中。

如果它们在相同的命名空间中,则更改您的命名空间。

如果它们在不同的命名空间中,如果您想使用NuGet的版本,则添加using LibPd = LibPDBinding.LibPD;行,如果您想使用您的版本,则添加using LibPd = <yournamespace>.LibPD;行。

它在工作。uPD github代码有一个错误,据我所知。但愿它能修好。与此同时,我只是从头开始这个过程,这就是我在unity 5中获得uPD测试场景的方法:

  1. 从github获取uPD。这里有一个unity包
  2. 从github获取libPD。按照libPD github页面上的说明编译x64libpdcsharp.dll版本
  3. 将unity项目中现有的libpdcsharp.dll替换为你编译的x64版本
  4. 在libpd文件中找到libpd'libs'mingw64'libwinthread-1.dll把它放在你的unity项目中——和其他DLL放在同一个地方就可以了。我我不认为你把Dll放在哪里很重要(至少它没有
  5. 运行项目,注意你得到一个错误在统一EntryPointNotFoundException: libpd_safe_init
  6. 双击错误,打开问题脚本。[DllImport("libpdcsharp", EntryPoint="libpd_safe_init")]
  7. 将其更改为[DllImport("libpdcsharp", EntryPoint="libpd_init")]这是libpdcsharp中init函数的真正入口点。我不知道libpd_safe_init是什么。

感谢帮助我排除故障并找到问题的贡献者!