WPF에 Unity를 UnityWebPlayer 를 사용하지 않고 포함시키는 법에 대해서 정리해둔 중국(중국인들 코딩실력 무섭따오) 사이트의 내용을 구글신과 협동하여 번역, 정리해둔 게시글입니다.

중국어를 하나도 모르기 때문에 번역이 매우 미흡하나 프로젝트를 하시는데 도움이 되기를 바랍니다.




설명

이러한 요구 사항은 -편집자, 모두 쉽게 정적 데이터 테이블의 다양한 (엑셀) 를 편집하여 얻을 뿐만 아니라, (척추 골격 애니메이션) 미리보기 표에 지정된 리소스에 있습니다.

질문 등 WPF, WinForm, 표 편집기 소프트웨어 프레임 워크에 적합하며 해당하는 척추는 라이브러리를 렌더링하지 않습니다. 그리고 척추 프레임 등 Unity3D, MonoGame, Cocos2D 등, 또는 좋은 엑셀 데이터베이스 소프트웨어의 존재 또는 부족 문제를 제어 할 경우

우리는 프로그램이 소프트웨어 기능이 좋은 수 있도록 WPF 를 사용 하는 것입니다. 그리고 Unity 컨트롤을 렌더링하여 사용합니다.


기술 로드맵

WPF 에 UnityWebPlayer 를 포함하면되지 왜?

유니티는 WPF (또는 WinForm) 에 포함 된 ActiveXUnityWebPlayer 실제 컨트롤에 포장됩니다. 일반적인 관행입니다. 그러나 UnityWebPlayer 는 적어도 다음과 같은 두 가지 질문이 보안 샌드 박스에서 실행되기 때문이다. : 

  • 어떤 System.IO 어셈블리, Assetbundle 를 로드 할 수 없고, 파이프 라인은 전처리 척추없이 로드되지 수 없습니다. (먼 소리인지 모르것으나, 아마 파이프 라인을 Web .Net에서 사용하지 못한다는 것을 말하는것 같습니다.)
  • Excel 파일을 로드 할 수 없습니다.

어떻게 Unity Windows Standalone 을 WPF 에 삽입하는 방법

다음 WPF 부모 창을 지정하는 제어와 같은 독립을 달성하기 위해 WindowsAPI 를 사용합니다.


WPF Standalone 양방향 통신을 달성하는 방법

독립이 필요한 WPF Spine 에 전류를 설정 할 수 있고 또한 독립에 엑셀의 WPF 유지 보수에 의해 운영 될 수 있다. 한 가지 가능한 해결책은 파이프입니다.

이 논의는초기화 하지 않는 Unity NamedPipelineServer 에 대해서 논의한다. NamePipelineClient 은 뿐만 아니라 그것을 사용하는 법에 논의하였다.


Unity Windows Standalone WPF에 가져가기 

핵심코드는 다음과 같습니다. : 

// 독립 윈도우의 치수를 정의하는 WPF 사용자 컨트롤을 정의

1
2
3
4
5
6
7
8
9
10
11
12
ProcessStartInfo info = new ProcessStartInfo(“UnityControl.exe”);
info.UseShellExecute = true;
info.WindowStyle = ProcessWindowStyle.Minimized;
m_AppProcess = System.Diagnostics.Process.Start(info);
m_AppProcess.WaitForInputIdle();
this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle,appIdleEvent, thisnull);
// Application Idle
WindowInteropHelper helper = new WindowInteropHelper(Window.GetWindow(this));
IntPtr ptr = helper.Handle;
SetParent(app.MainWindowHandle, helper.Handle);
SetWindowLong(new HandleRef(this, app.MainWindowHandle), GWL_STYLE, WS_VISIBLE);
MoveWindow(app.MainWindowHandle, (int)control.Margin.Left, (int)control.Margin.Top, (int)control.Width, (int)control.Height, true);
cs


Unity Windows Standalone 및 WPF 통신을 달성

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// WPF
NamedPipeServerStream pipeServer = new NamedPipeServerStream(
    "testpipe"
    PipeDirection.InOut, 
    1);
pipeServer.WaitForConnection();
 
string str = "hello from server!";
byte[] outBuffer = Encoding.Unicode.GetBytes(str);
int len = outBuffer.Length;
pipeServer.WriteByte((byte)(len / 256));
pipeServer.WriteByte((byte)(len % 256));
pipeServer.Write(outBuffer, 0, len);
pipeServer.Flush();
 
len = pipeServer.ReadByte() * 256;
len += pipeServer.ReadByte();
byte[] inBuffer = new byte[len];
pipeServer.Read(inBuffer, 0, len);
string remoteInfo = Encoding.Unicode.GetString(inBuffer);
 
lbRemoteInfo.Content = remoteInfo;
 
// Unity 
pipeClient = new NamedPipeClientStream(
    ".""testpipe"
    PipeDirection.InOut);
pipeClient.Connect(10000);
 
int len = pipeClient.ReadByte() * 256;
len += pipeClient.ReadByte();
byte[] inBuffer = new byte[len];
pipeClient.Read(inBuffer, 0, len);
remoteInfo = Encoding.Unicode.GetString(inBuffer);
 
pipeClient.Flush();
string str = "hello from client!";
byte[] outBuffer = Encoding.Unicode.GetBytes(str);
len = outBuffer.Length;
pipeClient.WriteByte((byte)(len / 256));
pipeClient.WriteByte((byte)(len % 256));
pipeClient.Write(outBuffer, 0, len);
pipeClient.Flush();
 
cs


결과

좋은 결과를 보이는 간단한 테스트를 수행합니다 : 

  • Unity ( Client ) 가 WPF ( Server ) Window 에 내장되어
  • WPF는 "hello from server!" 보내고 Unity 컨트롤 화면의 왼쪽 상단 모서리에 
  • WPF Unity 는 "hello from client!" 를 전송하여 WPF의 라벨에 표시한다.


지침 및 참조

MSDN 통신 채널 Demo

프로세스 간 통신 네트워크에 대한 명명된 파이프를 사용하는 방법


Mono 파이프 라인의 안전성 레벨을 지원하지 않는다.

그게 없으면, NamedPipeServerStream 생성자, TokenImpersonationLevel 를 기입하지 않습니다.

StackOverflow


Unity에서 NamedPipelineServer를 사용 할 수 없습니다.

NamePipelineClient 을 사용할 수 있습니다.

StackOverflow


Unity 에서 System.IO.Pipes 네임 스페이스를 사용

플레이어 설정, .NET 버전에서 .net2.0 을 .net2.0 subset 로 바꾼다.

StackOverflow


Windows 에Unity 를 포함하는 방법

2015/07/09 - [잡다한 자료(번역)/WinForm+Unity3D] - C# WinForm에 다른 응용 프로그램을 포함 형성하는 법.




이로써 WPF 에 Unity 를 포함시키는 방법이 끝났습니다.

원본 사이트는 : WPF内嵌Unity并实现双向通讯

에서 더욱 자세한 내용.... 은 잘 모르겠고 원본 내용을 보실 수 있습니다.


감사합니다.








  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기