Exemplo n.º 1
0
    /// <summary>
    /// Used for starting the ShateImage procedure. Called from inspector.
    /// </summary>
    public void ShareImage()
    {
        #if UNITY_ANDROID && !UNITY_EDITOR
        SaveImageForSharing(textureToSave, "TempImages", "Mandala_" + fileNameByDate);

        Share.ShareScreenshot(imageFinalPath);
        #elif UNITY_IOS && !UNITY_EDITOR
        SaveImageForSharing(textureToSave, "TempImages", "Mandala_" + fileNameByDate);

        GameObject shareButton = savePictureDialog.transform.Find("AnimationHolder/Body/ButtonsHolder/ButtonShare").gameObject;
        Vector3 [] tmp         = new Vector3[4];

        shareButton.GetComponent <RectTransform>().GetWorldCorners(tmp);
        //Debug.Log (tmp[0].ToString()+" "+tmp[1].ToString()+" "+tmp[2].ToString()+" "+tmp[3].ToString() );
        Vector3 center = new Vector3(tmp[0].x + Mathf.Abs(tmp[0].x - tmp[3].x) / 2f
                                     , tmp[0].y + Mathf.Abs(tmp[0].y - tmp[1].y) / 2f
                                     , tmp[0].z);
        //Debug.Log ("CENTER "+ center.ToString());
        Vector2 centerInPixels = RectTransformUtility.WorldToScreenPoint(Camera.main, center);
        OtherMessagesBinding.sendMessage("ShareImage###" + (int)centerInPixels.x + "###" + (int)centerInPixels.y + "###" + imageFinalPath);
        Debug.Log("ShareImage###" + (int)centerInPixels.x + "###" + (int)centerInPixels.y + "###" + imageFinalPath);
        #endif
    }
Exemplo n.º 2
0
    /// <summary>
    /// Saves the picture to device galery.
    /// </summary>
    /// <param name="texture">Tekstura koju zelimo da sacuvamo </param>
    /// <param name="directoryName">Ime direktrojuma koji zelimo da sacuvamo sliku.</param>
    /// <param name="pictureName">Ime slike bez ekstenzije.</param>
    void SavePicture(Texture2D texture, string directoryName, string pictureName)
    {
        if (!Directory.Exists(Application.persistentDataPath + "/" + directoryName))
        {
            Directory.CreateDirectory(Application.persistentDataPath + "/" + directoryName);
        }
        //Debug.Log (Application.persistentDataPath + "/test");
        byte[] bytes = texture.EncodeToPNG();

        File.WriteAllBytes(Application.persistentDataPath + "/" + directoryName + "/" + pictureName + ".png", bytes);

        #if UNITY_ANDROID && !UNITY_EDITOR
        string path2 = Share.ReturnGalleryFolder();
        //Debug.Log("NAIL path2 "+path2);
        if (path2 != "")
        {
            try
            {
                if (!Directory.Exists(path2 + directoryName))
                {
                    Directory.CreateDirectory(path2 + directoryName);
                }

                path2 += directoryName + "/" + pictureName + ".png";
                string path = Application.persistentDataPath + "/" + directoryName + "/" + pictureName + ".png";
                File.Copy(path, path2, false);
                imageFinalPath = path2;
                GameObject.Find("Canvas").GetComponent <MenuManager>().ShowPopUpMessageTitleText("PICTURE SAVED");
                GameObject.Find("Canvas").GetComponent <MenuManager>().ShowPopUpMessageCustomMessageText("Picture has been saved to your gallery.");
                Debug.Log("Mandala " + "picture saved at: " + imageFinalPath);
                //ShowPopUp("PICTURE SAVED"," ");
            }
            catch (Exception e)
            {
                Debug.Log("NAIL PATH 2 " + e.Message);
                GameObject.Find("Canvas").GetComponent <MenuManager>().ShowPopUpMessageTitleText("PICTURE NOT SAVED");
                GameObject.Find("Canvas").GetComponent <MenuManager>().ShowPopUpMessageCustomMessageText("Please grant the storage permission and try again!");
                //ShowPopUp("PICTURE  NOT SAVED"," ");
            }
        }
        else
        {
            Invoke("WaitAndShowFailure", 2f);
        }
        //MenuShare.anchoredPosition = hidePos;
        //bMenuShare = false;

        Share.RefreshGalleryFolder(path2);
        #endif

        #if UNITY_IOS && !UNITY_EDITOR
        OtherMessagesBinding.sendMessage("SaveToGallery###" + Application.persistentDataPath + "/" + directoryName + "/" + pictureName + ".png");
//        GameObject.Find("Canvas").GetComponent<MenuManager>().ShowPopUpMessageTitleText("PICTURE SAVED");
//        GameObject.Find("Canvas").GetComponent<MenuManager>().ShowPopUpMessageCustomMessageText("PICTURE IS SAVED TO YOUR GALERY");
        #endif


        #if UNITY_EDITOR
        GameObject.Find("Canvas").GetComponent <MenuManager>().ShowPopUpMessageTitleText("PICTURE SAVED");
        GameObject.Find("Canvas").GetComponent <MenuManager>().ShowPopUpMessageCustomMessageText(imageFinalPath);
        Debug.Log("picture saved");
        #endif
    }