123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using easyar;
- using TMPro;
- using UnityEngine;
- using UnityEngine.Networking;
- using XRTool.Util;
- using static easyar.ImageTargetController;
- public class DemoManager : MonoBehaviour
- {
- public TextMeshProUGUI timetext;
- public bool isinit;
- public bool isDianbiao;
- public GameObject AISelect;
-
- private void OnEnable()
- {
- AISelect.SetActive(true);
- isDianbiao = false;
-
- }
- public void jixushibie()
- {
- StartCoroutine(DownloadImage("https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/MREdustry_100/DemoShiBieTu.jpg"));
- ChangeCameraSaoMiao.Instance.showDemoSaoMiao();
- imageTarget.SetActive(false);
- shibieGo.SetActive(false);
- TimerMgr.Instance.CreateTimer(() => {
- imageTarget.SetActive(true);
- }, 10f);
- }
- public void tuichushibie()
- {
- WindowsManager.Instance.show(WindowConfig.windowType.ProjectMain);
- WindowsManager.Instance.show(WindowConfig.windowType.Top, false);
- }
- public GameObject shibieGo;
- private void Update()
- {
- if(im&& isDianbiao)
- {
- if (imageTarget.activeSelf)
- {
- if (im)
- {
- Destroy(im);
- im = null;
- shibieGo.SetActive(true);
- timetext.text = DateTime.Now.ToString("yyyy 年 M 月 d 日 HH:mm");
- ChangeCameraSaoMiao.Instance.close();
- }
- }
- }
- }
- // 协程方法,用于异步下载图片
- IEnumerator DownloadImage(string url)
- {
- // 使用UnityWebRequestTexture来获取图片纹理
- UnityWebRequest m_webrequest = UnityWebRequest.Get(url);
- yield return m_webrequest.SendWebRequest();
- // 检查下载是否成功
- if (m_webrequest.result != UnityWebRequest.Result.Success)
- {
- // 打印错误信息
- Debug.LogError("Failed to download image");
- }
- else
- {
- string giftopngpath = Application.persistentDataPath + "/DownLoadXR/DemoShiBieTu.png";
- // 从下载处理器获取纹理
- Texture2D tex = new Texture2D(1, 1);
- tex.LoadImage( m_webrequest.downloadHandler.data);
- tex.Apply();
- byte[] gifbyte = tex.EncodeToPNG();
- //文件流信息
- //StreamWriter sw;
- Stream sw;
- FileInfo file = new FileInfo(giftopngpath);
- try
- {
- if (!Directory.Exists(Application.persistentDataPath + "/DownLoadXR"))
- {
- Directory.CreateDirectory(Application.persistentDataPath + "/DownLoadXR");
- }
- if (!file.Exists)
- {
- sw = file.Create();
- //如果此文件存在则打开
- //sw = file .Append();
- //如果此文件不存在则创建
- //以行的形式写入信息
- //sw.WriteLine(info);
- sw.Write(gifbyte, 0, gifbyte.Length);
- sw.Close();
- sw.Dispose();
- }
- }
- catch
- {
- }
- yield return new WaitForSeconds(1f) ;
- ImageFileSourceData data = new ImageFileSourceData();
- data.Name = "DemoShiBieTu";
- data.Path = giftopngpath;
- data.PathType = PathType.Absolute;
- data.Scale = 0.1f;
- im = imageTarget.AddComponent<ImageTargetController>();
- im.ImageFileSource = data;
- ARSaoTuManager.Instance.imageOnFind.LoadTarget(im);
- ARSaoTuManager.Instance.cameraDevice.Open();
- }
- }
- ImageTargetController im;
- public GameObject imageTarget;
- public GameObject deviceGo;
- private void OnDisable()
- {
- if (im)
- {
- Destroy(im);
- im = null;
- }
- shibieGo.SetActive(false);
- deviceGo.SetActive(false);
- }
- public void SeleckDianBiao()
- {
- isDianbiao = true;
- AISelect.SetActive(false);
- if (ChangeCameraSaoMiao.Instance)
- {
- StartCoroutine(DownloadImage("https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/MREdustry_100/DemoShiBieTu.jpg"));
- ChangeCameraSaoMiao.Instance.showDemoSaoMiao();
- imageTarget.SetActive(false);
- TimerMgr.Instance.CreateTimer(() => {
- imageTarget.SetActive(true);
- }, 10f);
- }
- }
- public void SeleckDevice()
- {
- //ShowInfoTipManager.Instance.showTip("暂未开放,敬请期待");
- //TimerMgr.Instance.CreateTimer(() => { ShowInfoTipManager.Instance.closeTip(); }, 2f);
- isDianbiao = false;
- AISelect.SetActive(false);
- deviceGo.gameObject.SetActive(true);
- TopManager.Instance.AIExitIconState(true);
- // 设备识别
- }
- public void GoHome()
- {
- WindowsManager.Instance.show(WindowConfig.windowType.ProjectMain);
- }
- public void GoDemo()
- {
- // WindowsManager.Instance.show(WindowConfig.windowType.Demo);
- }
- public void GoRTC()
- {
- WindowsManager.Instance.show(WindowConfig.windowType.RTC);
- }
- public void GoDaoHang()
- {
- WindowsManager.Instance.show(WindowConfig.windowType.DaoHang);
- }
- public void GoXunJian()
- {
- WindowsManager.Instance.show(WindowConfig.windowType.XunJianLB);
- }
- public void AIDeviceExit()
- {
- deviceGo.SetActive(false);
- AISelect.SetActive(true);
- // Ui 显示 隐藏
- TopManager.Instance.AIExitIconState(false);
- }
- }
|