当前位置: 首页 > news >正文

网站申请支付宝支付南昌seo网站排名

网站申请支付宝支付,南昌seo网站排名,简单网站建设优化,专做polo衫的网站上一篇文章中我使用UnrealSharp成功使用了我的一个C#控制台程序中的网络模块,这个程序是基于KCP网络了,其中调用了Cmake 编译的一个C的DLL,在虚幻中DLL需要放在Binaries目录中才可以。Unity中只要放在任意Plugins目录中就可以。 但是Binaries…

上一篇文章中我使用UnrealSharp成功使用了我的一个C#控制台程序中的网络模块,这个程序是基于KCP网络了,其中调用了Cmake 编译的一个C++的DLL,在虚幻中DLL需要放在Binaries目录中才可以。Unity中只要放在任意Plugins目录中就可以。
但是Binaries目录版本控制一般不提交,我们可以改一下,改成按照路径加载。

修改前的脚本

using System.Runtime.InteropServices;//脚本修改自//https://github.com/a11s/kcp_warppernamespace NetLibrary
{public unsafe class KCP{const string LIBNAME = "libikcp.dll";//---------------------------------------------------------------------// interface//---------------------------------------------------------------------/// <summary>/// create a new kcp control object, 'conv' must equal in two endpoint/// from the same connection. 'user' will be passed to the output callback/// output callback can be setup like this: 'kcp->output = my_udp_output'/// </summary>/// <param name="conv"></param>/// <param name="user"></param>/// <returns></returns>[DllImport(LIBNAME, EntryPoint = "ikcp_create", CallingConvention = CallingConvention.Cdecl)]public static extern IKCPCB* ikcp_create(uint conv, void* user);/// <summary>/// release kcp control object/// </summary>/// <param name="kcp"></param>[DllImport(LIBNAME, EntryPoint = "ikcp_release", CallingConvention = CallingConvention.Cdecl)]public static extern void ikcp_release(IKCPCB* kcp);/// <summary>/// set output callback, which will be invoked by kcp///public static extern void ikcp_setoutput(IKCPCB* kcp, int (* output)(byte* buf, int len,             ikcpcb *kcp, void* user));/// </summary>/// <param name="kcp"></param>/// <param name="d_output"></param>[DllImport(LIBNAME, EntryPoint = "ikcp_setoutput", CallingConvention = CallingConvention.Cdecl)]public static extern void ikcp_setoutput(IKCPCB* kcp, System.IntPtr d_output);

篇幅太大没有必要,只展示部分代码片段。
可以看到之前是通过DllImport 载入LIBNAME变量来载入DLL的。

改为动态路径

先放上所有改动

// 动态获取库路径
private static string GetLibraryPath()
{string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;//动态库的路径被拼接到 Binaries\Managed\Third\libikcp.dll,而你的实际库文件存放在 E:\myproject\Third\libikcp.dll,这说明 AppDomain.CurrentDomain.BaseDirectory 返回的路径是 Binaries\Managed。baseDirectory = Path.Combine(baseDirectory, "../../");string relativePath;// 根据平台选择库路径if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)){relativePath = "ThirdParty/Kcp/Win64/libikcp.dll";}else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID"))){relativePath = "ThirdParty/Kcp/Android/arm64-v8a/libikcp.so";}else{throw new PlatformNotSupportedException("Unsupported platform");}return Path.Combine(baseDirectory, relativePath);
}// DllImport 使用动态路径
private const string LIBNAME = "PLACEHOLDER"; // 占位符
private static bool _isResolverSet = false;
// 添加初始化方法以动态设置路径
public static void Initialize()
{if (_isResolverSet){Loger.Debug($"BSserver DLL: 已经加载过了 .");return;}try{string libraryPath = GetLibraryPath();//Loger.Error($"BSserver DLL:{libraryPath}");NativeLibrary.SetDllImportResolver(typeof(KCP).Assembly, (name, assembly, path) =>{if (name == LIBNAME){return NativeLibrary.Load(libraryPath);}return IntPtr.Zero;});_isResolverSet = true;}catch(Exception e) {//AClientMain.inst.PrintString("C# : DLL:" + libraryPath);Console.WriteLine($"Loaded library 加载错误 ."+e.Message);Loger.Error($"BSserver DLL 加载错误 : " + e.Message);}}
//const string LIBNAME = "libikcp.dll";
//---------------------------------------------------------------------
// interface
//---------------------------------------------------------------------/// <summary>
/// create a new kcp control object, 'conv' must equal in two endpoint
/// from the same connection. 'user' will be passed to the output callback
/// output callback can be setup like this: 'kcp->output = my_udp_output'
/// </summary>
/// <param name="conv"></param>
/// <param name="user"></param>
/// <returns></returns>
[DllImport(LIBNAME, EntryPoint = "ikcp_create", CallingConvention = CallingConvention.Cdecl)]
public static extern IKCPCB* ikcp_create(uint conv, void* user);/// <summary>
/// release kcp control object
/// </summary>
/// <param name="kcp"></param>
[DllImport(LIBNAME, EntryPoint = "ikcp_release", CallingConvention = CallingConvention.Cdecl)]
public static extern void ikcp_release(IKCPCB* kcp);

使用方法:
我们在UE的工程下创建目录ThirdParty,按照代码里的路径,把DLL放进去,按照不同平台。

在加载DLL之前,我们需要调用Initialize方法初始化动态设置路径就可以了。

这些代码是ChatGPT帮忙写的,经过几次修改有了这段代码。

小技巧

以前是内事不决问baidu,外事不决问google,现在是内事问豆包,外事问ChatGPT。 :)
但是小心AI一本正经的胡说八道。 :P

http://www.dt0577.cn/news/5922.html

相关文章:

  • 北京正规网站建设公司网页设计与制作个人网站模板
  • 青岛煜鹏网站建设公司品牌策划包括哪几个方面
  • 政府网站建设培训心得各网站收录
  • 晋江做任务的网站谷歌优化教程
  • 做网站赚广告费多么徐州网站关键词排名
  • 公安网站备案公司做网络推广哪个网站好
  • 茂名快速建站模板网站建设优化推广系统
  • 网站建设需要的功能腾讯企点app
  • 国企网站建设方案360优化大师官方免费下载
  • 评网网站建设内容营销成功案例
  • 网站水印设置作教程网络营销模式有哪些类型
  • WordPress修改注册界面网站排名优化
  • 做海岛旅游预定网站的seo
  • 网站如何做中英文效果百度客服电话人工服务热线
  • 微信公众平台可以导入wordpressseo推广优化公司哪家好
  • 做网站是什么课武汉网站seo推广
  • 网站翻页模板十大免费b2b网站
  • 淄博学校网站建设报价体验营销案例
  • 寮步营销型网站建设石家庄seo代理商
  • wordpress点击弹出层插件建站优化推广
  • 怎么建设微信二维码发在网站上软件开发公司联系方式
  • 肯德基的网站建设整站优化要多少钱
  • whois哪个网站好网站备案查询
  • 深圳网站建设制作品牌公司四川最好的网络优化公司
  • 莱芜百度网站制作比百度好用的搜索引擎
  • 两个网站做的h5如何合在一起分销平台
  • 如何建设好幼儿园网站免费建网站哪家好
  • 聊城专业做网站的公司深圳网络推广的公司
  • 金猪云高端网站建设自动优化app
  • 网站建设个体营业执照营业推广的目标通常是