日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Unity5.3 使用Awesomium插件内嵌网页

發布時間:2023/12/20 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Unity5.3 使用Awesomium插件内嵌网页 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用Awesomium插件

爬坑指南
1.使用的為awesomium_unity1.7.4.2win_full插件;
2.此插件最大不爽之處在于非要發布后才能看到網頁,謹記;
3.主要寫腳本控制WebUIComponent即可;
4.拖預制體的時候會有莫名奇妙的錯誤,請自行體會;
插件導入后,新建一個空物體,
添加組件后

好了,離成功不遠了,首先是Common下的Source就是要顯示的網址。
看見組件中的Rendering下的Visible沒?現在沒勾,這個要勾上顯示用的。
如果只是顯示的話,現在不要任何腳本,發布一個PC端的,運行后就能看到網頁了。
下面介紹WebUIComponent的屬性
Width,Height 寬和高;
Target 渲染目標,1、None 2、GUI用OnGUI 3、Render 用網格渲染器(要把WebUIComponent添加到Plane或Quad等3D物體上);
Achor 錨點;
IsTransparent 是否有透明通道;
FilterMode 渲染模式
Visible 可見


下面說說代碼吧,直接上干貨
首先是繼承WebUIScript,重寫了方法(這里只是簡單重寫了主要的)

using UnityEngine; using System.Collections; using UnityEngine.UI; using Awesomium.Core; using Awesomium.Unity; using Awesomium.Core.Data; using UnityEngine.EventSystems;public class WebRoomInfoHandler : WebUIScript {Ray ray;RaycastHit hit;private WebSession session;#region//重寫protected override void Awake(){if (Application.isEditor)return;if (!webUI)return;// Get or create an in-memory WebSession.if (session == null){session = WebCore.CreateWebSession(new WebPreferences() { SmoothScrolling = true });UnityEngine.Debug.Log("Created In-Memory Session");}if (session.GetDataSource("media") == null){// Create and add a ResourceDataSource. This will be used to load assets// from the resources assembly (AwesomiumSampleResources) available with this sample.ResourceDataSource dataSource = new ResourceDataSource(ResourceType.Embedded,typeof(AwesomiumSampleResources.Loader).Assembly);session.AddDataSource("media", dataSource);UnityEngine.Debug.Log("Added DataSource");}// Assign the WebSession to the WebUIComponent.webUI.WebSession = session;}// Use this for initializationprotected override void Start(){if (Application.isEditor)return;// Check if there's a WebUIComponent available// in this GameObject.if (!webUI)return;// Set a handler for the DocumentReady event.webUI.DocumentReady += OnDocumentReady;}protected override void OnGUI(){if (Input.GetMouseButtonDown(0)){OnClickRoom();}}#endregion#region//事件private void OnDocumentReady(object sender, UrlEventArgs e){JSObject webUIManager = webUI.CreateGlobalJavascriptObject("webUIManager");if (webUIManager == null)return;webUIManager.Bind("closeWebUI", false, CloseWebUIHandler);//}#endregion

下面才是控制的重點;和上面在一個腳本哦。

#region//方法void OnClickRoom(){ray = Camera.main.ScreenPointToRay(Input.mousePosition);if (Physics.Raycast(ray, out hit, 100f)){if (hit.collider.name.Equals("Cube")){Debug.Log("點擊房間");BtnOnClick();}}}void CloseWebUIHandler(object sender, JavascriptMethodEventArgs e){webUI.Visible = false;}public void BtnOnClick(){webUI.Source = "https://www.baidu.com".ToUri();webUI.Visible = true;}#endregion

在場景中新建一個Cube,這樣點擊就會顯示網頁了,如果你想關閉這個網頁,不好意思自己慢慢研究吧。如過你會寫網頁,注意一下webUIManager,在網頁里寫上closeWebUI方法,相信你會實現與unity交互的。
效果圖如下

錯誤之處歡迎之處,哈哈!Demo下載地址:
鏈接:https://pan.baidu.com/s/1i4U07kh 密碼:70wl

(%E9%93%BE%E6%8E%A5%EF%BC%9Ahttp://pan.baidu.com/s/1i4U07kh%20%E5%AF%86%E7%A0%81%EF%BC%9A70wl)

總結

以上是生活随笔為你收集整理的Unity5.3 使用Awesomium插件内嵌网页的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。