2023.02
Native Share for Android & iOSというAssetを利用してシェア機能を追加してみます。
asset store にあります。
https://github.com/yasirkula/UnityNativeShare
まずはスクリーンショットを
https://docs.unity3d.com/jp/current/ScriptReference/ScreenCapture.CaptureScreenshot.html
using UnityEngine;
// Generate a screenshot and save to disk with the name SomeLevel.png.
public class ExampleScript : MonoBehaviour
{
void OnMouseDown()
{
ScreenCapture.CaptureScreenshot("SomeLevel");
}
}シンプルですね^^
保存先は、 Application.persistentDataPath で、pngが付くか確認が必要
やっぱりpngは付きませんね、SomeLevel.pngとして実行したら付きますが^^;
ScreenCapture.CaptureScreenshot(“SomeLevel”);
とした場合は
string filePath = Application.persistentDataPath + "/SomeLevel" ;
です。SomeLevel.pngではありません!騙されないように^^;;;
Native Share はサンプル通り
new NativeShare().AddFile(filePath)
.SetSubject("THE COM Result").SetText(shareText).SetUrl("https://grtlab.com/")
.SetCallback((result, shareTarget) => Debug.Log("Share result: " + result + ", selected app: " + shareTarget))
.Share();
twitter投稿もこんな感じで◎



コメント