中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

淄博周村網(wǎng)站建設(shè)哪家好杭州網(wǎng)絡(luò)推廣

淄博周村網(wǎng)站建設(shè)哪家好,杭州網(wǎng)絡(luò)推廣,臨清做網(wǎng)站推廣,徐州網(wǎng)站開發(fā)信息上一篇文章中我使用UnrealSharp成功使用了我的一個C#控制臺程序中的網(wǎng)絡(luò)模塊,這個程序是基于KCP網(wǎng)絡(luò)了,其中調(diào)用了Cmake 編譯的一個C的DLL,在虛幻中DLL需要放在Binaries目錄中才可以。Unity中只要放在任意Plugins目錄中就可以。 但是Binaries…

上一篇文章中我使用UnrealSharp成功使用了我的一個C#控制臺程序中的網(wǎng)絡(luò)模塊,這個程序是基于KCP網(wǎng)絡(luò)了,其中調(diào)用了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的。

改為動態(tài)路徑

先放上所有改動

// 動態(tài)獲取庫路徑
private static string GetLibraryPath()
{string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;//動態(tài)庫的路徑被拼接到 Binaries\Managed\Third\libikcp.dll,而你的實際庫文件存放在 E:\myproject\Third\libikcp.dll,這說明 AppDomain.CurrentDomain.BaseDirectory 返回的路徑是 Binaries\Managed。baseDirectory = Path.Combine(baseDirectory, "../../");string relativePath;// 根據(jù)平臺選擇庫路徑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 使用動態(tài)路徑
private const string LIBNAME = "PLACEHOLDER"; // 占位符
private static bool _isResolverSet = false;
// 添加初始化方法以動態(tài)設(shè)置路徑
public static void Initialize()
{if (_isResolverSet){Loger.Debug($"BSserver DLL: 已經(jīng)加載過了 .");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的工程下創(chuàng)建目錄ThirdParty,按照代碼里的路徑,把DLL放進去,按照不同平臺。

在加載DLL之前,我們需要調(diào)用Initialize方法初始化動態(tài)設(shè)置路徑就可以了。

這些代碼是ChatGPT幫忙寫的,經(jīng)過幾次修改有了這段代碼。

小技巧

以前是內(nèi)事不決問baidu,外事不決問google,現(xiàn)在是內(nèi)事問豆包,外事問ChatGPT。 :)
但是小心AI一本正經(jīng)的胡說八道。 :P

http://m.risenshineclean.com/news/65978.html

相關(guān)文章:

  • 做網(wǎng)站設(shè)計提成賺錢嗎百度百度一下官網(wǎng)
  • 動態(tài)網(wǎng)站開發(fā)心得體會百度推廣后臺登陸官網(wǎng)
  • 漳州網(wǎng)站建設(shè)點擊博大選百度云
  • 第3章營銷型企業(yè)網(wǎng)站建設(shè)開魯seo網(wǎng)站
  • 2020年新聞大事件長春網(wǎng)站seo公司
  • 蘭州網(wǎng)站建設(shè)公司排名網(wǎng)絡(luò)營銷推廣的渠道有哪些
  • 上海閔行區(qū)租房價格杭州seo搜索引擎優(yōu)化
  • 網(wǎng)站怎么做反鏈網(wǎng)絡(luò)營銷推廣合同
  • 手機網(wǎng)站建設(shè)方案doc微信朋友圈推廣平臺
  • 網(wǎng)站維護是什么意思b站推廣網(wǎng)站入口mmm
  • 怎么做網(wǎng)站搜索引擎利于搜索競價惡意點擊報案
  • 展示型型網(wǎng)站建設(shè)營銷案例分析報告模板
  • 有什么好的免費網(wǎng)站做教育宣傳沈陽seo排名優(yōu)化教程
  • 帝國管理系統(tǒng)導(dǎo)入新的模板怎么建網(wǎng)站?正規(guī)推廣平臺有哪些
  • 商河 網(wǎng)站建設(shè)域名在線查詢
  • 政府網(wǎng)站源碼太原seo外包公司
  • 上海商場網(wǎng)站開發(fā)外貿(mào)營銷推廣
  • 網(wǎng)站設(shè)計的基本知識結(jié)構(gòu)公關(guān)服務(wù)
  • 游戲網(wǎng)站建設(shè)多少錢營銷策劃方案模板范文
  • 廣州市網(wǎng)站建設(shè) 駿域動力北京已感染上千萬人
  • 深圳企業(yè)網(wǎng)站建設(shè)制作網(wǎng)絡(luò)流量統(tǒng)計工具
  • 如何用word做網(wǎng)站西安網(wǎng)絡(luò)公司
  • 廣州網(wǎng)站建設(shè)推廣網(wǎng)絡(luò)營銷策劃
  • 114做網(wǎng)站同城推廣
  • 網(wǎng)站建設(shè)集團網(wǎng)站收錄提交
  • 武漢網(wǎng)站設(shè)計價格谷歌廣告上海有限公司官網(wǎng)
  • 不允許做企業(yè)網(wǎng)站百度官網(wǎng)認證
  • 如何介紹網(wǎng)站模板下載seo診斷方法步驟
  • 中國建設(shè)銀行網(wǎng)站官網(wǎng)網(wǎng)址關(guān)鍵詞快速優(yōu)化排名軟件
  • 廈門網(wǎng)站免費制作百度優(yōu)化培訓(xùn)