https://www.cnblogs.com/cnxkey/articles/5394378.html
Recently self Unity3D, plan to use this trendy, popular, powerful game engine developed a three-dimensional business presentation system, but found that UI Games UI and business systems still have some differences, many users still more accustomed WinForm or WPF in UI form, then how in the online search, I WinForm and Unity3D integrated, the result is not very satisfactory, the vast majority of the answer is "No Way", was also given in the form of the use of the WebBrowser control, to be honest this is pretty more reliable, so previously done something similar; later found a post to say that you can use U3D WebPlayer controls, try holding the idea, created a winform application, really found in the toolbox inside UnityWebPlayer control of such a control:
In this case it is achieved before needs: U3D and Winform will combine, but how winform controls and U3D interact with it? Look at the definition of UnityWebPlayerClass class, we found a SendMessage method, and SendMessage define their own script U3D same.
The following first create a C # script in U3D, add a very simple function:
void Down()
{
transform.Translate( Vector3.down * Time.deltaTime );
}
将脚本拖到叫做Sphere的对象上面。然后在窗体上添加一个按钮,在按钮的click事件中调用上面定义的方法:
axUnityWebPlayer1.SendMessage( "Sphere", "Down", null );
再次运行,不停地点击按钮,就可以看到小球缓慢往下移动的效果了。
经过上面的尝试,总算是初步解决了U3D和Winform(WPF也类似)集成的问题,不过核心的对象控制代码还是得在U3D中写好、编译才行,winform只是提供了一个更为习惯的UI而已。不知道是否还有更好、更方便、更强大的方法,期待。。。
这文章对我很有用处,但是我使用控件后,设置src属性,运行提示错误说不是有效的u3d网页文件,src地址要是全部地址,直到.unity3d,例如:c:\**\**\**.unity3d。
AxUnityWebPlayer ax = new AxUnityWebPlayer();
ax.BeginInit();
ax.CreateControl();// 关键
ax.Location = new Point(0, 0); ax.Size = new Size(200, 200); ax.Dock = DockStyle.Fill; ax.src = Application.StartupPath + "\\abc\\abc.unity3d"; splitContainer1.Panel1.Controls.Add(ax); ax.EndInit();