UDKは.NETを使用しています。 UnrealScriptの.NETをどういうふうに使うことができるのでしょうか?
UnrealScriptでC#を使用するのは本当に素晴らしいことです。.NETをUnrealScriptで使用する
dllimportを使用する.NETとUnrealScriptの間でやりとりするC++レイヤを確かに構築できますが、この質問の対象ではありません。
UDKは.NETを使用しています。 UnrealScriptの.NETをどういうふうに使うことができるのでしょうか?
UnrealScriptでC#を使用するのは本当に素晴らしいことです。.NETをUnrealScriptで使用する
dllimportを使用する.NETとUnrealScriptの間でやりとりするC++レイヤを確かに構築できますが、この質問の対象ではありません。
.NETライブラリをUnrealScriptから直接アクセスする方法はないようですが、[DllExport] extension for C#とUnrealScript interopシステムを組み合わせて、中間のC++ラッパーなしで.NETとやりとりすることができます。
int、string、構造体と交換し、C#でUnrealScript Stringを埋め替えるという簡単な例を見てみましょう。
1のUnrealScript側
3 [\バイナリ\のWin32 \ USERCODE](またはWin64の)にUDKManagedTest.dllと場所として、たとえば、C#コードをコンパイル
using System;
using System.Runtime.InteropServices;
using RGiesecke.DllExport;
namespace UDKManagedTestDLL
{
struct TestStruct
{
public int Value;
}
public static class UnmanagedExports
{
// Get string from C#
// returned strings are copied by UnrealScript interop system so one
// shouldn't worry about allocation\deallocation problem
[DllExport("GetString", CallingConvention = CallingConvention.StdCall]
[return: MarshalAs(UnmanagedType.LPWStr)]
static string GetString()
{
return "Hello UnrealScript from C#!";
}
//This function takes int, squares it and return a structure
[DllExport("GetStructure", CallingConvention = CallingConvention.StdCall]
static TestStructure GetStructure(int x)
{
return new TestStructure{Value=x*x};
}
//This function fills UnrealScript string
//(!) warning (!) the string should be initialized (memory allocated) in UnrealScript
// see example of usage below
[DllExport("FillString", CallingConvention = CallingConvention.StdCall]
static void FillString([MarshalAs(UnmanagedType.LPWStr)] StringBuilder str)
{
str.Clear(); //set position to the beginning of the string
str.Append("ha ha ha");
}
}
}
2 C#クラスを作成します関数の宣言を配置する必要があります。
class TestManagedDLL extends Object
DLLBind(UDKManagedTest);
struct TestStruct
{
int Value;
}
dllimport final function string GetString();
dllimport final function TestStruct GetStructure();
dllimport final function FillString(out string str);
DefaultProperties
{
}
次に関数を使用できます。
FillStringメソッドで表示されているように、UDK文字列を埋めるのが唯一のトリックです。固定長バッファーとして文字列を渡すので、この文字列を初期化しなければなりません。初期化された文字列の長さは、C#が動作する長さ以上でなければならない(MUST)。
更なる読みはhereであることが判明した。
これは理論的に質問に答えるかもしれませんが、(http://meta.stackexchange.com/q/8259)ここでの答えの本質的な部分、および参考のためのリンクを提供します。 – BoltClock
私は数時間後にやります! (今の就業時間があります) – MajesticRa
@BoltClockの例が追加されました。 – MajesticRa
".NETをUnrealScriptから使用する"という意味を説明できますか?例やユーザーの話をする。 –
には、ネイティブC/C++ラッピングのない.NETライブラリの「dllimport」があります。または、UnrealScriptと.NETの間の他の種類の通信を直接(C++ラッピングを作成せずに)持っている – MajesticRa