Advertisement
subzero911

Social Sharing for Quiz Game

Aug 25th, 2016
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SocialSharing : MonoBehaviour
  5. {
  6.     Texture2D screenshot;
  7.     public Canvas canvas;
  8.     public ScreensManager nav;
  9.     string status = "Я играю в викторину \"Саша Спилберг\".\nПомогите ответить на вопрос!";
  10.     string statusEN = "I am playing the \"New District\" game.\nPlease help me to answer this question!";
  11.  
  12.     public IEnumerator TakeScreenshot()
  13.     {
  14.         yield return new WaitForEndOfFrame();
  15.                  
  16.         int width = Screen.width;
  17.         int height = Screen.height;
  18.  
  19.         canvas.renderMode = RenderMode.ScreenSpaceCamera;
  20.  
  21.         RenderTexture rt = new RenderTexture(width, height, 24);
  22.         Camera.main.targetTexture = rt;
  23.  
  24.         screenshot = new Texture2D(width, height, TextureFormat.RGB24, false);
  25.  
  26.         Camera.main.Render();        
  27.  
  28.         RenderTexture.active = rt;
  29.         screenshot.ReadPixels(new Rect(0, 0, width, height), 0, 0);        
  30.         screenshot.Apply();
  31.  
  32.         Camera.main.targetTexture = null;
  33.         RenderTexture.active = null;
  34.         Destroy(rt);
  35.         canvas.renderMode = RenderMode.ScreenSpaceOverlay;
  36.     }
  37.  
  38.     void ShowQuestionPage()
  39.     {
  40.         //спрячем 2 страницы, закрывающие страницу вопросов
  41.         nav.askFriendsPage.SetActive(false);
  42.         nav.hintPage.SetActive(false);
  43.     }
  44.  
  45.     public void InstagramShare()
  46.     {
  47.         ShowQuestionPage();
  48.         StartCoroutine(TakeScreenshot());
  49.         UM_ShareUtility.InstagramShare(status, screenshot);
  50.         Debug.Log("Отправка в Instagram");        
  51.     }
  52.  
  53.     public void FacebookShare()
  54.     {
  55.         ShowQuestionPage();
  56.         StartCoroutine(TakeScreenshot());
  57.         UM_ShareUtility.FacebookShare(status, screenshot);
  58.         Debug.Log("Отправка в Facebook");
  59.         //Debug.Log("Share to Facebook");
  60.     }
  61.  
  62.     public void TwitterShare()
  63.     {
  64.         ShowQuestionPage();
  65.         StartCoroutine(TakeScreenshot());
  66.         UM_ShareUtility.TwitterShare(status, screenshot);
  67.         Debug.Log("Отправка в Twitter");
  68.     }
  69.  
  70.     public void ShareMedia()
  71.     {
  72.         ShowQuestionPage();
  73.         StartCoroutine(TakeScreenshot());
  74.         UM_ShareUtility.ShareMedia("Sasha Spilberg Celebrity Quiz", status, screenshot);
  75.         Debug.Log("Поделиться");
  76.     }
  77.  
  78.     public void VKShare()
  79.     {
  80.         //нужен плагин
  81.         Debug.LogError("Не реализована шарилка для VK", transform);
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement