unity3d使用3D WebView播放网页中的视频
创始人
2025-01-10 13:03:43
0

Unity2021.3.35f1,硬件ESP32-Cam,3D WebView插件

1.新建工程,导入3D WebView for Winfows和3D WebView for Android

2.打开场景Assets\Vuplex\WebView\Demos\Scenes\2_CanvasWebViewDemo

3.修改Canvas的Render Mode为Screen Space-Camera,修改Canvas Scaler

4.修改CanvasWebViewPrefab的组件RectTransform的对齐方式和宽高,宽高与分辨率相同

5.修改CanvasWebViewPrefab中的网址,Resolution改为1(实为缩放)

6.运行程序即可看到视频

7.导入OpenCV for Unity 2.5.9

8.创建Scripts文件夹,再创建Test.cs,打开编辑代码

using OpenCVForUnity.CoreModule; using OpenCVForUnity.ImgprocModule; using OpenCVForUnity.UnityUtils; using UnityEngine; using UnityEngine.UI; using Vuplex.WebView; using Vuplex.WebView.Internal;  public class Test : MonoBehaviour {     public RawImage rawImage;     public CanvasWebViewPrefab view;     public CanvasViewportMaterialView vp;      Texture2D texture;     Texture2D texture1;     RenderTexture _tmpRenderTexture;      bool init = false;     // Start is called before the first frame update     void Start()     {  #if UNITY_ANDROID         view.OnNewTextureHandle += OnRenderTex; #endif     }      void OnRenderTex(EventArgs eventArgs)     {         Draw(eventArgs.Value);     }      private void Update()     { #if UNITY_STANDALONE_WIN || UNITY_EDITOR         Texture2D tx = vp.Texture as Texture2D;         Draw(tx); #endif     }      void Draw(Texture2D tx)     {         if (tx == null)         {             return;         }         if (!init)         {             texture = new Texture2D(tx.width, tx.height, TextureFormat.ARGB32, false);             texture1 = new Texture2D(tx.width, tx.height, TextureFormat.ARGB32, false);              init = true;         }          Mat cameraMat = new Mat(tx.height, tx.width, CvType.CV_8UC4);          Point pt = new Point(tx.width / 2, tx.height / 2);          Utils.textureToTexture2D(tx, texture);         Utils.texture2DToMat(texture, cameraMat);         Imgproc.circle(cameraMat, pt, 30, new Scalar(255, 0, 0), 3);         Utils.matToTexture2D(cameraMat, texture1);         rawImage.texture = texture1;     }  } 

9.创建实体Test,添加Test组件,并给变量赋值

10.运行程序,可以在RawImage中看到一个圆圈。

至此Windows环境已适配完成。

下面开始适配安卓版

11.去掉勾选CanvasWebViewPrefab组件中的Native 2D Mode (Android, iOS, WebGL, and UWP only)

12.将平台切换到Android,在Player Setting...中Graphics APIS 添加Vulkan

13.打开Assets\Vuplex\WebView\Core\Scripts\BaseWebViewPrefab.cs添加如下代码

        public delegate void OnNewTexture(EventArgs eventArgs);         public OnNewTexture OnNewTextureHandle;
if (OnNewTextureHandle != null) {    OnNewTextureHandle(eventArgs); }

13.发布apk,在手机上运行,即可看到与PC相同的效果

相关内容

热门资讯

正品辅助!佛手在线大菠萝辅助,... 正品辅助!佛手在线大菠萝辅助,epoker免费透视脚本,技巧教程(有挂教程)-哔哩哔哩【无需打开直接...
指南书辅助"来几局辅... 指南书辅助"来几局辅助器开挂"开挂(插件)辅助软件(有挂实锤);亲,来几局辅助器开挂这款游戏原来确实...
透视苹果版!雀姬手机辅助脚本,... >>您好:雀姬手机辅助脚本确实是有挂的,很多玩家在这款雀姬手机辅助脚本游戏中打牌都会发现很多用户的牌...
固有有开挂"牵手跑辅... 固有有开挂"牵手跑辅助"详细开挂辅助挂真实有挂(透视教程);无需打开直接搜索薇:136704302 ...
正版开挂!花花生活圈辅助工具安... 正版开挂!花花生活圈辅助工具安装教程,约局吧能不能开挂,德州教程(有挂神器)-哔哩哔哩1、下载安装好...
总结辅助"大当家脚本... 总结辅助"大当家脚本一键挂机"开挂(软件)辅助下载(真的有挂);无需打开直接搜索加(薇:136704...
透视免费!新道游修改器,微乐陕... 透视免费!新道游修改器,微乐陕西小程序破解器(透视)开挂辅助工具wpk教程1、下载安装好微乐陕西小程...
素来有辅助"乐乐围棋... 素来有辅助"乐乐围棋入门辅助"详细开挂辅助下载有挂工具(必胜教程);亲,乐乐围棋入门辅助这款游戏原来...
透视安卓版!荆州圣盛游戏辅助,... 透视安卓版!荆州圣盛游戏辅助,wejoker辅助软件视频(透视)开挂辅助器技巧教程;无需打开直接搜索...
妙计开挂"创思维激k... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...