- Home /
is it possible to use Unity inside wpf
Hi, I would like to make an program using Unity and WPF component.
Basically, The program shows 3d Object using Unity engine inside the frame
which has several components from WPF.
so the main frame is made by "WPF", inside main frame(WPF), we would like to use
unity engine. I've watched some videos from Youtube,
they show me that we are able to use WPF components inside unity program.
it seems like using a special tool, but I have no idea about it
is that possible? if so, how would I like to do this? Thank you =) (Sorry for my English, Eng is my 2nd language, so some grammar mistakes might exist)
I am also looking for the same kind of solution. Have you found anything?
Answer by RobW81 · Aug 25, 2012 at 08:28 PM
You can do this by getting Unity Handle and setting the Control's handle to Unity's handle with SetParent(). You will also need to call SetWindowLong() to hide the border of the Unity window and you might also need to position the Unity window at the top left of the control by calling MoveWindow().
If you don't know what I mean here is the sample code below. This starts Unity waits for the process to load and parents it to the control UnityPanel which is a Panel. Then removes the boarder from the window and positions Unity at the top left corner of the control. You will want to make sure that you run your game in window mode.
mUnityProcess = Process.Start(mUnityStartInfo); mUnityProcess.WaitForInputIdle(); mUnityHandle = mUnityProcess.MainWindowHandle; SetParent(mUnityProcess.MainWindowHandle, UnityPanel.Handle); SetWindowLong(mUnityHandle, GWL_STYLE, WS_VISIBLE); MoveWindow(mUnityHandle, 0, 0, UnityPanel.ClientSize.Width, UnityPanel.ClientSize.Height, true);
Answer by lcairco · Aug 13, 2014 at 03:15 PM
Here is another good starting place:
http://stackoverflow.com/questions/6477851/how-to-run-an-application-inside-wpf-application
Answer by Drunken-Monkey · Jun 14, 2012 at 04:23 PM
Are you sure the "Unity" in the video is in fact Unity3D? Microsoft has a .NET product called Unity (contained in PRISM). It has nothing to do with games, but used for dependency injection.
Well you might be able to make the web client run inside a WPF app - using some kind of embedded browser perhaps?
Answer by Cthaeh23 · Mar 12, 2017 at 07:36 PM
Just in case someone stumbles on this old question like me: I used this custom control: https://www.codeproject.com/Tips/673701/Hosting-EXE-Applications-in-a-WPF-Window-Applicati
But you have to change some code to make everythink work smoothely. To position Unity right (if unity should not be in the upper left corner of youre window):
Point position = this.TranslatePoint(new Point(0f, 0f), Window.GetWindow(this)); MoveWindow(_appWin, (int)(position.X scalingFactor), (int)(position.Y scalingFactor), (int)(ActualWidth scalingFactor), (int)(ActualHeight scalingFactor), true); ´ And to aquiere the handle when unity takes some time to load:
//Wait to aquire handle. _childp.WaitForInputIdle(); while (_childp.MainWindowHandle == IntPtr.Zero) { Thread.Sleep(10); }
For the communication between Unity and WPF I used TcpListener If done right this is fast enough to send data back and forth every frame.
Your answer
Follow this Question
Related Questions
What's my unity version? 1 Answer
Mathf.pingpong 4 Answers
getting high score of game from asp.net page 2 Answers
,Roll a ball - project 0 Answers
Prevent a Character Model to pass through another object 1 Answer