Beispiel #1
0
    IEnumerator TakeHiResShot()
    {
        btBack.transform.localScale  = new Vector3(0, 0, 0);
        btPhoto.transform.localScale = new Vector3(0, 0, 0);

        yield return(new WaitForEndOfFrame());


#if UNITY_ANDROID
        screenCapture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
        screenCapture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
        screenCapture.Apply();

        NativeGallery.SaveToGallery(screenCapture, "Yokai", "my img {0}.jpeg");
#endif

#if UNITY_IOS
        screenCapture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
        screenCapture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
        screenCapture.Apply();

        byte[] screenshot = screenCapture.EncodeToPNG();

        _GetTexture(screenshot, screenshot.Length);
#endif

        btBack.transform.localScale  = new Vector3(1, 1, 1);
        btPhoto.transform.localScale = new Vector3(1, 1, 1);

        yield return(new WaitForSeconds(0.5f));

        DialogTwitter.SetActive(true);
    }
Beispiel #2
0
    public void ShareTwitter()
    {
#if UNITY_IOS
        DialogTwitter.SetActive(false);
        ScreenshotSaved();
#endif

#if UNITY_ANDROID
        SaveAndShare();
#endif
    }
Beispiel #3
0
    void SaveAndShare()
    {
        if (screenCapture != null)
        {
            try
            {
                DialogTwitter.SetActive(false);
                byte[] dataToSave  = screenCapture.EncodeToPNG();
                string destination = Path.Combine(Application.persistentDataPath, System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".png");
                File.WriteAllBytes(destination, dataToSave);

                AndroidJavaClass  intentClass  = new AndroidJavaClass("android.content.Intent");
                AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
                intentObject.Call <AndroidJavaObject>("setAction", intentClass.GetStatic <string>("ACTION_SEND"));

                AndroidJavaClass  uriClass  = new AndroidJavaClass("android.net.Uri");
                AndroidJavaObject uriObject = uriClass.CallStatic <AndroidJavaObject>("parse", "file://" + destination);

                intentObject.Call <AndroidJavaObject>("putExtra", intentClass.GetStatic <string>("EXTRA_STREAM"), uriObject);
                intentObject.Call <AndroidJavaObject>("setType", "image/png");
                intentObject.Call <AndroidJavaObject>("putExtra", intentClass.GetStatic <string>("EXTRA_TEXT"), "");
                AndroidJavaClass  unity           = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                AndroidJavaObject currentActivity = unity.GetStatic <AndroidJavaObject>("currentActivity");
                AndroidJavaObject jChooser        = intentClass.CallStatic <AndroidJavaObject>("createChooser", intentObject, "");
                currentActivity.Call("startActivity", jChooser);
            }
            catch (Exception e)
            {
                DebugConsole.Log(e.Message);
            }
        }
        else
        {
            DebugConsole.Log("Error !");
        }
    }