Esempio n. 1
0
 /// <summary>
 /// 打开相册 选择多张照片
 /// </summary>
 public static void OpenPhotos(Action <Texture2D[]> callBack)
 {
     NativeGallery.Permission permission = NativeGallery.GetImagesFromGallery((string[] path) =>
     {
         if (path == null || path.Length == 0)
         {
             return;
         }
         Texture2D[] texs = new Texture2D[path.Length];
         for (int i = 0; i < path.Length; i++)
         {
             try
             {
                 if (!string.IsNullOrEmpty(path[i]))
                 {
                     texs[i] = NativeGallery.LoadImageAtPath(path[i]);
                 }
             }
             catch (Exception ex) { Debug.LogWarning("第" + i + "张图片处理失败 : " + ex.Message + "\n" + path[i]); }
         }
         if (callBack != null)
         {
             callBack(texs);
         }
     });
     if (permission != NativeGallery.Permission.Granted)
     {
         ShowToast("当前没有相册访问权限,请在设置中打开");
         //打开应用程序设置
         if (NativeGallery.CanOpenSettings())
         {
             NativeGallery.OpenSettings();
         }
     }
 }
Esempio n. 2
0
 public void OnClick()
 {
     if (key == "")
     {
         //UIController.Instance.Push(uiName);
         NativeGallery.Permission p = NativeGallery.CheckPermission();
         // Debug.Log(p);
         if (p == NativeGallery.Permission.Granted)
         {
             PickImage(maxSize);
         }
         else if (p == NativeGallery.Permission.ShouldAsk)
         {
             if (NativeGallery.RequestPermission() == NativeGallery.Permission.Granted)
             {
                 PickImage(maxSize);
             }
         }
         else
         {
             //UIController.Instance.Pop("PhotoPermission");
             if (NativeGallery.CanOpenSettings())
             {
                 UIController.Instance.PushSelectHint("PhotoPermission", PhotoPermission, "提示开启相册权限", null, "设置", "取消");
             }
             else
             {
                 UIController.Instance.PushHint("PhotoPermission", "提示开启相册权限");
             }
         }
     }
     else if (key == "origin")
     {
         DataManager.Instance.getData("GameStatus").SetStringValue("PhotoName", "");
         UIController.Instance.Pop("PhotoSelect");
         EncryptionManager.SetString("PhotoName", "");
         EncryptionManager.Save();
     }
     else
     {
         DataManager.Instance.getData("GameStatus").SetStringValue("PhotoName", key);
         UIController.Instance.Pop("PhotoSelect");
         EncryptionManager.SetString("PhotoName", key);
         EncryptionManager.Save();
     }
 }
Esempio n. 3
0
    /// <summary>
    /// 保存视频到相册 : 从byte[]
    /// </summary>
    public static void SaveVideo(byte[] data, Action <bool> callBack = null)
    {
        try
        {
            NativeGallery.Permission permission = NativeGallery.SaveVideoToGallery(data, Application.productName, DateTime.Now.ToFileTime() + ".jpg", (string info) =>
            {
                if (info == null)
                {
                    ShowToast("保存视频成功 ! ");
                }
                else
                {
                    ShowToast("保存视频失败 : " + info);
                }

                if (callBack != null)
                {
                    callBack(info == null);
                }
            });
            if (permission != NativeGallery.Permission.Granted)
            {
                ShowToast("保存视频失败 : 没有权限");
                //打开应用程序设置
                if (NativeGallery.CanOpenSettings())
                {
                    NativeGallery.OpenSettings();
                }

                if (callBack != null)
                {
                    callBack(false);
                }
            }
        }
        catch (Exception ex)
        {
            ShowToast("保存视频失败 : " + ex.Message);

            if (callBack != null)
            {
                callBack(false);
            }
        }
    }
Esempio n. 4
0
 /// <summary>
 /// 打开相册 选择一张照片
 /// </summary>
 public static void OpenPhoto(Action <string> callBack)
 {
     NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((string path) =>
     {
         if (!string.IsNullOrEmpty(path) && callBack != null)
         {
             callBack(path);
         }
     });
     if (permission != NativeGallery.Permission.Granted)
     {
         ShowToast("当前没有相册访问权限,请在设置中打开");
         //打开应用程序设置
         if (NativeGallery.CanOpenSettings())
         {
             NativeGallery.OpenSettings();
         }
     }
 }
        /// <summary>
        /// Ajoute une interface de calque en demandant de choisir une nouvelle texture.
        /// </summary>
        public void AddLayer(Action <Texture2D> callback_)
        {
#if !UNITY_EDITOR
            if (NativeGallery.CheckPermission() != NativeGallery.Permission.Granted)
            {
                if (NativeGallery.RequestPermission() != NativeGallery.Permission.Granted &&
                    NativeGallery.CanOpenSettings())
                {
                    NativeGallery.OpenSettings();
                }
                else
                {
                    Application.Quit();
                }
            }

            if (!NativeGallery.IsMediaPickerBusy())
            {
                var workerObjAFCW_ = AugmentedFaceCreatorWorker.Instance_;

                var maxSize_ = Mathf.Max(workerObjAFCW_.TextureWidth_, workerObjAFCW_.TextureHeight_);

                NativeGallery.GetImageFromGallery((path_) =>
                {
                    var texture_ = NativeGallery.LoadImageAtPath(path_, maxSize: maxSize_, markTextureNonReadable: false, generateMipmaps: false);

                    AddLayer(texture_, false, false, true);

                    callback_?.Invoke(texture_);
                }, title: "Select a texture");
            }
#else
            var workerAFCW_ = WorkerObj_.GetComponent <AugmentedFaceCreatorWorker>();

            var texture_ = Texture2D.whiteTexture;
            texture_.Resize(1024, 512);
            texture_.Apply();

            AddLayer(texture_, false, false, true);

            callback_?.Invoke(texture_);
#endif
        }
Esempio n. 6
0
 /// <summary>
 /// 打开相册 选择多张照片
 /// </summary>
 public static void OpenPhotos(Action <string[]> callBack)
 {
     NativeGallery.Permission permission = NativeGallery.GetImagesFromGallery((string[] path) =>
     {
         if (path == null || path.Length == 0)
         {
             return;
         }
         if (callBack != null)
         {
             callBack(path);
         }
     });
     if (permission != NativeGallery.Permission.Granted)
     {
         ShowToast("当前没有相册访问权限,请在设置中打开");
         //打开应用程序设置
         if (NativeGallery.CanOpenSettings())
         {
             NativeGallery.OpenSettings();
         }
     }
 }