Пример #1
0
    private void PickImage(int maxSize)
    {
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            Debug.Log("Image path: " + path);
            if (path != null)
            {
                // Create Texture from selected image
                avatarTex = NativeGallery.LoadImageAtPath(path, maxSize);
                if (avatarTex == null)
                {
                    Debug.Log("Couldn't load sprite from " + path);
                    return;
                }

                avatarImage.sprite = Sprite.Create(avatarTex, new Rect(0.0f, 0.0f, avatarTex.width, avatarTex.height), new Vector2(0.5f, 0.5f), 100.0f);
            }
        }, "Select a PNG image", "image/png", maxSize);
        Debug.Log("Permission result: " + permission);
    }
    public void GetImage()
    {
        NativeGallery.Permission permission =
            NativeGallery.GetImageFromGallery((path) =>
        {
            if (path == null)
            {
                return;
            }

            // Create Texture from selected image
            imageFromGallery = NativeGallery.LoadImageAtPath(path, MAX_SIZE);
            if (imageFromGallery == null)
            {
                Debug.Log("Couldn't load texture from " + path);
            }

            imageObtained = true;
        }, "Select a PNG image", "image/png");
    }
Пример #3
0
    private 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);
                    text.text = "Couldn't load texture from " + path;
                    return;
                }

                // Assign texture to a temporary quad and destroy it after 5 seconds
                GameObject quad           = GameObject.CreatePrimitive(PrimitiveType.Quad);
                quad.transform.position   = Camera.main.transform.position + Camera.main.transform.forward * 2.5f;
                quad.transform.forward    = Camera.main.transform.forward;
                quad.transform.localScale = new Vector3(1f, texture.height / (float)texture.width, 1f);

                Material material = quad.GetComponent <Renderer> ().material;
                if (!material.shader.isSupported) // happens when Standard shader is not included in the build
                {
                    material.shader = Shader.Find("Legacy Shaders/Diffuse");
                }

                material.mainTexture = texture;

                Destroy(quad, 5f);

                // If a procedural texture is not destroyed manually,
                // it will only be freed after a scene change
                Destroy(texture, 5f);
            }
        }, "Select a PNG image", "image/png", maxSize); //

        Debug.Log("Permission result: " + permission);
        text.text = "Permission result: " + permission;
    }
    private 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;
                }

                //usersImage.Add(texture);
            }
        }, "Select a PNG image", "image/png");

        Debug.Log("Permission result: " + permission);
    }
Пример #5
0
    //Displays the text or the image of the card
    private void displayContent(string content, string path)
    {
        if (path == "" || path == null)
        {
            outputImage.SetActive(false);
            outputText.GetComponent <InputField>().text = content;
        }
        else
        {
            outputImage.SetActive(true);
            outputText.GetComponent <InputField>().text = "";

            Texture2D texture = NativeGallery.LoadImageAtPath(path);
            if (texture == null)
            {
                Debug.Log("Couldn't load texture from " + path);
                return;
            }
            outputImage.GetComponent <RawImage>().texture = texture;
        }
    }
Пример #6
0
 public static void ImportTexture(System.Action <Texture2D> callback)
 {
     CheckPermission(NativeGallery.GetImageFromGallery((path) => {
         if (path == null)
         {
             callback(null);
             return;
         }
         Texture2D texture = NativeGallery.LoadImageAtPath(path,
                                                           maxSize: 1024, markTextureNonReadable: false);
         if (texture == null)
         {
             DialogGUI.ShowMessageDialog(GUIManager.guiGameObject, "Error importing image");
         }
         else
         {
             Debug.Log("Dimensions: " + texture.width + ", " + texture.height);
         }
         callback(texture);
     }, "Select a texture image"));
 }
