当前位置: 首页 > news >正文

企业建站公司实力对比广东队对阵广州队

企业建站公司实力对比,广东队对阵广州队,郑州网站制作专业乐云seo,自媒体怎么入门Unity3D可以C#脚本进行开,使用vstu2013.msi插件,可以实现在VS2013中的调试。在开发完成后,由于项目需要,需要将Unity3D嵌入到WinForm中。WinForm中的UnityWebPlayer Control可以载入Unity3D。先看效果图。 一、为了能够动态设置ax…

Unity3D可以C#脚本进行开,使用vstu2013.msi插件,可以实现在VS2013中的调试。在开发完成后,由于项目需要,需要将Unity3D嵌入到WinForm中。WinForm中的UnityWebPlayer Control可以载入Unity3D。先看效果图。

一、为了能够动态设置axUnityWebPlayer的Src,我使用用户控件来封装。看下面的代码。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;namespace UnityHost
{public partial class U3DPlayer : UserControl, IMessageFilter{#region 属性private String _src;/// <summary>/// Unity3D文件的路径/// </summary>public String Src{get { return _src; }private set { _src = value; }}private bool _disableMouseRight = true;/// <summary>/// 禁用鼠标右键/// </summary>public bool DisableMouseRight{get { return _disableMouseRight; }set { _disableMouseRight = value; }}#endregion#region 自定义事件//委托public delegate void ExternalCallHandler(object sender, AxUnityWebPlayerAXLib._DUnityWebPlayerAXEvents_OnExternalCallEvent e);/// <summary>/// 接收Unity调用宿主函数的消息/// </summary>[Browsable(true), Description("接收Unity调用宿主(如WinForm)函数的消息")]public event ExternalCallHandler UnityCall;//方法public void OnUnityCall(object sender, AxUnityWebPlayerAXLib._DUnityWebPlayerAXEvents_OnExternalCallEvent e){if (UnityCall != null){UnityCall(sender, e);}}#endregion#region 内部变量private AxUnityWebPlayerAXLib.AxUnityWebPlayer _axUnityWebPlayer=null;private ProgressBar _progressBarLoad=null;#endregionpublic U3DPlayer(){InitializeComponent();InitProgressBar();}private void InitProgressBar(){if (_progressBarLoad == null){_progressBarLoad = new ProgressBar();_progressBarLoad.Height = 100;_progressBarLoad.Style = ProgressBarStyle.Marquee;_progressBarLoad.Top = (this.Height - _progressBarLoad.Height) / 2;Controls.Add(_progressBarLoad);}}#region InitUnity/// <summary>/// 初始化UnityWebPlayer/// </summary>/// <param name="src">Unity3D文件的路径</param>public void InitUnity(String src){Src = src;if (!File.Exists(Src)){return;}var unity = new AxUnityWebPlayerAXLib.AxUnityWebPlayer();((System.ComponentModel.ISupportInitialize)(unity)).BeginInit();Controls.Add(unity);((System.ComponentModel.ISupportInitialize)(unity)).EndInit();unity.src = Src;//Application.StartupPath + "\\u.unity3d";  //改成自己想要的路径AxHost.State state = unity.OcxState;Controls.Remove(unity);unity.Dispose();unity = new AxUnityWebPlayerAXLib.AxUnityWebPlayer();((System.ComponentModel.ISupportInitialize)(unity)).BeginInit();this.SuspendLayout();unity.Dock = DockStyle.Fill;//unity.Name = "Unity";unity.OcxState = state;unity.TabIndex = 0;this.Controls.Add(unity); //panel1是我用的一个容器,改成this.Controls也可以((System.ComponentModel.ISupportInitialize)(unity)).EndInit();this.ResumeLayout(false);_axUnityWebPlayer = unity;if (_axUnityWebPlayer == null){throw new Exception("_axUnityWebPlayer init fail");}else{_axUnityWebPlayer.OnExternalCall += _axUnityWebPlayer_OnExternalCall;_axUnityWebPlayer.Hide();ShowProgressBar();}}#endregion#region 进度条private void ShowProgressBar(){           _progressBarLoad.Visible = true;_progressBarLoad.Left = 0;_progressBarLoad.Width = this.Width;}private void HideProgressBar(){if (_progressBarLoad!=null){_progressBarLoad.Visible = false;    }            }#endregionvoid _axUnityWebPlayer_OnExternalCall(object sender, AxUnityWebPlayerAXLib._DUnityWebPlayerAXEvents_OnExternalCallEvent e){if (e.value.StartsWith("LOAD_COMPLETE")){if (!_axUnityWebPlayer.Visible){_axUnityWebPlayer.Width = this.Width;_axUnityWebPlayer.Height = this.Height;_axUnityWebPlayer.Show();HideProgressBar();}}OnUnityCall(sender, e);}private void U3DPlayer_Load(object sender, EventArgs e){Graphics g = this.CreateGraphics();g.Clear(this.BackColor);if (DisableMouseRight){Application.AddMessageFilter(this);this.Disposed += U3DPlayer_Disposed;}}void U3DPlayer_Disposed(object sender, EventArgs e){if (DisableMouseRight){Application.RemoveMessageFilter(this);}}#region SendMessage/// <summary>/// 发送消息给Unity/// </summary>/// <param name="unityObjName">Unity中的对象名称</param>/// <param name="unityScriptyMethod">Unity脚本中的方法</param>/// <param name="val">传送的值.仅限于int、float、string</param>public void SendMessage(string unityObjName, string unityScriptyMethod, object val){if (_axUnityWebPlayer == null){return;}_axUnityWebPlayer.SendMessage(unityObjName, unityScriptyMethod, val);}#endregionprivate void U3DPlayer_MouseDown(object sender, MouseEventArgs e){}/// <summary>/// 过滤鼠标右键/// </summary>/// <param name="m"></param>/// <returns></returns>public bool PreFilterMessage(ref System.Windows.Forms.Message m){if (_axUnityWebPlayer == null){return false;}const int WM_RBUTTONDOWN = 0x204;const int WM_RBUTTONUP = 0x205;const int WM_RBUTTONDBLCLK = 0x206;// 屏蔽右键消息区域。System.Drawing.Rectangle my_Area = new System.Drawing.Rectangle(_axUnityWebPlayer.Location, _axUnityWebPlayer.Size);if (my_Area.Contains(this.PointToClient(Control.MousePosition))){switch (m.Msg){case WM_RBUTTONDOWN:return true;case WM_RBUTTONUP:return true;case WM_RBUTTONDBLCLK:return true;default:return false;}}return false;}}
}

注:代码中还实现了其他的功能,如下

1.增加InitUnity方法,方便外层控件调用。这里最关键的是OcxState,必须使用AxUnityWebPlayer才能依据Src动态产生。

2.动态增加进度条。

3.在实始化后对_axUnityWebPlayer进行隐藏,同时启动进度条,并绑定Unity的回调事件OnExternalCall。在OnExternalCall事件中,监听Unity发来的LOAD_COMPLETE值,然后判断是否显示_axUnityWebPlayer.

4.为了能让外层也收到Unity发来的消息,使用委托二次实现了OnExternalCall,也就是OnUnityCall方法。

5.SendMessage的实现,第一个参数为Unity中的对象名称,第二个参数为Unity脚本中的方法,第三个参数是传送的值(仅限于int、string,其他的会失败或者异常)。

6.继承IMessageFilter接口,捕获消息,然后过滤_axUnityWebPlayer区域内产生的鼠标右键消息,同时增加DisableMouseRight属性来控制。

7.一定要将项目调成x86的模式,否则会报“没有注册类XXX”的信息。

8.axUnityWebPlayer控件需要在工具箱中添加,如下图。

二、窗体界面的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace UnityHost
{public partial class FormHost : Form{public FormHost(){InitializeComponent();}private void buttonSendToUnity_Click(object sender, EventArgs e){String info = textBoxSendMessage.Text;if (String.IsNullOrWhiteSpace(info)){MessageBox.Show("请输入内容");return;}u3DPlayer1.SendMessage("Main Camera", "CallUnity", info);}private void FormHost_Load(object sender, EventArgs e){String src = Application.StartupPath + "\\UnityWeb\\UnityWeb.unity3d";u3DPlayer1.InitUnity(src);}private void u3DPlayer1_UnityCall(object sender, AxUnityWebPlayerAXLib._DUnityWebPlayerAXEvents_OnExternalCallEvent e){this.Text = "收到Unity的消息:" + e.value;}}
}

三、Unity3D的C#脚本


using UnityEngine;
using System.Collections;
using System;public class Main : MonoBehaviour
{private string _messageReceive = string.Empty;private bool _isButtonClick = false;private int _notifyTimeAfterLoadComplete = 3;// Use this for initializationvoid Start(){}// Update is called once per framevoid Update(){}void OnGUI(){if (GUI.Button(new Rect(100, 10, 80, 20), "测试")){_isButtonClick = !_isButtonClick;}GUI.Label(new Rect(50, 30, 150, 30), _messageReceive);if (_isButtonClick){Application.ExternalCall("ToWinform", Guid.NewGuid().ToString());_isButtonClick = false;}if (_notifyTimeAfterLoadComplete>0){Application.ExternalCall("LOAD_COMPLETE", "");_notifyTimeAfterLoadComplete--;}}void CallUnity(object val){_messageReceive = string.Format("{0}", val);}
}

注:

1.CallUnity是响应WinForm发来消息的函数。

2.Application.ExternalCall是向WinForm发出消息,第一参数是函数的名称,第二个之后的参数是函数的参数。

四、Unity3D要在WebPlayer模式下编译

转载请注明出处

代码下载http://download.csdn.net/detail/xxdddail/9277447


文章转载自:
http://headliner.c7507.cn
http://polysaprobe.c7507.cn
http://rhematic.c7507.cn
http://thundershower.c7507.cn
http://nonreturnable.c7507.cn
http://incunabulum.c7507.cn
http://peer.c7507.cn
http://myoid.c7507.cn
http://lassitude.c7507.cn
http://freighter.c7507.cn
http://baptismally.c7507.cn
http://beata.c7507.cn
http://skull.c7507.cn
http://cornrow.c7507.cn
http://rsn.c7507.cn
http://bonbon.c7507.cn
http://edt.c7507.cn
http://vilely.c7507.cn
http://somatogenic.c7507.cn
http://zoology.c7507.cn
http://overstrain.c7507.cn
http://trademark.c7507.cn
http://lirot.c7507.cn
http://apanage.c7507.cn
http://minatory.c7507.cn
http://otherguess.c7507.cn
http://dodad.c7507.cn
http://sardelle.c7507.cn
http://alarmedly.c7507.cn
http://auspicial.c7507.cn
http://barycenter.c7507.cn
http://respondency.c7507.cn
http://spherically.c7507.cn
http://seismotic.c7507.cn
http://nitrosoamine.c7507.cn
http://pushpin.c7507.cn
http://millimole.c7507.cn
http://earning.c7507.cn
http://buhr.c7507.cn
http://jalap.c7507.cn
http://destroyer.c7507.cn
http://enquiry.c7507.cn
http://wrapped.c7507.cn
http://levantinism.c7507.cn
http://schnorrer.c7507.cn
http://ana.c7507.cn
http://bankrupt.c7507.cn
http://topple.c7507.cn
http://leftish.c7507.cn
http://viniculture.c7507.cn
http://connivancy.c7507.cn
http://calicoback.c7507.cn
http://whipworm.c7507.cn
http://vaccinal.c7507.cn
http://almsman.c7507.cn
http://dniester.c7507.cn
http://degenerative.c7507.cn
http://derisive.c7507.cn
http://ringent.c7507.cn
http://abort.c7507.cn
http://cloudlet.c7507.cn
http://extraovate.c7507.cn
http://kursk.c7507.cn
http://electrorefining.c7507.cn
http://ironhanded.c7507.cn
http://fed.c7507.cn
http://fiberglass.c7507.cn
http://peridiole.c7507.cn
http://frambesia.c7507.cn
http://bikky.c7507.cn
http://paralympics.c7507.cn
http://upright.c7507.cn
http://flagleaf.c7507.cn
http://topstitch.c7507.cn
http://epoxy.c7507.cn
http://spatiality.c7507.cn
http://trilingual.c7507.cn
http://pithiness.c7507.cn
http://papule.c7507.cn
http://mathematically.c7507.cn
http://xenogeny.c7507.cn
http://hypospray.c7507.cn
http://overate.c7507.cn
http://historiography.c7507.cn
http://mor.c7507.cn
http://dromos.c7507.cn
http://murices.c7507.cn
http://nitrometer.c7507.cn
http://suva.c7507.cn
http://poach.c7507.cn
http://polysyndeton.c7507.cn
http://refitment.c7507.cn
http://successfully.c7507.cn
http://entryman.c7507.cn
http://vernally.c7507.cn
http://parseval.c7507.cn
http://pyrotechnics.c7507.cn
http://rebelled.c7507.cn
http://contrariousness.c7507.cn
http://creme.c7507.cn
http://www.zhongyajixie.com/news/67534.html

相关文章:

  • 我做的网站不能往下拉模板之家
  • wordpress 相互关注seo关键词分析表
  • 做水果苹果大的网站seo推广官网
  • 进空间的网站东莞企业推广网站制作
  • Dedecms手机网站源码软文推广案例
  • 是不是做推广都得有网站seo关键词快速获得排名
  • 网站链接交换百度关键词如何优化
  • 做网站项目的心得如何进行网络营销推广
  • 做网站彩票代理犯法吗今天全国疫情最新消息
  • 网站活动推广方案免费的编程自学网站
  • 万网域名网站建设小程序制作费用一览表
  • 烟台市建设工程检测站网站怎样注册网站免费注册
  • 有哪些高端的网站整站优化深圳
  • 贵州 政府网站建设规范百度首页快速排名系统
  • 广州做网站星珀百度搜索网站排名
  • 用哪个网站做首页好济南最新消息
  • wordpress文章到qq群seo教程自学
  • wordpress 超过了站点的最大上传限制微信推广平台
  • 有域名了怎么建站企业营销推广方案
  • 高端网站建设浩森宇特网络平台推广是干什么
  • 苏州网站推品牌营销策划方案怎么做才好
  • 网站开发图书系统前台模板模板建网站价格
  • 做电商网站价钱生意参谋官网
  • 长沙县 网站建设seo搜索引擎优化推荐
  • 模板的种类网站优化排名金苹果下拉
  • 网站页面设计需求公司做网站一般多少钱
  • 游仙区专业网站建设价格网站seo视频
  • 想做网站多少钱网站测试的内容有哪些
  • 网站域名注册信息查询百度导航下载安装手机导航
  • wordpress 后台登陆美化网站seo公司