|
|
| (同じ利用者による、間の3版が非表示) |
| 1行目: |
1行目: |
| ==NatShareとは==
| | [[Unity/画像共有/NatShare/基本]] |
| 画像共有プラグイン
| |
|
| |
|
| androidはversion7.0以上のみ対応
| | [[Unity/画像共有/NatShare/1.3.1バージョンアップ]] |
| | |
| 参考:https://nobushiueshi.com/unitysns%E5%85%B1%E6%9C%89%E3%81%AFnatshare%E3%81%8C%E3%81%8A%E3%81%99%E3%81%99%E3%82%81/
| |
| | |
| ==DL&Import==
| |
| NatShare(github):https://github.com/natmlx/NatShare | |
| | |
| githubのcodeからNatSuite-mainをDLし、Assets以下に設置。
| |
| | |
| x NatShare(UnityAssets):https://assetstore.unity.com/packages/tools/integration/natshare-mobile-sharing-api-117705
| |
| | |
| UnityAssetsでのインストールは、coreが競合する恐れがあるので、やめておく。詳しくは下の競合項目を。
| |
| | |
| ==テキストと画像共有==
| |
| <pre>
| |
| using UnityEngine;
| |
| using UnityEngine.UI;
| |
| using NatSuite.Sharing;
| |
| | |
| public class SampleScene : MonoBehaviour
| |
| {
| |
| void Start()
| |
| {
| |
| GameObject.Find("TextButton").GetComponent<Button>().onClick.AddListener(ShareText);
| |
| GameObject.Find("ImageButton").GetComponent<Button>().onClick.AddListener(ShareCaptureImage);
| |
| GameObject.Find("TextImageButton").GetComponent<Button>().onClick.AddListener(ShareTextCaptureImage);
| |
| }
| |
| // テキスト共有
| |
| void ShareText()
| |
| {
| |
| var payload = new SharePayload();
| |
| payload.AddText("ここに共有したいテキストを入力");
| |
| payload.Commit();
| |
| }
| |
| // キャプチャ画像共有
| |
| void ShareCaptureImage()
| |
| {
| |
| var screenshot = ScreenCapture.CaptureScreenshotAsTexture();
| |
| var payload = new SharePayload();
| |
| payload.AddImage(screenshot);
| |
| payload.Commit();
| |
| }
| |
| // テキスト&キャプチャ画像共有
| |
| void ShareTextCaptureImage()
| |
| {
| |
| var screenshot = ScreenCapture.CaptureScreenshotAsTexture();
| |
| var payload = new SharePayload();
| |
| payload.AddText("ここに共有したいテキストを入力");
| |
| payload.AddImage(screenshot);
| |
| payload.Commit();
| |
| }
| |
| // 通常画像共有
| |
| void ShareImage()
| |
| {
| |
| Texture2D texture = image.texture;
| |
| var payload = new SharePayload();
| |
| payload.AddImage(screetexturenshot);
| |
| payload.Commit();
| |
| }
| |
| void
| |
| CanvasImage.texture
| |
| }
| |
| </pre>
| |
| | |
| ==Androidビルド時にcore-1.6.0とjetified-core-1.0.0-rc02が競合するとき==
| |
| エラー詳細
| |
| java.lang.RuntimeException: Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in modules core-1.6.0-runtime.jar (androidx.core:core:1.6.0) and jetified-core-1.0.0-rc02-runtime.jar (:core-1.0.0-rc02:)
| |
| AdMobプラグインが、core-1.6.0を使ってるぽい。
| |
| | |
| 対応方法
| |
| #NatShareプラグインをUnityAssetsからDLしてる場合は、githubからDLするように
| |
| #NatShare-main/Plugins/Android/core-1.0.0-rc02.aarを削除
| |
| | |
| 参考:https://marumaro7.hatenablog.com/entry/natshareerror
| |
| | |
| ==iosでシェアの画像を保存ボタンを押すとクラッシュする問題==
| |
| エラー詳細
| |
| <pre>
| |
| [access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryAddUsageDescription key with a string value explaining to the user how the app uses this data.
| |
| </pre>
| |
| NSPhotoLibraryUsageDescriptionの権限がないため。
| |
| | |
| XcodePhotoLibraryPostProcessを自動で権限を付ける方法
| |
| | |
| Assets/Editor/XcodePhotoLibraryPostProcess.cs
| |
| <pre>
| |
| using System.Collections;
| |
| using System.Collections.Generic;
| |
| using System.IO;
| |
| using UnityEngine;
| |
| #if UNITY_IOS
| |
| using UnityEditor;
| |
| using UnityEditor.Build;
| |
| using UnityEditor.Build.Reporting;
| |
| using UnityEditor.iOS.Xcode;
| |
| | |
| public class XcodePhotoLibraryPostProcess : IPostprocessBuildWithReport
| |
| {
| |
| public int callbackOrder { get { return 0; } }
| |
| | |
| public void OnPostprocessBuild(BuildReport report)
| |
| {
| |
| if (report.summary.platform == BuildTarget.iOS)
| |
| {
| |
| string path = Path.Combine(report.summary.outputPath, "Info.plist");
| |
| PlistDocument plist = new PlistDocument();
| |
| plist.ReadFromFile(path);
| |
| plist.root.SetString("NSPhotoLibraryUsageDescription", "シェアボタンで共有時に画像を選択します");
| |
| plist.root.SetString("NSPhotoLibraryAddUsageDescription", "シェアボタンで共有時に画像を保存します");
| |
| plist.WriteToFile(path);
| |
| }
| |
| }
| |
| }
| |
| #endif
| |
| </pre>
| |
| 参考:https://nobushiueshi.com/unityios%E3%83%93%E3%83%AB%E3%83%89%E6%99%82%E3%81%ABnsphotolibraryaddusagedescription%E3%81%A8nsphotolibraryusagedescription%E3%82%92%E8%87%AA%E5%8B%95%E3%81%A7%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B/
| |