namespace UnityNative.Sharing
{
public interface IUnityNativeSharing
{
void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With", string mimeType = "image/*");
void ShareText(string shareText, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With");
}
public class UnityNativeSharing : IUnityNativeSharing
{
private readonly IUnityNativeSharingAdapter adapter;
///
/// Creates a UnityNativeSharing object with the correct platform setup. Use this if not being used with an IoC container
///
/// Interface for the detected platform
public static IUnityNativeSharing Create()
{
#if UNITY_ANDROID
return new UnityNativeSharing(new AndroidUnityNativeSharingAdapter());
#elif UNITY_IOS
return new UnityNativeSharing(new IosUnityNativeSharingAdapter());
#else
return new UnityNativeSharing(new NullUnityNativeSharingAdapter());
#endif
}
public UnityNativeSharing(IUnityNativeSharingAdapter adapter)
{
this.adapter = adapter;
}
///
/// Shares a screenshot with text
///
/// Text to share
/// The path to the attached file
/// Should the share dialog be opened (Android only)
/// The text to show on the share dialog (Android only)
/// Mime type of the file being shared (Android only)
public void ShareScreenshotAndText(string shareText, string filePath, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With", string mimeType = "image/*")
{
adapter.ShareScreenshotAndText(shareText, filePath, showShareDialogBox, shareDialogBoxText, mimeType);
}
///
/// Shares text
///
/// Text to share
/// Should the share dialog be opened (Android only)
/// The text to show on the share dialog (Android only)
public void ShareText(string shareText, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With")
{
adapter.ShareText(shareText, showShareDialogBox, shareDialogBoxText);
}
}
}