Тема: Аркадні ігри для андроїд
Я зацікавився розробкою ігор за допомогою юніті... хочу спробувати створити декілька простих ігор з різним ігровим процесом. Якщо Вам цікаво ось моя друга гра...
https://play.google.com/store/apps/deta … topbullets
Поки що чомусь не працює Leaderboard i Acheivements, кнопка Share працює, але не на всіх смартфонах... буду розбиратися чому...
▼код кнопки Share (робить скріншот і поширює його разом з текстом)
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class ScriptShare : MonoBehaviour
{
    public Button buttonShareButton;
    public GameObject gameObjectGame;
    public GameObject CanvasCounter;
    public GameObject gameObjectGameOver;
    private bool boolIsFocus = false;
    private string stringShareSubject, stringShareMessage;
    private bool boolIsProcessing = false;
    private string stringScreenshotName;
    void Start()
    {
        buttonShareButton.onClick.AddListener(OnShareButtonClick);
    }
    void OnApplicationFocus(bool focus)
    {
        boolIsFocus = focus;
    }
    public void OnShareButtonClick()
    {
        stringScreenshotName = "StopBullets.png";
        stringShareSubject = "I Challenge You To Beat My High Score In \"Stop Bullets\"";
        stringShareMessage = "I Challenge You To Beat My High Score In \"Stop Bullets\". " +
        ". Get The \"Stop Bullets\" App From The Link Below. \n ---> https://play.google.com/store/apps/details?id=com.myrniihry.stopbullets?";
        ShareScreenshot();
    }
    private void voidFunction_PrepareToSharing()
    {
        /* first time turn on the game and turn off the interface, second time vice versa */
        gameObjectGame.SetActive(!gameObjectGame.activeSelf);
        CanvasCounter.SetActive(!CanvasCounter.activeSelf);
        gameObjectGameOver.SetActive(!gameObjectGameOver.activeSelf);
    }
    private void ShareScreenshot()
    {
#if UNITY_ANDROID
        if (!boolIsProcessing)
        {
            StartCoroutine(ShareScreenshotInAnroid());
        }
#else
        Debug.Log("No sharing set up for this platform.");
#endif
    }
#if UNITY_ANDROID
    public IEnumerator ShareScreenshotInAnroid()
    {
        boolIsProcessing = true;
        // wait for graphics to render
        yield return new WaitForEndOfFrame();
        string screenShotPath = Application.persistentDataPath + "/" + stringScreenshotName;
        voidFunction_PrepareToSharing();
        yield return new WaitForEndOfFrame();
        ScreenCapture.CaptureScreenshot(stringScreenshotName, 1);
        voidFunction_PrepareToSharing();
        yield return new WaitForSeconds(0.5f);
        if (!Application.isEditor)
        {
            //Create intent for action send
            AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
            AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
            intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
            //create image URI to add it to the intent
            AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
            AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + screenShotPath);
            //put image and string extra
            intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
            intentObject.Call<AndroidJavaObject>("setType", "image/png");
            intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), stringShareSubject);
            intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), stringShareMessage);
            AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
            AndroidJavaObject chooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intentObject, "Share Your High Score");
            currentActivity.Call("startActivity", chooser);
        }
        yield return new WaitUntil(() => boolIsFocus);
        boolIsProcessing = false;
    }
#endif
}
 