using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using ET; using FairyGUI; using UI.DressUp; using UnityEngine; using UnityEngine.Android; namespace GFGGame { public class PhotographSaveView : BaseView { private UI_PhotographSaveUI _ui; private Texture2D tex; private byte[] bytes; protected override void OnInit() { base.OnInit(); packageName = UI_PhotographUI.PACKAGE_NAME; _ui = UI_PhotographSaveUI.Create(); viewCom = _ui.target; isfullScreen = true; _ui.m_btnClose.onClick.Add(this.Hide); _ui.m_btnSave.onClick.Add(this.OnClickBtnSave); _ui.m_btnSavePhoto.onClick.Add(this.OnClickBtnSavePhoto); } protected override void OnShown() { base.OnShown(); tex = this.viewData as Texture2D; bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片 _ui.m_imgRes.texture = new NTexture(tex); float width = _ui.m_imgBorder.width; float height = width * tex.height / tex.width; _ui.m_imgRes.SetSize(width, height); _ui.m_imgBorder.SetSize(width, height + 12); Timers.inst.AddUpdate(CheckGuide); } protected override void OnHide() { base.OnHide(); _ui.m_btnSave.selected = false; _ui.m_btnSave.touchable = true; _ui.m_btnSavePhoto.selected = false; _ui.m_btnSavePhoto.touchable = true; Timers.inst.Remove(CheckGuide); } public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } private void OnClickBtnSave() { //检查用户是否已授予对需要授权的设备资源或信息的访问权。 if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite)) { //请求用户授权访问需要授权的设备资源或信息. Permission.RequestUserPermission(Permission.ExternalStorageWrite); } if (Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite)) { string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg"; PhotographUtil.Instance.SavePicturoToLocal(bytes, fileName); _ui.m_btnSave.touchable = false; } } private async void OnClickBtnSavePhoto() { if (PoemPhotoDataManager.Instance.PersonalPhotoInfos.Count >= GlobalCfgArray.globalCfg.maxPhotoCount) { PromptController.Instance.ShowFloatTextPrompt("照片数量已达上限"); return; } object[] rsp = await PoemPhotoSProxy.ReqTempPictureUrl(); if (rsp == null) return; bool pushResult = await PictureStorageHelper.PushToHWCloud(rsp[0].ToString(), bytes); if (!pushResult) return; long addResult = await PoemPhotoSProxy.ReqAddTophoto((long)rsp[1]); if (addResult > 0) { List list = PoemPhotoDataManager.Instance.PersonalPhotoInfos; for (int i = 0; i < list.Count; i++) { if (list[i].PictureId == addResult) { list[i].Bytes = bytes; list[i].Ntexture = new NTexture(tex); break; } } } _ui.m_btnSavePhoto.touchable = false; } private void CheckGuide(object param) { if (GuideDataManager.IsGuideFinish(ConstGuideId.FREEDOM_DRESS) <= 0) { UpdateToCheckGuide(null); } else { Timers.inst.Remove(CheckGuide); } } protected override void UpdateToCheckGuide(object param) { if (!ViewManager.CheckIsTopView(this.viewCom)) return; GuideController.TryGuide(_ui.m_btnClose, ConstGuideId.FREEDOM_DRESS, 9, ""); GuideController.TryCompleteGuide(ConstGuideId.FREEDOM_DRESS, 9); } protected override void TryCompleteGuide() { base.TryCompleteGuide(); // GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FREEDOM_DRESS); GuideController.TryCompleteGuideIndex(ConstGuideId.FREEDOM_DRESS, 9); GuideController.TryCompleteGuide(ConstGuideId.FREEDOM_DRESS, 9); } } }