简体   繁体   English

如何将 MySql 连接器导入 Unity 项目?

[英]How do I import MySql Connector into Unity Project?

  • I've tried placing the basic dll's into unity's assets folder - Result: "blah blah will cause Unity to Crash Error."我试过将基本的 dll 放入统一的资产文件夹 - 结果:“等等等等会导致 Unity 崩溃错误。”
  • I've tried Manually adding references - Result: Unity refreshes its references anytime the editor refreshes, so worthless.我试过手动添加引用 - 结果:Unity 会在编辑器刷新时刷新其引用,因此毫无价值。
  • I've tried Installing using NuGet - Result: Closest to success as it handles all the dependencies and whatnot but I get: Assets/Scripts/Developing/TalkToDB.cs(3,7): error CS0246: The type or namespace name `MySql' could not be found.我试过使用 NuGet 安装 - 结果:最接近成功,因为它处理所有依赖项等等,但我得到:Assets/Scripts/Developing/TalkToDB.cs(3,7): error CS0246: The type or namespace name `MySql ' 找不到。 Are you missing an assembly reference?您是否缺少程序集参考?

Is it some kind of a combination of "Use NuGet then copy the dll into the Assets?"它是“使用 NuGet 然后将 dll 复制到资产中”的某种组合吗? or something redundant like that?或者像那样多余的东西? cause that's about the best guess I've got.因为这是我得到的最好的猜测。


Also, I've tried a couple older versions of the NuGet package to no avail.另外,我尝试了几个旧版本的 NuGet 包,但无济于事。 As well, MySql.Data is listed under the References of "Assembly-CSharp" And my Unity is set to 4.X framework Using Unity's latest 2018.2.5f1 (64bit) (I really hope that I don't have to ditch 4.x for this to work... I'll miss initializing values to properties..)同时,MySql.Data“集结号-CSHARP”的参考文献中列出我的统一设置为4.X框架使用Unity的最新2018.2.5f1(64位)(我真希望我没有沟4。 x 为此工作......我会想念初始化属性的值......)

Fortunately I came across this:幸运的是我遇到了这个:

How to get MySql Connector/Net Working with Unity 2017如何让 MySql 连接器/网络与 Unity 2017 一起工作

And Regarding Security concerns.以及关于安全问题。 My Key is none of my sessions should ever be persistent from .NET - There will be advanced PHP scripts for altering of data and anything regarding elevated permissions.我的关键是我的任何会话都不应该从 .NET 持久化 -将有高级 PHP 脚本用于更改数据和任何有关提升权限的内容。

Reference: Why you shouldn't connect your mobile application to a database参考: 为什么不应该将移动应用程序连接到数据库

Beyond this,超出此,

Exceptions to the rule.规则的例外。

"Some database vendors may have provided drivers to connect to remote databases, but as yet I'm not aware of any. “一些数据库供应商可能已经提供了连接到远程数据库的驱动程序,但我还不知道有任何驱动程序。

Other exceptions include ODBC connectivity.其他例外情况包括 ODBC 连接。 For example, I've heard of developers being able to (or at least trying to) connect to MySQL databases using JDBC when developing applications in Java.例如,我听说开发人员在用 Java 开发应用程序时能够(或至少尝试)使用 JDBC 连接到 MySQL 数据库。 This is not actually quite the same as connecting directly using a binary driver, however, it comes close..." - 2这实际上与使用二进制驱动程序直接连接并不完全相同,但是,它很接近......” - 2

This is exactly what I will be doing, using the MySql Connector to talk to MySql drivers (which I'm too tired at the moment to recall the name of (maybe it's based on ODBC? I can't remember. Thus Google. Lol))这正是我将要做的,使用MySql 连接器与 MySql 驱动程序交谈(我现在太累了,想不起来它的名字(也许它是基于 ODBC?我不记得了。因此谷歌。大声笑) ))

So all in all, using the link provided at the top, Unity 2018 can be compatible with the latest (as of this post) MySql Connector(s) .总而言之,使用顶部提供的链接,Unity 2018 可以与最新的(截至本文) MySql Connector(s)兼容。

Any Assets folder must contain: System.Data.dll & MySql.Data.dll (that's it)任何 Assets 文件夹都必须包含:System.Data.dll & MySql.Data.dll(就是这样)

No NuGet required.不需要 NuGet。

However the error message: "Loading script assembly 'Assets/Plugins/MySql/System.Data.dll' failed!"但是错误消息:“加载脚本程序集 'Assets/Plugins/MySql/System.Data.dll' 失败!” And as of yet, it is apparently not able to reference connectionString from an app.config like your normal C# outside of Unity would be able to.到目前为止,它显然无法像 Unity 之外的普通 C# 那样从 app.config 引用 connectionString。 This being said, I'm working on finding either Unity's implementation of the app.config, or an equivalent alternative.话虽如此,我正在努力寻找 Unity 的 app.config 实现,或等效的替代方案。


UPDATE:更新:

Aside from a couple annoying dll loading errors in Unity that don't influence anything - other than annoying me and wasting a couple bytes of RAM for a second (lol, y'kno.);除了 Unity 中的几个烦人的 dll 加载错误之外,它们不会影响任何事情——除了让我烦恼和浪费几字节的 RAM 一秒钟(哈哈,你知道); All works well and I remember the reason I am not concerned about connecting my application directly to my Database is because the ONLY permissions the users will have is the Execute permission so all procedures will be stored on the server (via Stored Procedures) and thus protecting the database against any potential attacks even if cough cough when cough ahem, a user decides to "de-compile" (is that even a word...? heh) my application.一切正常,我记得我不担心将我的应用程序直接连接到我的数据库的原因是因为用户将拥有的唯一权限是执行权限,因此所有过程都将存储在服务器上(通过存储过程),从而保护数据库抵御任何潜在的攻击,即使咳咳咳咳咳咳咳咳,用户决定“反编译”(甚至是一个词...?呵呵)我的应用程序。


Final Update:最终更新:

As I posted here ;正如我在这里发布的那样;

It took me a week to finally figure it out...我花了一个星期终于弄明白了......

You need to use:您需要使用:

 I18N.dll I18N.West.dll I18N.*.dll (Optional, they are region specific) System.Data.dll

from C:\\Program Files\\Unity\\Editor\\Data\\Mono\\lib\\mono\\2.0来自 C:\\Program Files\\Unity\\Editor\\Data\\Mono\\lib\\mono\\2.0

NOT the BleedingEdge path.不是 BleedingEdge 路径。 Then it will work without errors [And in Builds]... confirmed in the latest Unity 2018.2.14f1 Place into the Assets folder - Also the project needs to be set to .Net 4.0然后它会正常工作[并且在构建中]...在最新的 Unity 2018.2.14f1 中确认放置到 Assets 文件夹中 - 此外项目需要设置为 .Net 4.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM