123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using ET;
- using FairyGUI;
- using UI.DressUp;
- using UnityEngine;
- 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);
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- public override void Dispose()
- {
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- private void OnClickBtnSave()
- {
- // Texture2D tex = this.viewData as Texture2D;
- // byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
- string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg";
- PhotographDataManager.Instance.SavePicturoToLocal(bytes, fileName);
- }
- private async void OnClickBtnSavePhoto()
- {
- if (PoemPhotoDataManager.Instance.PersonalPhotoInfos.Count >= GlobalCfgArray.globalCfg.maxPhotoCount)
- {
- PromptController.Instance.ShowFloatTextPrompt("照片数量已达上限");
- return;
- }
- // Texture2D tex = this.viewData as Texture2D;
- // byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
- string[] rsp = await PoemPhotoSProxy.ReqTempPictureUrl((int)PictureType.jpg);
- if (rsp == null) return;
- string code = PoemPhotoSProxy.PushToHWCloud(rsp[0], bytes);
- if (string.IsNullOrEmpty(code)) return;
- long result = await PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum);
- if (result > 0)
- {
- List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].PictureId == result)
- {
- list[i].Ntexture = new NTexture(tex);
- break;
- }
- }
- }
- }
- }
- }
|