【Vuforia+Unity】AR判断当前平台获取点击/触摸坐标点选中识别的二维码跳转网页

实现了:【Vuforia+Unity】判断当前平台获取点击/触摸坐标点选中识别的二维码跳转网页

using UnityEngine;

using Vuforia;

public class BarcodeScanner : MonoBehaviour

{

public TMPro.TextMeshProUGUI barcodeAsText;

string platformNum="";

private void Start()

{

switch (Application.platform)

{

case RuntimePlatform.WindowsEditor:

Debug.Log("用户使用的是 WindowsEditor");

platformNum = "WindowsEditor";

break;

case RuntimePlatform.OSXEditor:

Debug.Log("用户使用的是 OSXEditor");

platformNum = "OSXEditor";

break;

case RuntimePlatform.LinuxEditor:

Debug.Log("用户使用的是 LinuxEditor");

platformNum = "LinuxEditor";

break;

case RuntimePlatform.Android:

platformNum = "Android";

Debug.Log("用户使用的是 Android device");

break;

// 可以继续添加其他平台的判断,如 iOS, Windows, macOS 等

default:

Debug.Log("Running on an unspecified platform");

break;

}

}

void Update()

{

if (platformNum== "Android")//判断平台

{

if (Input.touchCount > 0) // 如果有触摸事件

{

Touch touch = Input.GetTouch(0); // 获取第一个点击触摸事件

if (touch.phase == TouchPhase.Began) // 如果触摸开始

{

Debug.Log("用户点击一次");

CastRay(touch.position);

}

}

}

if (platformNum == "WindowsEditor")//判断平台

{

if (Input.GetMouseButtonDown(0))

{

CastRay(Input.mousePosition);

}

}

}

void CastRay(Vector3 onePos)//这个函数负责向用户点击的点坐标位置发射射线,然后击中二维码后读取内容

{

Ray ray = Camera.main.ScreenPointToRay(onePos);

if (Physics.Raycast(ray.origin, ray.direction, out RaycastHit hit))

{

Debug.Log("射线射击二维码,用户点击成功");

barcodeAsText.text = hit.collider.GetComponent<BarcodeBehaviour>().InstanceData.Text;//获取二维码内容

string barcodeText = barcodeAsText.text;

if (barcodeText.StartsWith("http://") || barcodeText.StartsWith("https://"))

{

// 使用Application.OpenURL打开网址

Application.OpenURL(barcodeText);

}

else

{

barcodeAsText.text = barcodeText; // 如果不是网址,正常显示扫描结果

}

}

}

}

相关推荐
想你依然心痛2 分钟前
HarmonyOS 6 悬浮导航 + 沉浸光感:打造鸿蒙智能体驱动的沉浸式数据可视化驾驶舱
华为·信息可视化·ar·harmonyos·智能体
冰凌糕16 分钟前
Unity3D Shader 渲染状态详解
unity
郝学胜-神的一滴31 分钟前
[简化版 GAMES 101] 计算机图形学 10:反走样与深度缓冲核心解析
c++·unity·godot·图形渲染·three.js·unreal engine·opengl
2601_9588151616 小时前
悟赫德(Woowhead)品牌深度拆解:用“东方智慧×全球科技”在180亿手机膜赛道定义新品类
人工智能·科技·智能手机·ar·圆偏振光护眼·观复盾护景贴·悟赫德woowhead
2601_9588151619 小时前
scinique® 1.0双护技术与观复盾产品全解析:手机膜的光学上限是如何被重新定义的
智能手机·ar·圆偏振光护眼·观复盾护景贴·悟赫德woowhead
技术探讨者21 小时前
极境导表工具 —— 让配置数据成为游戏开发的效率引擎
unity·编辑器·ai编程·游戏策划
游乐码21 小时前
Unity基础(六)小案例
游戏·unity·游戏引擎
2601_9588151621 小时前
消费电子贴膜的光学技术革新:圆偏振光与磁控溅射AR的原理解析
智能手机·ar·产品评测·观复盾护景贴·iphone护眼膜
北京阿法龙科技有限公司1 天前
让AR显示如何做到公安安防在户外阳光下也能清晰可见
ar
2601_958352901 天前
AR-1106 量产落地白皮书:中小厂商如何用 1/10 成本实现语音交互功能
人工智能·ar·语音识别·智能机器人·音频处理模块