123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System.Collections;
- using System.IO;
- using FairyGUI;
- using UI.DressUp;
- using UnityEngine;
- namespace GFGGame
- {
- public class PhotographSaveView : BaseView
- {
- private UI_PhotographSaveUI _ui;
- 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);
- }
- protected override void OnShown()
- {
- base.OnShown();
- Texture2D tex = this.viewData as Texture2D;
- _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);
- }
- private void OnClickBtnSave()
- {
- string path = Application.persistentDataPath;
- Debug.Log("文件路径path:" + path);
- #if UNITY_ANDROID
- path = Application.persistentDataPath.IndexOf("Android") > 0 ? path.Substring(0, Application.persistentDataPath.IndexOf("Android")) + "/Pictures/万世镜/" : path + "/Pictures/万世镜/";
- #endif
- //判断目录是否存在,不存在则会创建目录
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- }
- string fileName = DateUtils.Instance.GetCurTime() + ".png";
- path = path + fileName;
- Debug.Log("文件路径:" + path);
- Texture2D tex = this.viewData as Texture2D;
- byte[] bytes = tex.EncodeToPNG();//将纹理数据,转化成一个png图片
- // string path = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("Android"));
- File.WriteAllBytes(path, bytes);
- Timers.inst.StartCoroutine(GetSaveState(path));// ();
- }
- private IEnumerator GetSaveState(string path)
- {
- yield return new WaitForEndOfFrame();
- if (File.Exists(path))
- {
- PromptController.Instance.ShowFloatTextPrompt("保存成功");
- }
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- public override void Dispose()
- {
- base.Dispose();
- }
- }
- }
|