Exemplo n.º 1
0
    public void PickImage(int maxSize)    //이미지를 가져오는 함수
    {
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            Debug.Log("Image path: " + path);
            if (path != null)
            {
                // Create Texture from selected image
                Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize);
                if (texture == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }
                Sprite sprite       = Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100f);
                profileImage.sprite = sprite;
                StartCoroutine(SaveImage(texture));
            }
        }, "Select a PNG image", "image/png");

        Debug.Log("Permission result: " + permission);
        if (permission == NativeGallery.Permission.Denied)
        {
            NativeGallery.OpenSettings();
        }
    }
Exemplo n.º 2
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();
         }
     }
 }
Exemplo n.º 3
0
    void PhotoPermission(SelectStatus b)
    {
        if (b == SelectStatus.YES)
        {
            NativeGallery.OpenSettings();
        }
        //else if (b == SelectStatus.NO)
        //{

        //}
    }
Exemplo n.º 4
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);
            }
        }
    }
Exemplo n.º 5
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
        }
Exemplo n.º 7
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();
         }
     }
 }
Exemplo n.º 8
0
        protected override void OnInit(QFramework.IUIData uiData)
        {
            mData = uiData as BindWIFIMessagePanelData ?? new BindWIFIMessagePanelData();

            if (Application.platform == RuntimePlatform.Android)
            {
                NativeGallery.RequestPermission((result, action) =>
                {
                    isSendMessage = true;
                    Log.I("RequestPermission: " + result);
                    if (result == (int)NativeGallery.Permission.Granted)
                    {
                        // InvokeRepeating("GetWifiInfo",1,1); 可以实时更新wifi,但无法修改wifi密码,暂时舍弃
                        NativeGallery.GetSomethingFromNative((json, action1) =>
                        {
                            if (json.IsNotNullAndEmpty())
                            {
                                isSSIDContains5G(json);
                                InputFieldSSID.text = json;
                                string pwd          = PlayerPrefsUtil.GetWiFiPWD(json);
                                if (pwd.IsNotNullAndEmpty())
                                {
                                    InputFieldPWD.text = pwd;
                                }
                                else
                                {
                                    InputFieldPWD.text = string.Empty;
                                }
                            }
                            Log.I("GetSomethingFromNative: " + json);
                        }, (int)NativeAction.Location);
                    }
                }, (int)NativeAction.Location);
            }
            else if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                if (NativeGallery.RequestIPhonePermission(2) == NativeGallery.Permission.Granted)
                {
                    NativeGallery.GetSomethingFromIPhone(result =>
                    {
                        if (result.IsNotNullAndEmpty())
                        {
                            InputFieldSSID.text = result;
                            isSSIDContains5G(result);
                            string pwd = PlayerPrefsUtil.GetWiFiPWD(result);
                            if (pwd.IsNotNullAndEmpty())
                            {
                                InputFieldPWD.text = pwd;
                            }
                            else
                            {
                                InputFieldPWD.text = String.Empty;
                            }
                        }
                    }, 1);
                }
            }

            var submit = Observable.Merge(
                InputFieldSSID.OnEndEditAsObservable().Where(_ => Input.GetKeyDown(KeyCode.Return)),
                BtnCommit.OnClickAsObservable().Select(_ => InputFieldSSID.text)
                );

            submit.Where(s => s != "")
            .Subscribe(s =>
            {
                AudioManager.PlaySound("Button_Audio");
                isSendMessage = false;
                if (saveWiFipwd)
                {
                    // 保存 WiFi ssid 和 pwd 到本地
                    PlayerPrefsUtil.SetWiFiSSIDPWD(InputFieldSSID.text, InputFieldPWD.text);
                }
                else
                {
                    PlayerPrefsUtil.SetWiFiSSIDPWD(InputFieldSSID.text, String.Empty);
                }

                Debug.Log("submit-确定 " + "ssid=" + s + "  pwd=" + InputFieldPWD.text);
                UIMgr.OpenPanel <BindDevicePanel>(new BindDevicePanelData()
                {
                    pwdStr  = InputFieldPWD.text,
                    ssidStr = InputFieldSSID.text
                }, UITransitionType.CIRCLE, this);
            }).AddTo(this);
            BtnClearPWD.OnClickAsObservable().Subscribe(_ =>
            {
                AudioManager.PlaySound("Button_Audio");
                InputFieldPWD.text = String.Empty;
            }).AddTo(this);
            BtnSSIDList.onClick.AddListener(() =>
            {
                AudioManager.PlaySound("Button_Audio");
#if UNITY_ANDROID
                NativeGallery.RequestPermission((result, action) =>
                {
                    Log.I("RequestPermission: " + result);
                    if (result == (int)NativeGallery.Permission.Granted)
                    {
                        NativeGallery.OpenWifiSettings();
                    }
                }, (int)NativeAction.Location);
#elif UNITY_IOS
                NativeGallery.OpenSettings();
#else
#endif
            });
            InputFieldSSID.OnValueChangedAsObservable().Subscribe((s =>
            {
                var texture2D = mResLoader.LoadSync <Texture2D>("ic_bindDetermine");
                if (s.Length > 0)
                {
                    texture2D = mResLoader.LoadSync <Texture2D>("ic_bindDetermine");
                }
                else
                {
                    texture2D = mResLoader.LoadSync <Texture2D>("btn_code_sel");
                }
                ImgDetermine.sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.one * 0.5f);
            })).AddTo(this);

            BtnShow.OnClickAsObservable().Subscribe(_ =>
            {
                AudioManager.PlaySound("Button_Audio");
                var texture2D = mResLoader.LoadSync <Texture2D>("ic_savepwd");
                showWiFipwd   = !showWiFipwd;
                if (showWiFipwd)
                {
                    texture2D = mResLoader.LoadSync <Texture2D>("btn_show_pwd");
                    InputFieldPWD.contentType = InputField.ContentType.EmailAddress;
                }
                else
                {
                    texture2D = mResLoader.LoadSync <Texture2D>("btn_hide_pwd");
                    InputFieldPWD.contentType = InputField.ContentType.Password;
                }

                var image    = BtnShow.transform.Find("Image").GetComponent <Image>();
                image.sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.one * 0.5f);
                InputFieldPWD.MyUpdateLabel();
            }).AddTo(this);

            BtnConnectTips.OnClickAsObservable().Subscribe(_ =>
            {
                AudioManager.PlaySound("Button_Audio");
                UIMgr.OpenPanel <BindCheckWIFIPanel>(new BindCheckWIFIPanelData(), UITransitionType.NULL);
            }).AddTo(this);

            BtnBack.OnClickAsObservable().Subscribe(_ =>
            {
                AudioManager.PlaySound("Button_Audio");
                Debug.Log("WiFi 返回");
                Back();
            }).AddTo(this);

            BtnSavepwd.OnClickAsObservable().Subscribe(_ =>
            {
                AudioManager.PlaySound("Button_Audio");
                Debug.Log("记住密码");
                saveWiFipwd   = !saveWiFipwd;
                var texture2D = mResLoader.LoadSync <Texture2D>("ic_savepwd");
                if (saveWiFipwd)
                {
                    texture2D = mResLoader.LoadSync <Texture2D>("ic_savepwd");
                }
                else
                {
                    texture2D = mResLoader.LoadSync <Texture2D>("ic_unsavepwd");
                }
                ImageSavePWD.sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.one * 0.5f);
            }).AddTo(this);


            SimpleEventSystem.GetEvent <TipConfirmClick>()
            .Subscribe(_ =>
            {
                if (_.GetAction == TipAction.Contains5GAlter)
                {
                    if (Application.platform == RuntimePlatform.IPhonePlayer)
                    {
                        NativeGallery.RequestPermission((result, action) =>
                        {
                            Log.I("RequestPermission: " + result);
                            if (result == (int)NativeGallery.Permission.Granted)
                            {
                                NativeGallery.OpenWifiSettings();
                            }
                        }, (int)NativeAction.Location);
                    }
                    else if (Application.platform == RuntimePlatform.IPhonePlayer)
                    {
                        NativeGallery.OpenSettings();
                    }
                }
            }).AddTo(this);

            // please add init code here
        }