|
@@ -1,3 +1,4 @@
|
|
|
|
+using System;
|
|
using System.Collections;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using System.IO;
|
|
using FairyGUI;
|
|
using FairyGUI;
|
|
@@ -40,12 +41,20 @@ namespace GFGGame
|
|
|
|
|
|
#if UNITY_ANDROID
|
|
#if UNITY_ANDROID
|
|
|
|
|
|
- path = Application.persistentDataPath.IndexOf("Android") > 0 ? path.Substring(0, Application.persistentDataPath.IndexOf("Android")) + "DCIM/Camera/万世镜" : path + "/Pictures/万世镜";
|
|
|
|
|
|
+ path = Application.persistentDataPath.IndexOf("Android") > 0 ? path.Substring(0, Application.persistentDataPath.IndexOf("Android")) + "Pictures/万世镜" : path + "/Pictures/万世镜";
|
|
#endif
|
|
#endif
|
|
//判断目录是否存在,不存在则会创建目录
|
|
//判断目录是否存在,不存在则会创建目录
|
|
if (!Directory.Exists(path))
|
|
if (!Directory.Exists(path))
|
|
{
|
|
{
|
|
- Directory.CreateDirectory(path);
|
|
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ Directory.CreateDirectory(path);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception exception)
|
|
|
|
+ {
|
|
|
|
+ throw new Exception("创建文件夹失败, error:" + exception.Message);
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
string fileName = DateUtils.Instance.GetCurTime() + ".png";
|
|
string fileName = DateUtils.Instance.GetCurTime() + ".png";
|
|
path = path + "/" + fileName;
|
|
path = path + "/" + fileName;
|
|
@@ -53,9 +62,19 @@ namespace GFGGame
|
|
Debug.Log("文件路径:" + path);
|
|
Debug.Log("文件路径:" + path);
|
|
Texture2D tex = this.viewData as Texture2D;
|
|
Texture2D tex = this.viewData as Texture2D;
|
|
byte[] bytes = tex.EncodeToPNG();//将纹理数据,转化成一个png图片
|
|
byte[] bytes = tex.EncodeToPNG();//将纹理数据,转化成一个png图片
|
|
-
|
|
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ FileStream newFs = new FileStream(path, FileMode.Create, FileAccess.Write);
|
|
|
|
+ newFs.Write(bytes, 0, bytes.Length);
|
|
|
|
+ newFs.Close();
|
|
|
|
+ newFs.Dispose();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ throw new Exception("保存失败, error:" + ex.Message);
|
|
|
|
+ }
|
|
// string path = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("Android"));
|
|
// string path = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("Android"));
|
|
- File.WriteAllBytes(path, bytes);
|
|
|
|
|
|
+ // File.WriteAllBytes(path, bytes);
|
|
Timers.inst.StartCoroutine(GetSaveState(path));// ();
|
|
Timers.inst.StartCoroutine(GetSaveState(path));// ();
|
|
}
|
|
}
|
|
private IEnumerator GetSaveState(string path)
|
|
private IEnumerator GetSaveState(string path)
|