Пример #7
0
    public void GalleryPrompt()
    {
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            Debug.Log("Image path: " + path);
            if (path != null)
            {
                // Create Texture from selected image
                Texture2D texture = NativeGallery.LoadImageAtPath(path);
                if (texture == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }
                puzzleMaterial.mainTexture = texture;

                // If a procedural texture is not destroyed manually,
                // it will only be freed after a scene change
            }
        }, "Select a PNG image", "image/png");
    }
    //displays given, of either text or image of the card in the gameobject button
    private void DisplayFunc(GameObject contentObject, GameObject imageObject, string content, string path)
    {
        if (path == "" || path == null)
        {
            imageObject.SetActive(false);
            contentObject.GetComponent <InputField>().text = content;
        }
        else
        {
            imageObject.SetActive(true);
            contentObject.GetComponent <InputField>().text = "";

            Texture2D texture = NativeGallery.LoadImageAtPath(path);
            if (texture == null)
            {
                Debug.Log("Couldn't load texture from " + path);
                return;
            }
            imageObject.GetComponent <RawImage>().texture = texture;
        }
    }
    /// <summary>
    /// Loads an array of sprites. Either by importing images from device storage or the Resources folder.
    /// </summary>
    private void LoadSprites()
    {
        if (Variables.CustomBackgrounds)
        {
            List <Sprite> NewSprites = new List <Sprite>();

            for (int i = 0; i < paths.Length; i++)
            {
                // Create Texture from selected image
                Texture2D texture = NativeGallery.LoadImageAtPath(paths[i]);
                if (texture == null)
                {
                    //DebugText.text = "Couldn't load texture from " + paths[i];
                    Error.gameObject.SetActive(true);
                    return;
                }
                else
                {
                    Sprite mySprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f);

                    NewSprites.Add(mySprite);
                }
            }

            CustomSprites = NewSprites.ToArray();

            Backgrounds = CustomSprites;
        }
        else
        {
            Sprites     = Resources.LoadAll <Sprite>(Variables.BackgroundPath);
            Backgrounds = Sprites;
        }

        Variables.BackgroundsChanged = false;


        Shuffle();
        SetSprite(0);
    }
Пример #10
0
    private void PickImage(int maxSize)
    {
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            Debug.Log("Ruta de la imagen: " + path);

            if (path != null)
            {
                // Se crea una textura de la imagen seleccionada
                Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize);

                if (texture == null)
                {
                    Debug.Log("No se pudo cargar una textura de la ruta: " + path);
                    return;
                }

                // Se asigna la textura a un "quad" o plano y se destruye después
                // de 5 segundos para cargar otra imagen
                GameObject quad           = GameObject.CreatePrimitive(PrimitiveType.Quad);
                quad.transform.position   = Camera.main.transform.position + Camera.main.transform.forward * 2.5f;
                quad.transform.forward    = Camera.main.transform.forward;
                quad.transform.localScale = new Vector3(1f, texture.height / (float)texture.width, 1f);

                Material material = quad.GetComponent <Renderer>().material;

                if (!material.shader.isSupported)
                {
                    material.shader = Shader.Find("Legacy Shaders/Diffuse");
                }

                material.mainTexture = texture;

                Destroy(quad, 5f);
                Destroy(texture, 5f);
            }
        }, "Selecciona una imagen PNG", "image/png");

        Debug.Log("Resultado de los permisos: " + permission);
    }
Пример #11
0
        public void SelectImage()
        {
            _selectingImage = true;
            var maxSize = -1;

            var permission = NativeGallery.GetImageFromGallery((path) =>
            {
                Debug.Log("Image path: " + path);
                if (path == null)
                {
                    return;
                }
                // Create Texture from selected image
                var texture = NativeGallery.LoadImageAtPath(path, maxSize);
                if (texture == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }

                if (_instance != null)
                {
                    FindObjectOfType <GameDataManager>().AddImage(_instance.transform.localScale,
                                                                  _instance.GetComponent <SpriteRenderer>().sprite);
                }
                _instance = Instantiate(preview);
                _instance.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2.5f;
                _instance.transform.forward  = Camera.main.transform.forward;
                var spriteRenderer           = _instance.GetComponent <SpriteRenderer>();
                spriteRenderer.sprite        = Sprite.Create(texture,
                                                             new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
                _instance.transform.localScale = _instance.transform.localScale / 25f;

                _imageReady     = true;
                _selectingImage = false;
            }, "Select a PNG image", "image/png", maxSize);

            Debug.Log("Permission result: " + permission);
        }
Пример #12
0
    private void PickImage(int maxSize)
    {
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            Debug.Log("Image path: " + path);
            if (path == null)
            {
                return;
            }

            var texture = NativeGallery.LoadImageAtPath(path, maxSize, false, false);
            if (texture == null)
            {
                Debug.Log("Couldn't load texture from " + path);
                return;
            }

            MediaController.ME.SendPhoto(texture);
        }, "Select a PNG image", "image/png", maxSize);

        Debug.Log("Permission result: " + permission);
    }
Пример #13
0
    private void PickImage(int maxSize)
    {
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            if (path != null)
            {
                // Create Texture from selected image
                Texture texture = NativeGallery.LoadImageAtPath(path, maxSize);
                if (texture == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }
                //set image on surface
                defaultImageContainer.GetComponent <Renderer>().material.mainTexture = texture;
                image = texture;
                UpdateImageInFilter();
            }
        }, "Select a PNG image", "image/png", maxSize);

        Debug.Log("Permission result: " + permission);
    }
