Unity/画像共有/NativeShare
提供: 初心者エンジニアの簡易メモ
目次
公式
https://github.com/yasirkula/UnityNativeShare?tab=readme-ov-file
インストール
unitypackage or PackageManager、どちらかでインストール
unitypackageからインストール
https://github.com/yasirkula/UnityNativeShare/releases unitypackageをDLしてインストール
PackageManagerからインストール
以下を追加
Packages/manifest.json
{
"dependencies": {
"com.yasirkula.nativeshare": "https://github.com/yasirkula/UnityNativeShare.git"
},
"scopedRegistries": [
{
"name": "OpenUPM",
"url": "https://package.openupm.com",
"scopes": [
"com.yasirkula.nativeshare"
]
}
]
}
テキストの共有のサンプルコード
new NativeShare()
.SetText("テキスト!")
.Share();
画像とテキストの同時共有のサンプルコード
using System.IO;
void OnClickShare()
{
Texture2D tex = ScreenCapture.CaptureScreenshotAsTexture();
byte[] png = tex.EncodeToPNG();
UnityEngine.Object.Destroy(tex);
// 一時ファイル保存
string filePath = Path.Combine(Application.temporaryCachePath, "shared_img.png");
File.WriteAllBytes(filePath, png);
// 共有
new NativeShare()
.AddFile(filePath)
.SetText("スクショと一緒に送るテキスト!")
.Share();
}
