private IEnumerator TakeScreenshotAndSave()
  {
      NativeGallery.Permission permission = NativeGallery.CheckPermission();
      if (permission == NativeGallery.Permission.ShouldAsk)
      {
          permission = NativeGallery.RequestPermission();
      }
      else
      {
      }

      takingScreenshot = true;
      yield return(new WaitForEndOfFrame());

      Texture2D ss = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

      ss.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
      ss.Apply();
      fotos = Random.Range(10000, 99999);
      // Save the screenshot to Gallery/Photos
      string name = string.Format("foto_" + fotos + ".png", Application.productName, "{0}", System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));

      //Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(ss, Application.productName + " Captures", name));
      takingScreenshot = false;

      string stringX = "Permission result: " + NativeGallery.SaveImageToGallery(ss, Application.productName + " Captures", name);

      //textorefleja.text+=stringX;

      todo.SetActive(true);
      camaraimage.sprite = camarasprite;
  }
Beispiel #2
0
 void Update()
 {
     if (NativeGallery.CheckPermission() == NativeGallery.Permission.Granted)
     {
         SceneManager.LoadScene(sceneName);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Check if the suers has the proper android permissions to use the photo gallery
 /// </summary>
 void CheckPermissions()
 {
     if (NativeGallery.CheckPermission() == NativeGallery.Permission.ShouldAsk)
     {
         NativeGallery.RequestPermission();
     }
 }
Beispiel #4
0
 /// <summary>
 /// Open window for image pick. Work on IOS/Android
 /// </summary>
 public void UploadAvatarFromGallery()
 {
     if (NativeGallery.CheckPermission() != NativeGallery.Permission.Granted)
     {
         NativeGallery.RequestPermission();
     }
     NativeGallery.GetImageFromGallery(OnImagePicked);
 }
    public void Select()
    {
        var permission = NativeGallery.CheckPermission();

        if (permission == NativeGallery.Permission.Granted)
        {
            NativeGallery.GetImageFromGallery(OnImageSelected);
        }
        else
        {
            NativeGallery.RequestPermission();
        }
    }
  public void CaptureScreenshot()
  {
      camaraimage.sprite = transparentesprite;
      todo.SetActive(false);
      NativeGallery.Permission permission = NativeGallery.CheckPermission();
      if (permission == NativeGallery.Permission.ShouldAsk)
      {
          permission = NativeGallery.RequestPermission();
          //Debug.Log("Asking");
      }

      /**PERMISION CAMERA ANDROID
       * https://stackoverflow.com/questions/50875097/c-sharp-unity-script-to-take-and-save-screenshot-in-android-gallery-with-library
       */

      StartCoroutine(TakeScreenshotAndSave());
  }
Beispiel #7
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();
     }
 }
        /// <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
        }
Beispiel #9
0
    //Корутина скриншота
    IEnumerator TakeScreenShot(bool hideCanvas)
    {
        yield return(new WaitForEndOfFrame());

        try
        {
            var texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
            texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
            texture.Apply();
            WriteLogLine("NativeGallery.CheckPermission: " + NativeGallery.CheckPermission());
            NativeGallery.SaveImageToGallery(texture, "Photo from Unity AR", "PhotoAR{0}");
            Destroy(texture);
            if (hideCanvas)
            {
                canvas.SetActive(true);
            }
        } catch (Exception exc)
        {
            WriteLogLine(exc.Message);
        }
    }
Beispiel #10
0
 void Start()
 {
     if (Application.internetReachability != NetworkReachability.NotReachable)
     {
         NativeGallery.Permission permission = NativeGallery.RequestPermission();
         permission = NativeGallery.Permission.ShouldAsk;
         NativeGallery.RequestPermission();
         if (NativeGallery.CheckPermission() == NativeGallery.Permission.Granted)
         {
             SceneManager.LoadScene(sceneName);
         }
     }
     else
     {
         NativeGallery.Permission permission = NativeGallery.RequestPermission();
         permission = NativeGallery.Permission.ShouldAsk;
         NativeGallery.RequestPermission();
         if (NativeGallery.CheckPermission() == NativeGallery.Permission.Granted)
         {
             SceneManager.LoadScene(sceneName);
         }
     }
 }
Beispiel #11
0
    public void RetrieveImage()
    {
        if (NativeGallery.CheckPermission() != NativeGallery.Permission.Granted)
        {
            NativeGallery.Permission permission = NativeGallery.RequestPermission();

            CodelabUtils._ShowAndroidToastMessage("Please Grant the permission before you continue");
        }
        //else
        //{
        NativeGallery.Permission permissionr =
            NativeGallery.GetImageFromGallery((path) =>
        {
            if (path != null)
            {
                CodelabUtils._ShowAndroidToastMessage($"Image path {path}");
                // Create Texture from selected image
                Texture2D texture = NativeGallery.LoadImageAtPath(path, 512);

                if (texture == null)
                {
                    CodelabUtils._ShowAndroidToastMessage($"Could not load texturee from {path}");
                    CodelabUtils._ShowAndroidToastMessage($"Could not load texturee from {path}");
                    return;
                }

                // add to the list of texture item
                AddItem(new Item(texture, path));

                refreshList();

                /*StartCoroutine(StoreImages(new Item(texture, path),
                 *  path.Substring(path.Length - 10, path.Length)));*/
            }
        }, "Select an Image", "image/*");
        //}
    }