Azarian

Build Your Snowman

by Azarian

Build Your Snowman Unity

Screenshots

Build Your Snowman Unity
Build Your Snowman Unity

Specification

How to Use

Sample Code

using UnityEngine; using System.Collections; using System.IO; public class ScreenShot : MonoBehaviour { void OnMouseDown() { transform.localScale = new Vector3(0.9f,0.9f,1); } void OnMouseUp() { StartCoroutine(ScreenshotEncode()); transform.localScale = new Vector3(1,1,1); GetComponent&lt;AudioSource&gt;().Play(); } IEnumerator ScreenshotEncode() { yield return new WaitForEndOfFrame(); Texture2D texture = new Texture2D(Screen.width/2, Screen.height, TextureFormat.RGB24, false); texture.ReadPixels(new Rect(Screen.width/2, 0, Screen.width/2, Screen.height), 0, 0); texture.Apply(); yield return 0; byte[] bytes = texture.EncodeToPNG(); string Screen_Shot_File_Name = "ScreenShot" + System.DateTime.Now.ToString("_yyyy-MM-dd-hh-mm-ss") + ".png"; File.WriteAllBytes(Application.persistentDataPath + "/" + Screen_Shot_File_Name , bytes); Origin_Path = Application.persistentDataPath + "/" + Screen_Shot_File_Name; string Path = "/mnt/sdcard/DCIM/" + Screen_Shot_File_Name; if(System.IO.File.Exists(Origin_Path)) { Debug.Log("Path_move save is " + Path); System.IO.File.Copy(Origin_Path, Path); } DestroyObject( texture ); Invoke("SendShare",0.2f); } void SendShare() { Share("",Origin_Path,""); } string Origin_Path = ""; public void Share(string shareText, string imagePath, string url, string subject = "") { // it just work on android device 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://" + imagePath); intentObject.Call<AndroidJavaObject>("setType", "image/*"); intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), shareText); intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject); AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity"); AndroidJavaObject jChooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intentObject, subject); currentActivity.Call("startActivity", jChooser); } }

Video

Comments (0)

  • {{com.username}}
    {{com.username}}
    Buyer
    Seller

    {{com.username}}

    {{com.ctime}}

    {{com.content}}

    • {{com2.username}}
      {{com2.username}}
      Buyer
      Seller

      {{com2.username}}

      {{com2.ctime}}

      {{com2.content}}