| 
					
				 | 
			
			
				@@ -10,6 +10,7 @@ namespace GFGGame 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public class PhotographSaveView : BaseView 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         private UI_PhotographSaveUI _ui; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         protected override void OnInit() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             base.OnInit(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -21,6 +22,7 @@ namespace GFGGame 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             _ui.m_btnClose.onClick.Add(this.Hide); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             _ui.m_btnSave.onClick.Add(this.OnClickBtnSave); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         protected override void OnShown() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             base.OnShown(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -31,21 +33,21 @@ namespace GFGGame 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             _ui.m_imgRes.SetSize(width, height); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             _ui.m_imgBorder.SetSize(width, height + 12); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        private void OnClickBtnSave() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            string path = Application.persistentDataPath; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Debug.Log("文件路径path:" + path); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        protected override void OnHide() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            base.OnHide(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-#if UNITY_ANDROID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            int index = Application.persistentDataPath.IndexOf("Android"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            path = index < 0 ? path : Application.persistentDataPath.Substring(0, index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        public override void Dispose() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            base.Dispose(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-             path = "/sdcard/DCIM/"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        private void OnClickBtnSave() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            string path = Application.persistentDataPath + "/Pictures/WanshiJing/"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-#endif 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //判断目录是否存在,不存在则会创建目录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (!Directory.Exists(path)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -59,66 +61,23 @@ namespace GFGGame 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            string fileName = DateUtils.Instance.GetCurTime() + ".png"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            string fileName = "wsj" + DateUtils.Instance.GetCurTime() + ".jpg"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Debug.Log("文件路径:" + path); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Texture2D tex = this.viewData as Texture2D; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            byte[] bytes = tex.EncodeToPNG();//将纹理数据,转化成一个png图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             var filePath = path + fileName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //File.WriteAllBytes(filePath, bytes); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //GetSaveState(path); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            savePngAndUpdate(filePath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            File.WriteAllBytes(filePath, bytes); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            UpdateSystemPhoto(filePath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //调用iOS或Android原生方法保存图片后更新相册. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        private void savePngAndUpdate(string fileName) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        private void UpdateSystemPhoto(string filePath) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            PromptController.Instance.ShowFloatTextPrompt("功能暂未开放,敬请期待!", MessageType.WARNING); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #if UNITY_ANDROID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            GetAndroidJavaObject().Call("scanFile", fileName, "保存成功辣٩(๑>◡<๑)۶ "); //这里我们可以设置保存成功弹窗内容 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            AndroidJavaObject androidJavaObject = new AndroidJavaObject("com.gfg.gfgbrary.SaveImage"); //设置成我们aar库中的签名+类名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            androidJavaObject.Call("scanFile", filePath, "已保存至相册"); //这里我们可以设置保存成功弹窗内容 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #endif 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //用于获取Android原生方法类对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        private AndroidJavaObject GetAndroidJavaObject() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return new AndroidJavaObject("com.gfg.gfglibrary.SaveImage"); //设置成我们aar库中的签名+类名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        private void GetSaveState(string path) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Timers.inst.Add(1, 10, (param) => 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (File.Exists(path)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    string[] paths = { path }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    ScanFile(paths); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    PromptController.Instance.ShowFloatTextPrompt("保存成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //刷新图片,显示到相册中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        void ScanFile(string[] path) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            using (AndroidJavaClass PlayerActivity = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                AndroidJavaObject playerActivity = PlayerActivity.GetStatic<AndroidJavaObject>("currentActivity"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                using (AndroidJavaObject Conn = new AndroidJavaObject("android.media.MediaScannerConnection", playerActivity, null)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    Conn.CallStatic("scanFile", playerActivity, path, null, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        protected override void OnHide() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            base.OnHide(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        public override void Dispose() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            base.Dispose(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |