- サンプルシーン、サンプルコードはAssetに含まれていない
- 下記のように書いた
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using NatShareU;
public class NatShareSample : MonoBehaviour {
public Text timeText;
void Update()
{
timeText.text = Time.time.ToString();
}
public void OnClickShareScreenshot()
{
StartCoroutine(ShareScreenshotCoroutine());
}
IEnumerator ShareScreenshotCoroutine()
{
Debug.Log("clicked");
string fileName = "screenshot.png";
ScreenCapture.CaptureScreenshot(fileName);
yield return new WaitForSeconds(0.1f);
string imagePath = Application.persistentDataPath + "/" + fileName;
byte[] data = File.ReadAllBytes(imagePath);
Texture2D screenshotTexture = new Texture2D(Screen.width, Screen.height);
screenshotTexture.LoadImage(data);
NatShare.Share(screenshotTexture);
}
}
Tips
- アセットを検証する時は新たにプロジェクトを作った方が、ビルド・確認の回転が速くなって良い
- 上記コードのように待ちが必要な時はコルーチンを使っている
English ver