Пример #14
0
    private void TakePicture(int maxSize)
    {
        NativeCamera.Permission permission = NativeCamera.TakePicture((path) =>
        {
            Debug.Log("Image path: " + path);
            if (path == null)
            {
                return;
            }

            var texture = NativeGallery.LoadImageAtPath(path, maxSize, false, false);
            if (texture == null)
            {
                Debug.Log("Couldn't load texture from " + path);
                return;
            }

            MediaController.ME.SendPhoto(texture);
        }, maxSize);

        Debug.Log("Permission result: " + permission);
    }
Пример #15
0
    private 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;
                }

                mySprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f);
                GetComponent <Image>().sprite = mySprite;
            }
        }, "Select a PNG image", "image/png");

        Debug.Log("Permission result: " + permission);
    }
    public void DoItt()
    {
        NativeGallery.GetImageFromGallery((path) =>
        {
            Debug.Log("Image path: " + path);
            if (path != null)
            {
                // Create Texture from selected image
                Texture2D texturee = NativeGallery.LoadImageAtPath(path, 1024);     // image will be downscaled if its width or height is larger than 1024px
                if (texturee == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }
                img2.texture = texturee;
                tt           = TextureToTexture2D(img2.texture);

                // Use 'texture' here
                // ...
            }
        }, title: "Select single image", mime: "image/*");
    }
    public void GetPicture()
    {
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            Debug.Log("Image path: " + path);
            if (path != null)
            {
                // Create Texture from selected image
                Texture2D texture = NativeGallery.LoadImageAtPath(path, 1028);
                if (texture == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }

                //targetPicture.texture = texture;
            }
        }, "Select a PNG image", "image/png");

        Debug.Log("Permission result: " + permission);

        Debug.Log("Hello");
    }
Пример #18
0
    //displays the contents for the second side of the card
    //checks if text is empty then displays image,
    //if text not empty display text for card
    private void showSecondSide()
    {
        sideShowingText.GetComponent <Text>().text = "Second side";
        if (secondSideText == "" || secondSideText == null)
        {
            imageField.SetActive(true);
            cardSideInputField.GetComponent <InputField>().text = "";


            Texture2D texture = NativeGallery.LoadImageAtPath(imagePathSecondSide);
            if (texture == null)
            {
                Debug.Log("Couldn't load texture from " + imagePathSecondSide);
                return;
            }
            imageField.GetComponent <RawImage>().texture = texture;
        }
        else
        {
            imageField.SetActive(false);
            cardSideInputField.GetComponent <InputField>().text = secondSideText;
        }
    }
Пример #19
0
 public void OpenGalleryButton(Image TargetImg)
 {
     #if UNITY_EDITOR
     if (!ImagePicker.activeSelf)
     {
         ImagePicker.SetActive(true);
     }
     #endif
     #if UNITY_ANDROID
     Texture2D texture = new Texture2D(1, 1);
     NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
     {
         if (path != null)
         {
             texture = NativeGallery.LoadImageAtPath(path);
             Texture2D ReadableTexture = DuplicateTexture(texture);
             Sprite sprite             = Sprite.Create(ReadableTexture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100); // create a sprite with the data of the downloaded image
             TargetImg.sprite          = sprite;
         }
     });
     Destroy(texture);
     #endif
 }
Пример #20
0
    private void PickImage(int maxSize)
    {
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => {
            Debug.Log("Image Path : " + path);
            if (path != null)
            {
                Debug.Log("In here");
                // Create Texture from selected image
                texture = NativeGallery.LoadImageAtPath(path, maxSize, false);
                if (texture == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }

                img.texture = texture;
                Upbtn.SetActive(false);
                NextBtn.enabled = true;

                Debug.Log("Done");
            }
        }, "Select an image", "image/*");
    }
Пример #21
0
    private void PickImage(int maxSize, GameObject imageObj)
    {
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            Debug.Log("Image path: " + path);
            if (path != null)
            {
                // Create Texture from selected image
                Texture2D test = NativeGallery.LoadImageAtPath(path, maxSize);
                if (test == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    loaded = false;
                    return;
                }

                Sprite mySprite = Sprite.Create(test, new Rect(0.0f, 0.0f, test.width, test.height), new Vector2(0.5f, 0.5f), 100.0f);
                imageObj.transform.GetChild(0).GetComponent <Image>().sprite = mySprite;
            }
        }, "Select a PNG image", "image/png", maxSize);

        Debug.Log("Permission result: " + permission);
    }
