2011-07-27 6 views
0

UDK는 .NET을 사용합니다. UnrealScript에서. NET을 어떻게 든 사용할 수 있습니까?
UnrealScript에서 C#을 사용하는 것은 정말 좋습니다..NET을 UnrealScript와 함께 사용

dllimport을 사용하는 .NET과 UnrealScript간에 상호 작용할 수있는 C++ 레이어를 확실히 만들 수 있지만이 질문의 대상이 아닙니다.

+0

".NET을 UnrealScript에서 사용"이란 의미를 설명 할 수 있습니까? 예제 또는 사용자 스토리를 제공하십시오. –

+0

에는 네이티브 C/C++ 래핑없이 .NET 라이브러리가있는 'dllimport'가 있습니다. 또는 UnrealScript와 .NET 간의 다른 종류의 통신 (C++ 래핑을 만들지 않고)을 직접 수행하십시오. – MajesticRa

답변

5

.NET 라이브러리를 UnrealScript에서 직접 액세스 할 수있는 방법은 없지만 [DllExport] extension for C#과 UnrealScript interop 시스템을 결합하여 중간 C++ 래퍼없이 .NET과 상호 작용할 수 있습니다.

int, string, structure로 바꾸고 C#에서 UnrealScript String을 채우는 간단한 예를 살펴 보겠습니다.

1 말하자면 컴파일 C# 코드를 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 UDKManagedTest.dll 같은 장소에 [\ 바이너리 \는 Win32 \ UserCode (또는 Win64를) 언리얼 측면

3 함수의 선언을 배치해야합니다.

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입니다.

+0

이론적으로 질문에 대답 할 수 있지만 (http://meta.stackexchange.com/q/8259) 대답의 핵심 부분을 참조 용으로 제공하십시오. – BoltClock

+0

좋습니다! 나는 몇 시간 후에 그것을 할 것이다! (현재 업무 시간 있습니다) – MajesticRa

+0

@BoltClock 예가 추가되었습니다. – MajesticRa