Using an exported project as a XAML UserControl
While I know that Unity projects are meant to run as stand-alone applications, I need to make something a little bit different and I need your help.
Basically I'd like to add a 3D scene to my app, which is not a brand new app so I can't start from scratch, and since an Unity exported project will run into a SwapChainPanel
I thought that I could just import it in my app and just use it.
This will be way easier than moving the project to Unity's exported solution.
Final goal will be to export & compile Unity project and just update DLLs + project data into my main app to update Unity scene.
I did some tests but I wasn't really lucky, so I feel that I'm missing something.
What I did was to copy all the references from the Unity exported project to my App project, then I moved assets and levels (keeping the same file structure) and finally I copied DLLs and Players folder.
Final result was the app crashing as soon as I loaded the page containing the SwapChainPanel
, with an error about missing renderer in game manager (sorry for not being 100% accurate, I don't have the project right now).
So, my question is: is there a way to export a Unity project as a XAML UserControl
so that I can just plug it into an already existing app? Being an UserControl
is not really mandatory, having it inside a page in my already existing page will be good for now, but I'd like to just use the Unity project inside my app.
Answer by InfiniBuzz · Oct 12, 2016 at 09:41 AM
What I was doing to embed a Unity application inside an application was the following:
Create WinForms control (should also work with WPF control, did not try that. if not use WinFormsHost)
Start unity process from code, passing the window handle with "-parentHWND" (see link)
Communicate to the process using IPC mechanisms
You can find more information about starting unity with commandline attributes on the linked page.
See the table almost at the end of the page (-parentHWND description), there is a little ZIP with an example project which was very helpful to me.
Depending on what "application" you have, the solution will be similar.
Regarding IPC i tried NamedPipes and SharedMemory with no luck so I'm currently sticking with TCP communication.
I also use DLLs from the Application and from within Unity. In order to do that I put the dll project output (dll file) inside the Unity assets so you can access it from unity c# code just as you would with other libraries.
It works but it is not very straight forward.
Answer by MRNA · Apr 18, 2017 at 09:21 AM
Thank you @InfiniBuzz
Your comments greatly helped to figure out how to use an unity application as a child app.
Truly, I have a small problem with the sample code. Since I am using Windows 10 Universal API, I can't generate executable exe app. The app should be either deployed or installed :(
Do you have any idea how I can bind app in Windows store API
Best Regards Reza
What exactly is the problem you are facing? I didn't try what you are trying so I don't know if or how it works. But if you give some error description or points you are stuck with, me or someone else could help you.
Let me explain it. I am developing an application based on Windows IoT environment and capabilities. therefore, I need to use UWP (universal windows presentation) API. by using the application I can read position of several nodes with wireless communication and I would like to use a 3D unity app attached to my main application.
Actually, there is an option in Unity to build for 3D design in Windows 10 environment (Windows Store) .
I tried to add the exported unity app into the main visual studio solution and use it as child xaml page. but I had two issues.
First, It seems the libraries are not compatible and I face with several errors. Second, the 3D objects property are not available in exported unity app. ( I guess the only solution is I have to use IPC)
Regards
Your answer
Follow this Question
Related Questions
UWP project can't handle dynamic type and cause crashes 0 Answers
Why after importing Standard Assets my Visual Studio Solution has 3 projects ? 1 Answer
Autocomplete in Visual Studio Code 3 Answers
VS Code or visual studio? 1 Answer
VisualStudio doesn't show code helpers in StateMachineBehaviour 0 Answers