Пример #22
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/*");
        //}
    }
Пример #23
0
    public void PickImage(int maxSize)
    {
        loadingText.SetActive(true);
        image.gameObject.SetActive(false);

        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            if (path != null)
            {
                Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize);
                if (texture == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }

                loadingText.SetActive(false);
                image.gameObject.SetActive(true);

                Sprite sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f));
                image.sprite  = sprite;
            }
        }, "Select an image", "image/*", maxSize);
    }
Пример #24
0
    public void TakePhoto(int maxSize = -1)
    {
        //调用插件自带接口,拉取相册,内部有区分平台
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            Debug.Log("Image path: " + path);
            //如果路径不为空
            if (path != null)
            {
                // 此Action为选取图片后的回调,返回一个Texture2D
                Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize);
                if (texture == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }
                Debug.Log(texture.name);
                //将获得的图片显示出来
                ShowPicture(texture);
            }
        }, "选择图片", "image/png", maxSize);

        Debug.Log("Permission result: " + permission);
    }
    /*private IEnumerator TakeScreenshotAndSave()
     * {
     *  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();
     *
     *  // Save the screenshot to Gallery/Photos
     *  Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(ss, "GalleryTest", "My img {0}.png"));
     *
     *  // To avoid memory leaks
     *  Destroy(ss);
     * }*/
    private void Load100Images(int maxSize)
    {
        ag = AndroidGallery.GetInstance("VRActor1");
        GameObject[] quads = GameObject.FindGameObjectsWithTag("Frame");
        Debug.Log("Load Frame Tages" + quads[0]);
        Debug.Log("Selected Quad : " + quads[0].transform.Find("Quad"));
        string[] imgs = ag.GetRecent100();
        int      i    = 0;

        foreach (GameObject q in quads)
        {
            if (imgs[i] != null)
            {
                // Create Texture from selected image
                Texture2D texture = NativeGallery.LoadImageAtPath(imgs[i], maxSize);
                if (texture == null)
                {
                    Debug.Log("Couldn't load texture from " + imgs[i]);
                    return;
                }
                GameObject quad     = q;
                Material   material = quad.transform.Find("Quad").GetComponent <Renderer>().material;
                if (!material.shader.isSupported) // happens when Standard shader is not included in the build
                {
                    material.shader = Shader.Find("Legacy Shaders/Diffuse");
                }

                material.mainTexture = texture;

                // If a procedural texture is not destroyed manually,
                // it will only be freed after a scene change
                //Destroy(texture, 5f);
                i++;
            }
        }
    }
Пример #26
0
    private Texture2D PickImage(int maxSize = -1)
    {
        Texture2D texture = new Texture2D(2, 2);

        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            Debug.Log("Image path: " + path);
            if (path != null)
            {
                // Create Texture from selected image
                maprenderer.material.mainTexture = NativeGallery.LoadImageAtPath(path, maxSize, false);
                float w = (float)maprenderer.material.mainTexture.width;
                float h = (float)maprenderer.material.mainTexture.height;

                float s = 10 / Mathf.Sqrt(w * h);

                map.transform.localScale = new Vector3(w * s, h * s, 1);
            }
        }, "Select a PNG image", "image/png");

        Debug.Log("Permission result: " + permission);

        return(texture);
    }
Пример #27
0
    private void PickImage(int maxSize)
    {
        //找尋路徑
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            if (path != null)
            {
                // Create Texture from selected image 目前尚未研究maxSize值得變化,目前設定都為512
                texture = NativeGallery.LoadImageAtPath(path, maxSize);
                //紀錄圖片的路徑,存到DataBase
                image_path = path;
                //找不到圖片
                if (texture == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }
                //進行切割圖片
                cutting(texture);
            }
        }, "Select a PNG image", "image/png", maxSize);

        Debug.Log("Permission result: " + permission);
    }
