PTT
Submit
Submit
選擇語言
正體中文
简体中文
PTT
GameDesign
Re: [程式] Unity scripting (native plugin)
作者:
riveranb
(River)
2017-12-26 09:37:38
※ 引述《riveranb (River)》之銘言:
: 標題: [程式] Unity scripting (native plugin)
:
: 以下是我的 sample codes
:
: ==== C++ native plugin部分 ====
: extern "c" declspec(dllexport) void cppfunc( char * tostring, int maxlen)
: {
: std::string source = .... // get texts from opened file
: if(source.length() < maxlen)
: {
: strcpy(tostring, source.c_str());
: }
: }
:
: ==== Unity C# script部分 ====
: [DllImport ("CppPlugin")]
: static extern void cppfunc(StringBuilder tostring, int maxlen);
:
: ......
:
:
: {
: {
: StringBuilder thestring = new StringBuilder(_maxlen); // maxlen = 64
: StringBuilder thestring = new StringBuilder(_maxlen); // maxlen = 64
: while( /** if more in file **/ )
: while( /** if more in file **/ )
: {
: #if METHOD1
: thestring = new StringBuilder(_maxlen); // method 1, always correct
: #else if METHOD2
: thestring.Length = 0; // method 2, get wrong strings after several calls
: #endif
: CppInterop.cppfunc(thestring, _maxlen);
: }
: }
:
:
作者:
cjcat2266
(CJ Cat)
2017-12-26 12:46:00
嗯,是我的話也會用byte[],找不太到StringBuilder傳到之間的轉換,讓我感覺毛毛的,到底是怎麼把內部buffer傳過去不是很明白,如果有其他人找到資料拜託分享一下另外,需要同時設定Length和Capacity這樣好像沒有治本底層應該還是會重新配置新的buffer記憶體還有,不更動StringBuilder會維持初次結果也很神祕可做個實驗,在C++把char*位址、初始值和結果值印出來
作者:
wulouise
(在線上!=在電腦前)
2017-12-30 10:32:00
找到的資料只有default-marshaling-for-stringsStrinbuilder本身就是一個buffer 所以給buffer之前必須設定好她的capacity
https://goo.gl/wxHzs2
根據這邊說法 SB只有在放不下新資料的時候才會reallocate memory XDDD過unmanaged code的話她一定不知道建議你用新的sb 或是參考
https://goo.gl/7Tp3Qm
繼續閱讀
[程式] Unity scripting (native plugin)
riveranb
[遊戲] XenoTower Prototype試玩
tim099
[情報] 桌遊設計大賽說明會問卷
wolfuni
[情報] 《永恆的賽妮亞-雨後的紫陽花》正式推出
domodsc
[請益] Unity在iOS上的splash被黑塊遮住
sirius65482
[程式] Unity壓縮&伸展特效工具包 送件素材商店
cjcat2266
[請益] Unity 的 dll
gn00618777
[請益] Unity assetstore收費
Brian23
[程式] 如何限制遊戲幀數
SecondRun
[請益] unity 調用手機相機的色差
bantime
Links
booklink
Contact Us: admin [ a t ] ucptt.com