|
@@ -43,7 +43,7 @@ namespace GFGGame
|
|
|
int index = Application.persistentDataPath.IndexOf("Android");
|
|
|
path = index < 0 ? path : Application.persistentDataPath.Substring(0, index);
|
|
|
|
|
|
- // path = "file://sdcard/DCIM/";
|
|
|
+ path = "/sdcard/DCIM/";
|
|
|
|
|
|
#endif
|
|
|
//判断目录是否存在,不存在则会创建目录
|
|
@@ -65,9 +65,27 @@ namespace GFGGame
|
|
|
Debug.Log("文件路径:" + path);
|
|
|
Texture2D tex = this.viewData as Texture2D;
|
|
|
byte[] bytes = tex.EncodeToPNG();//将纹理数据,转化成一个png图片
|
|
|
- File.WriteAllBytes(path + "/Pictures/wanshijing/" + fileName, bytes);
|
|
|
- GetSaveState(path);
|
|
|
+ var filePath = path + fileName;
|
|
|
+ File.WriteAllBytes(filePath, bytes);
|
|
|
+ //GetSaveState(path);
|
|
|
+ savePngAndUpdate(filePath);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //调用iOS或Android原生方法保存图片后更新相册.
|
|
|
+ private void savePngAndUpdate(string fileName)
|
|
|
+ {
|
|
|
+#if UNITY_ANDROID
|
|
|
+ GetAndroidJavaObject().Call("scanFile", fileName, "保存成功辣٩(๑>◡<๑)۶ "); //这里我们可以设置保存成功弹窗内容
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ //用于获取Android原生方法类对象
|
|
|
+ private AndroidJavaObject GetAndroidJavaObject()
|
|
|
+ {
|
|
|
+ return new AndroidJavaObject("com.gfg.saveimagelibrary.SaveImageActivity"); //设置成我们aar库中的签名+类名
|
|
|
+ }
|
|
|
+
|
|
|
private void GetSaveState(string path)
|
|
|
{
|
|
|
|