U3dplayer unitywebplayer Dynamic Change src

Source: Internet
Author: User

Single-machine problem solved, next is the problem of dynamic src , previously saw there is a solution.

Today's Reference: Unity dynamic change src solution - Wisdom Week Everything

My goal is to realize the ability to open any . unity3d file , sort out his code, delete it, make a user control, code:

public partial class U3dplayer:usercontrol

{

public static U3dplayer AppendTo (Control Parent, string path)

{

Try

{

U3dplayer player = new U3dplayer (path);

Parent. Controls.clear ();

Parent. Controls.Add (player);

return player;

}

catch (Exception ex)

{

Console.WriteLine (ex);

return null;

}

}

Public U3dplayer (String path)

{

InitializeComponent ();

_u3dplayer = Initu3dplayer ();

OpenFile (path);

}

Private Axunitywebplayer _u3dplayer;

private void OpenFile (string path)

{

_u3dplayer = Createu3dplayerex (path, _u3dplayer);

}

Private Axunitywebplayer Initu3dplayer ()

{

var resources = new ComponentResourceManager (GetType ());

Axhost.state state1 = ((axhost.state) (resources. GetObject ("U3dplayer.ocxstate"));

var player = Createu3dplayer (state1);

return player;

}

Private Axunitywebplayer Createu3dplayerex (string path, Axunitywebplayer player)

{

var state = GetState (path, player);

return Createu3dplayer (state);

}

/*

* When the SRC attribute is set for unity, the string resource is automatically generated and assigned to the attribute ocxstate.

* Because there is no way to manually generate this string, it is necessary to pass the code, that is, the first assignment to OcxState, and then the way to get the required string resources.

* Then assign the value to the re-created control.

*/

<summary>

Get the string resource you want

</summary>

<param name= "Path" ></param>

<param name= "Player" ></param>

<returns></returns>

private static Axhost.state GetState (string path, Axunitywebplayer player)

{

PLAYER.SRC = new FileInfo (path). FullName; Here's the point.

Axhost.state state = player. OcxState;

Player. Dispose ();//Because we're going to create a new soon.

return state;

}

Private Axunitywebplayer Createu3dplayer (axhost.state state1)

{

var player = new Axunitywebplayer () {Dock = DockStyle.Fill};

((ISupportInitialize) (player)). BeginInit ();

Player. OcxState = state1;

Controls.Add (player);

((ISupportInitialize) (player)). EndInit ();

return player;

}

}

Finally, the OpenFile can not be changed to public, it should be said, can change, the previous two calls are no problem, but the third start will be abnormal closing procedures (specific reasons I did not go to the bottom). So when using a u3dplayer display a scene, to change, then create a good. The first AppendTo method. in fact, I would like to change the constructor directly to private, but there are some places to use, or forget.

U3dplayer unitywebplayer Dynamic Change src

Related Article

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.