PhotographSaveView.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6. using ET;
  7. using FairyGUI;
  8. using UI.DressUp;
  9. using UnityEngine;
  10. namespace GFGGame
  11. {
  12. public class PhotographSaveView : BaseView
  13. {
  14. private UI_PhotographSaveUI _ui;
  15. private Texture2D tex;
  16. private byte[] bytes;
  17. protected override void OnInit()
  18. {
  19. base.OnInit();
  20. packageName = UI_PhotographUI.PACKAGE_NAME;
  21. _ui = UI_PhotographSaveUI.Create();
  22. viewCom = _ui.target;
  23. isfullScreen = true;
  24. _ui.m_btnClose.onClick.Add(this.Hide);
  25. _ui.m_btnSave.onClick.Add(this.OnClickBtnSave);
  26. _ui.m_btnSavePhoto.onClick.Add(this.OnClickBtnSavePhoto);
  27. }
  28. protected override void OnShown()
  29. {
  30. base.OnShown();
  31. tex = this.viewData as Texture2D;
  32. bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
  33. _ui.m_imgRes.texture = new NTexture(tex);
  34. float width = _ui.m_imgBorder.width;
  35. float height = width * tex.height / tex.width;
  36. _ui.m_imgRes.SetSize(width, height);
  37. _ui.m_imgBorder.SetSize(width, height + 12);
  38. }
  39. protected override void OnHide()
  40. {
  41. base.OnHide();
  42. }
  43. public override void Dispose()
  44. {
  45. if (_ui != null)
  46. {
  47. _ui.Dispose();
  48. _ui = null;
  49. }
  50. base.Dispose();
  51. }
  52. private void OnClickBtnSave()
  53. {
  54. // Texture2D tex = this.viewData as Texture2D;
  55. // byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
  56. string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg";
  57. PhotographDataManager.Instance.SavePicturoToLocal(bytes, fileName);
  58. }
  59. private async void OnClickBtnSavePhoto()
  60. {
  61. if (PoemPhotoDataManager.Instance.PersonalPhotoInfos.Count >= GlobalCfgArray.globalCfg.maxPhotoCount)
  62. {
  63. PromptController.Instance.ShowFloatTextPrompt("照片数量已达上限");
  64. return;
  65. }
  66. // Texture2D tex = this.viewData as Texture2D;
  67. // byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
  68. string[] rsp = await PoemPhotoSProxy.ReqTempPictureUrl((int)PictureType.jpg);
  69. if (rsp == null) return;
  70. Timers.inst.StartCoroutine(PoemPhotoSProxy.PushToHWCloud(rsp[0], bytes, async () =>
  71. {
  72. long result = await PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum);
  73. if (result > 0)
  74. {
  75. List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
  76. for (int i = 0; i < list.Count; i++)
  77. {
  78. if (list[i].PictureId == result)
  79. {
  80. list[i].Ntexture = new NTexture(tex);
  81. break;
  82. }
  83. }
  84. }
  85. }));
  86. }
  87. }
  88. }