Пример #28
0
    public void PickImage()
    {
        int maxSize = 2048;

        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, false, true, false);
                //Texture2D copy = duplicateTexture(texture);
                Debug.Log("before width: " + texture.width);

                string imagePath = Application.persistentDataPath + "image_name.png";
                File.WriteAllBytes(imagePath, texture.GetRawTextureData());

                Texture2D loaded = new Texture2D(1, 1);
                if (File.Exists(imagePath))
                {
                    Debug.Log("File exists");
                    byte[] imageBytes = File.ReadAllBytes(imagePath);
                    loaded.LoadRawTextureData(imageBytes);
                    loaded.Apply();
                }
                else
                {
                    Debug.Log("File doesn't exist");
                }

                if (texture == null)
                {
                    Debug.Log("log 1");
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }

                Debug.Log("after width: " + loaded.width);
                Rect rect       = new Rect(0, 0, loaded.width, loaded.height);
                Vector2 vector2 = new Vector2(0.5f, 0.5f);
                Sprite sprite   = Sprite.Create(loaded, rect, vector2);
                imageToChange.ChangeSprite(sprite);

                //Debug.Log("Display Images Count After: " + RealmManager.realmManager.realm.displayImageAddresses.Count);

                //// Assign texture to a temporary quad and destroy it after 5 seconds
                //GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
                //quad.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2.5f;
                //quad.transform.forward = Camera.main.transform.forward;
                //quad.transform.localScale = new Vector3(1f, texture.height / (float)texture.width, 1f);

                //Material material = quad.GetComponent<Renderer>().material;
                //if (!material.shader.isSupported) // happens when Standard shader is not included in the build
                //    material.shader = Shader.Find("Legacy Shaders/Diffuse");

                //material.mainTexture = texture;

                //Destroy(quad, 5f);

                //// If a procedural texture is not destroyed manually,
                //// it will only be freed after a scene change
                //Destroy(texture, 5f);
            }
        }, "Select a PNG image", "image/png", maxSize);

        Debug.Log("Permission result: " + permission);
    }
Пример #29
0
    private void HandlePictureAddition(string[] paths)
    {
        var textures = paths.ToList().Select(path => NativeGallery.LoadImageAtPath(path, 700, false)).Where(t => t != null).ToList();

        HandlePictureAddition(textures);
    }
Пример #30
0
    //add new panorama to tour
    public void AddPhoto()
    {
        string new_photo_path = null;

        new_photo_path = FilePicker.PickImage(-1);

        Texture2D new_photo = null;

        //just create empty panorama if in unity editor
        #if !UNITY_EDITOR
        if (new_photo_path != null)
        {
            new_photo = NativeGallery.LoadImageAtPath(new_photo_path, -1, false);

            Vector3    new_pos               = new Vector3(editable_tour.panoramas.Count, editable_tour.panoramas.Count, 0) * panorama_prefab.transform.localScale.x;
            GameObject new_panorama          = Instantiate(panorama_prefab, new_pos, Quaternion.identity) as GameObject;
            Panorama   new_panorama_panorama = new_panorama.GetComponent <Panorama>();
            new_panorama_panorama.id   = editable_tour.panoramas.Count;
            new_panorama_panorama.link = new_photo_path;

            new_panorama.GetComponent <Renderer>().material.mainTexture = LoadPanorama(new_photo, new_photo_path);

            GameObject new_preview       = Instantiate(preview_prefab, scroll_content) as GameObject;
            Image      new_preview_image = new_preview.GetComponent <Image>();

            int axis = Math.Min(new_photo.height, new_photo.width);

            new_preview_image.sprite = Sprite.Create(new_photo, new Rect(0.0f, 0.0f, axis, axis), new Vector2(0.5f, 0.5f));


            PanoramaWithPreview new_panorama_with_preview = new_preview.GetComponent <PanoramaWithPreview>();
            panoramas.Add(new_panorama_with_preview);
            new_panorama_with_preview.preview    = new_preview_image;
            new_panorama_with_preview.panorama   = new_panorama_panorama;
            new_panorama_with_preview.OnPressed += OnPanoramaChosen;

            editable_tour.panoramas.Add(new_panorama_panorama);
        }
        #endif
        #if UNITY_EDITOR
        if (true)
        {
            new_photo_path = Application.dataPath + "/360_0051_stitched_injected.JPG";
            //new_photo = NativeGallery.LoadImageAtPath(new_photo_path, -1, false);

            Vector3    new_pos               = new Vector3(editable_tour.panoramas.Count, 2 * editable_tour.panoramas.Count, 0) * panorama_prefab.transform.localScale.x;
            GameObject new_panorama          = Instantiate(panorama_prefab, new_pos, Quaternion.identity) as GameObject;
            Panorama   new_panorama_panorama = new_panorama.GetComponent <Panorama>();
            new_panorama_panorama.id   = editable_tour.panoramas.Count;
            new_panorama_panorama.link = new_photo_path;

            GameObject new_preview       = Instantiate(preview_prefab, scroll_content) as GameObject;
            Image      new_preview_image = new_preview.GetComponent <Image>();

            PanoramaWithPreview new_panorama_with_preview = new_preview.GetComponent <PanoramaWithPreview>();
            panoramas.Add(new_panorama_with_preview);
            new_panorama_with_preview.preview    = new_preview_image;
            new_panorama_with_preview.panorama   = new_panorama_panorama;
            new_panorama_with_preview.OnPressed += OnPanoramaChosen;

            editable_tour.panoramas.Add(new_panorama_panorama);
        }
        #endif
    }