WinForm Show Unity3d file (supports dynamic file path change)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.