示例#1
0
 /**
  * This is the main method in the Native Gallery Controller.
  * You can use this to open the gallery and show the images availble on the Device.
  */
 public static void OpenGallery(System.Action <Texture2D, ExifOrientation> callback)
 {
     if (instance == null)
     {
         var        prefab = Resources.Load("NativeGallery", typeof(GameObject));
         GameObject go     = (GameObject)GameObject.Instantiate(prefab);
         go.name = "NativeGallery";
         if (instance == null)
         {
             Debug.LogError("Cannot open Test gallery in editor mode since no instance of NativeGalleryController was found");
             callback(null, ExifOrientation.ORIENTATION_UNDEFINED);
             return;
         }
         else
         {
             Debug.Log("NativeGallery: We have autocreted the instance of the NativeGalleryp prefab in the scene");
         }
     }
     instance.gameObject.SetActive(true);
     if (UnityEngine.Application.isEditor == false && instance.editorGallery != null)
     {
         instance.editorGallery.SetActive(false);
     }
                 #if UNITY_ANDROID && (!UNITY_EDITOR || NATIVE_GALLERY_DEV)
     Tastybits.NativeGallery.AndroidGallery.LoadImageMethod = instance.LoadImageMethod;
                 #endif
     ImagePicker.OpenGallery((Texture2D tx, ExifOrientation orient) => {
         instance.gameObject.SetActive(false);
         callback(tx, orient);
     }, instance.rotateImportedImage, instance.iOSImagePickerType);
 }
示例#2
0
 public static void OpenGallery(System.Action <Texture2D> callback)
 {
     if (instance == null)
     {
         Debug.LogError("Cannot open Test gallery in editor mode since no instance of NativeGalleryController was found");
         callback(null);
         return;
     }
     instance.gameObject.SetActive(true);
     if (UnityEngine.Application.isEditor == false && instance.editorGallery != null)
     {
         instance.editorGallery.SetActive(false);
     }
     ImagePicker.OpenGallery(( Texture2D tx ) => {
         instance.gameObject.SetActive(false);
         callback(tx);
     });
 }
示例#3
0
        void OnGUI()
        {
            if (!useOnGUI)
            {
                return;
            }
            var  re = new Rect(Screen.width / 4f, Screen.width / 4f, Screen.width / 2f, Screen.width / 2f);
            bool cl = GUI.Button(re, "Start Gallery\nPick image from Galery");

            if (cl)
            {
                ImagePicker.OpenGallery((Texture2D tex, ExifOrientation orientation) => {
                    if (tex != null)
                    {
                        textureGotten         = tex;
                        lastFileNamePicked    = tex.name;
                        orientationLabel.text = "Orientation: " + orientation;
                        Debug.LogError("you picked the file : " + textureGotten.name);
                    }
                    else
                    {
                        textureGotten      = null;
                        lastFileNamePicked = "";
                    }
                }, rotateImportedImage, iOSImagePickerType);
            }

            if (null != textureGotten)
            {
                float boxH = Screen.height / 2f;
                if (buttonstyle == null)
                {
                    buttonstyle = new GUIStyle(GUI.skin.button);
                }
                buttonstyle.normal.background = textureGotten;
                var r = new Rect(0, Screen.height - (boxH), Screen.width, boxH);
                GUI.Box(r, textureGotten);
            }
        }