-
-
Notifications
You must be signed in to change notification settings - Fork 120
/
UnityNativeSharing.cs
58 lines (52 loc) · 2.66 KB
/
UnityNativeSharing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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;
/// <summary>
/// Creates a UnityNativeSharing object with the correct platform setup. Use this if not being used with an IoC container
/// </summary>
/// <returns>Interface for the detected platform</returns>
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;
}
/// <summary>
/// Shares a screenshot with text
/// </summary>
/// <param name="shareText">Text to share</param>
/// <param name="filePath">The path to the attached file</param>
/// <param name="showShareDialogBox">Should the share dialog be opened (Android only)</param>
/// <param name="shareDialogBoxText">The text to show on the share dialog (Android only)</param>
/// <param name="mimeType">Mime type of the file being shared (Android only)</param>
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);
}
/// <summary>
/// Shares text
/// </summary>
/// <param name="shareText">Text to share</param>
/// <param name="showShareDialogBox">Should the share dialog be opened (Android only)</param>
/// <param name="shareDialogBoxText">The text to show on the share dialog (Android only)</param>
public void ShareText(string shareText, bool showShareDialogBox = true, string shareDialogBoxText = "Select App To Share With")
{
adapter.ShareText(shareText, showShareDialogBox, shareDialogBoxText);
}
}
}