/// <summary> /// 下载模型资源 /// </summary> private void Downloadasset() { if (isdownloading) { Uimanager.Getinstance().Showtips("资源正在下载中"); return; } //检查资源是否有缓存 if (!SKassetbundlehelper.instance.Checkcache(item.Getitemurl(), item.version)) { isdownloading = true; //检查网络是否可用 if (!Browser.Getinstance().GetNetreachable(false)) { return; } //载入资源 StartCoroutine(SKassetbundlehelper.instance.Paringbundle(item.Getitemurl(), item.version, Ondownloaded)); } else { //由showcase界面下载进入到scan view 解析模型资源 StartCoroutine(SKassetbundlehelper.instance.Paringbundle(item.Getitemurl(), item.version, Scannermanager.Getinstance().Parsingbundlecallback)); //黑色浸入 //Uimanager.Getinstance().Addblackfade(true,null); //Viewop(); // Viewop(); } }
/// <summary> /// 识别到目标 /// </summary> /// <param name="_targetSearchResult"></param> public void OnNewSearchResult(TargetFinder.TargetSearchResult _targetSearchResult) { if (!sm.isinited) { return; } //1.设置当前状态为得到扫描数据结果 //2.关闭云识别功能模块 //3.反序列化扫描得到的数据到metadata类型对象 //4.使用反序列化得到的对象变量id对服务器数据库发起请求 //5.激活当前识别追踪容器 sm.Getcurrecostatus = Scanstatus.SCANTHERESULTS; cloudrecobehaviour.CloudRecoEnabled = false; //------------将json反序列化为metadata类型对象------------------- //sm.metadaats = JsonUtility.FromJson<Metadata>(_targetSearchResult.MetaData); //------------得到扫描结果对象后向服务器发起查询请求事件------------ Browser.Getinstance().Getitems(_targetSearchResult.UniqueTargetId, Scannermanager.Getinstance().Parsingitemjson, Scannermanager.Getinstance().Onerror); //---------------------激活template追踪容器------------------------ if (imagetargettemplate) { ObjectTracker tracker = TrackerManager.Instance.GetTracker <ObjectTracker>(); ImageTargetBehaviour imageTargetBehaviour = (ImageTargetBehaviour)tracker.TargetFinder.EnableTracking(_targetSearchResult, imagetargettemplate.gameObject); } }
/// <summary> /// 获取相册路径 /// </summary> /// <returns></returns> public string Getpath() { string path = null; switch (Application.platform) { case RuntimePlatform.OSXEditor: case RuntimePlatform.WindowsEditor: path = Scannermanager.Getinstance().projectconfig.appenvironmentalpath; break; case RuntimePlatform.OSXPlayer: case RuntimePlatform.WindowsPlayer: path = Scannermanager.Getinstance().projectconfig.appenvironmentalpath; break; case RuntimePlatform.IPhonePlayer: path = Scannermanager.Getinstance().projectconfig.appenvironmentalpath; break; case RuntimePlatform.Android: path = Calljavabridge("GetDCIMpath"); break; } return(path); }
/// <summary> /// 绑定按钮事件 /// </summary> private void Btneventbind() { Scannermanager.Getinstance().onparsingitemend = Viewop; //获取识别图缩略图 markless.onClick.AddListener(() => { markerlessview.SetActive(true); Browser.Getinstance() .GetMarkless(item.thumbnails, Uimanager.Getinstance().Setmarkerless, null, markerlessimage); }); //关闭识别图浮窗 markerlessclosebtn.onClick.AddListener(() => { markerlessimage.sprite = null; Resources.UnloadUnusedAssets(); }); //下载识别图 markerlesscdownloadbtn.onClick.AddListener(() => { DownloadMarkless(); }); //下载资源 download.onClick.AddListener(() => { Downloadasset(); }); //播放视频 videoplayerbtn.onClick.AddListener(() => { videopayer.GetComponent <Button>().interactable = true; videoplayerbtn.gameObject.SetActive(false); if (tmpthumbnails != null) { DestroyImmediate(tmpthumbnails); videopayer.texture = null; } mediaplayer.Play(); }); //暂停视频 videopayer.GetComponent <Button>().onClick.AddListener(() => { videopayer.GetComponent <Button>().interactable = false; videoplayerbtn.gameObject.SetActive(true); mediaplayer.Pause(); }); favorite.onClick.AddListener(() => { //TODO:write data to dbs. Adddatatofavoritedb(); }); }
/// <summary> /// 清空所有对按钮的事件添加 /// </summary> public void OnDisable() { //Remove evnet favorite.onClick.RemoveAllListeners(); markless.onClick.RemoveAllListeners(); download.onClick.RemoveAllListeners(); videoplayerbtn.onClick.RemoveAllListeners(); markerlessclosebtn.onClick.RemoveAllListeners(); markerlesscdownloadbtn.onClick.RemoveAllListeners(); if (Scannermanager.Getinstance().onparsingitemend != null) { Scannermanager.Getinstance().onparsingitemend = null; } //clean cache mediaplayer.m_strFileName = null; mediaplayer.Stop(); mediaplayer.UnLoad(); DestroyImmediate(videopayer.texture); videoplayerbtn.gameObject.SetActive(true); //set favorite to null //favorite.GetComponent<Image>().sprite = Resources.Load<Sprite>("Ui/btn_like_nor"); }
/// <summary> /// 初始化 'Dooperation' 所需参数 /// </summary> public virtual void Initop() { Scannermanager.Getinstance().baseoperation = this; Getoperattarget = this.gameObject; selftransform = this.transform; isinited = true; }
/// <summary> /// 脚本被启动的回调 /// </summary> protected virtual void OnEnable() { if (isinited) { selftransform = this.transform; Getoperattarget = this.gameObject; Scannermanager.Getinstance().baseoperation = this; } }
//---------------------- Unity call back function---------------------------------- //--------------------------初始化当前脚本变量------------------------------------ private void Awake() { cloudrecobehaviour = GetComponent <CloudRecoBehaviour>(); if (cloudrecobehaviour) { cloudrecobehaviour.RegisterEventHandler(this); } sm = Scannermanager.Getinstance(); Stopscanning(); }
/// <summary> /// 获取识别图图片回调 /// </summary> /// <param name="_bytes"></param> /// <param name="_image"></param> private void GetMarkerless(byte[] _bytes, object _image) { //生成照片名称 string filename = Fileoperation.Generatefilename(".jpg"); string path = Scannermanager.Getinstance().projectconfig.photopath + "/" + filename; //存入本地相册 File.WriteAllBytes(path, _bytes); Crossplatformbridge.Getinstance().Savephoto("/SKbrowser/" + filename); StartCoroutine(Uimanager.Getinstance().Waittoshowtips("识别图已存储到相册")); }
/// <summary> /// 录屏结束后回调 /// </summary> private void Onstoprecording() { isstarted = false; //视屏录制完毕后回调,一般用于隐藏恢复用户提示界面(UI) if (onrecorded != null) { onrecorded(); } curtime = 0; //由于everplayer录屏插件录制的视频将存储到temporarycachpath中 //故我们使用这个路径用C#代码来查找 string tmpfilepath = Application.temporaryCachePath; #if UNITY_IPHONE tmpfilepath = tmpfilepath.Replace("Library/Caches", "tmp"); #endif //使用Directoryinfo 来搜索查询录制下来的视频 DirectoryInfo dir = new DirectoryInfo(tmpfilepath); var files = dir.GetFiles("*.mp4", SearchOption.AllDirectories); var file = files.OrderByDescending(f => f.CreationTime).FirstOrDefault(); if (file != null && string.IsNullOrEmpty(file.FullName)) { return; } string tmpfullname = file.FullName; #if UNITY_ANDROID //搜索到视频后将其另存到我们指定的目录下 Fileoperation.Writefiletodisk(file.FullName, Scannermanager.Getinstance().projectconfig.recordingpath, Fileoperation.Generatefilename(".mp4")); #endif #if UNITY_IPHONE || UNITY_IOS //IOS中存储路径与安卓有差异 string originpath = file.FullName; string temp = originpath.Replace(file.Name, file.Name + "_reencode.mp4"); if (Fileoperation.Fileexist(originpath)) { Crossplatformbridge.Getinstance().Savevideo(originpath, temp); } #endif Uimanager.Getinstance().Showtips("录像已存到本地"); }
public override void Updateviewstatus(Viewstatus _viewstatus) { //base.Updateviewstatus(_viewstatus); switch (Scannermanager.Getinstance().Getcurrecostatus) { case Scanstatus.GOTOSCAN: scaned.SetActive(false); scanning.SetActive(true); progress.gameObject.SetActive(false); back.gameObject.SetActive(true); if (blur.enabled) { //base.Updateviewstatus(_viewstatus); blur.enabled = false; } break; case Scanstatus.SCANTHERESULTS: scaned.SetActive(false); scanning.SetActive(true); progress.gameObject.SetActive(true); back.gameObject.SetActive(false); break; case Scanstatus.SCANISDONE: scaned.SetActive(true); scanning.SetActive(false); progress.gameObject.SetActive(false); back.gameObject.SetActive(false); blur.enabled = false; break; case Scanstatus.STOPSCANNING: scaned.SetActive(false); scanning.SetActive(true); progress.gameObject.SetActive(false); back.gameObject.SetActive(false); blur.enabled = true; base.Updateviewstatus(_viewstatus); break; } base.Updateviewstatus(_viewstatus); }
public void OnTrackableStateChanged(TrackableBehaviour.Status _previousstatus, TrackableBehaviour.Status _newstatus) { switch (_newstatus) { case TrackableBehaviour.Status.NOT_FOUND: case TrackableBehaviour.Status.UNKNOWN: case TrackableBehaviour.Status.UNDEFINED: Scannermanager.Getinstance().Ontrackerloseevent(this, this.gameObject); Debug.Log("Lose " + trackablebehaviour.TrackableName); break; case TrackableBehaviour.Status.DETECTED: case TrackableBehaviour.Status.TRACKED: case TrackableBehaviour.Status.EXTENDED_TRACKED: Scannermanager.Getinstance().Ontrackerfoundevent(this, this.gameObject); Debug.Log("Found " + trackablebehaviour.TrackableName); break; } }
/// <summary> /// 显示提示 /// </summary> /// <param name="msg"></param> internal void Showtips(string msg) { GameObject tmp = Instantiate(tipsviewprefab, this.transform); tmp.transform.localScale = Vector3.one; tmp.transform.localRotation = Quaternion.identity; tmp.transform.localPosition = Vector3.zero; tips.Add(tmp); RectTransform rect = tmp.GetComponent <RectTransform>(); tmp.GetComponent <RectTransform>().offsetMax = new Vector2(0, 68.6f); tmp.GetComponent <RectTransform>().offsetMin = new Vector2(0, 0); tmp.GetComponent <Tipsview>().Setupmsg(msg); if (Scannermanager.Getinstance().Getcurrecostatus != Scanstatus.STOPSCANNING || !Scannermanager.Getinstance().isinited) { Hideprogress(); } //((Tipsview)Getviewfromviewid(typeof(Tipsview).Name)).Setupmsg(msg); }
private IEnumerator TakephotoCoroutine() { if (doingbefore != null) { doingbefore.Invoke(); } yield return(new WaitForEndOfFrame()); //获取屏幕上的所有像素写到texture2d内并保存 Texture2D t2d = new Texture2D(screenwidth, screenheight, TextureFormat.ARGB32, false); t2d.ReadPixels(new Rect(0, 0, screenwidth, screenheight), 0, 0, false); t2d.Apply(false); string filename = Fileoperation.Generatefilename(".jpg"); byte[] bytes = t2d.EncodeToJPG(); Fileoperation.Writefiletodisk(Scannermanager.Getinstance().projectconfig.photopath, filename, bytes); Crossplatformbridge.Getinstance().Savephoto(Scannermanager.Getinstance().projectconfig.projectname + "/" + filename); if (doingafter != null) { doingafter.Invoke(); } }
private void Start() { self = this.transform; target = Camera.main.transform; scannermanager = Scannermanager.Getinstance(); }
/// <summary> /// 脚本禁用后的回调,用于释放资源等 /// </summary> protected virtual void OnDisable() { selftransform = null; Getoperattarget = null; Scannermanager.Getinstance().baseoperation = null; }