WinForm Show Unity3d file can support the Unity3d implementation of the module packaging, as well as in other projects need to show the Unity3d interface, just to fit to open the display, here I show how to use WinForm to open the Unity3d file.
First, download and install unity on Unity's website
After the installation is complete, the following directories:
B. Locate the Unitywebpluginax.ocx file under the Unity/webplayer64/loader-x64 folder and drag it to the Windowform Toolbox.
Then drag it onto the form and add a button to add the SRC path dynamically (the Unitywebplayercontrol control does not support dynamic switch src By default, it can only be opened by default when initialized, and here we do a little bit of micro-manipulation ... )。
III. realization of a Unityhelper
Using System.windows.forms;namespace unity3d{public class Unityhelper {public static axunitywebplayeraxlib. Axunitywebplayer createunity (Form form,string src) {var unity = new Axunitywebplayeraxlib.axunitywebpla Yer (); ((System.ComponentModel.ISupportInitialize) (Unity)). BeginInit (); Form. Controls.Add (Unity); ((System.ComponentModel.ISupportInitialize) (Unity)). EndInit (); UNITY.SRC = src; Axhost.state state = Unity. OcxState; Unity. Dispose (); Unity = new Axunitywebplayeraxlib.axunitywebplayer (); ((System.ComponentModel.ISupportInitialize) (Unity)). BeginInit (); Form. SuspendLayout (); Unity. Dock = DockStyle.Fill; Unity. Name = "Unity"; Unity. OcxState = State; Unity. TabIndex = 0; ((System.ComponentModel.ISupportInitialize) (Unity)). EndInit (); Form. ResumeLayout (FALSE); return unity; } }}
Then write down the simple calling code in the Form1.cs.
Using system;using system.windows.forms;namespace unity3d.netframework461{public partial class Form1:form { Public Form1 () { InitializeComponent (); } private void Button1_Click (object sender, EventArgs e) { string src = [email protected] "/unity3dfiles/ Trans.unity3d "; var unity = unityhelper.createunity (THIS,SRC); Form form = new form (); Form. Controls.Add (Unity); Form. Show ();}}}
Put a unity file in the project Bin/debug directory, and here I find a random
Trans.unity3d
Iv. Finally, let's run the test.
Click the button
You can see that our code works perfectly and opens a unity file in a new window.
If you want to display in the original control, assign the value directly to a SRC, if you want to change dynamically, then the direct dynamic operation of the control can ...
WinForm Show Unity3d file (supports dynamic file path change)