ISharePayload

interface NatSuite.Sharing.ISharePayload

This interface defines common functionality for all of the social sharing payloads which NatShare provides. As such, all payloads implement this interface.

Payloads are not thread safe, so they should only be used from the Unity main thread.

Adding Text

/// <summary>
/// Add text to the payload.
/// </summary>
ISharePayload AddText (string text);

Some payloads support adding text to be shared.

Adding Images

/// <summary>
/// Add an image to the payload.
/// </summary>
/// <param name="image">Image to the shared.</param>
ISharePayload AddImage (Texture2D image);

This method can be used to add images to be shared.

The added image must be readable. This is required because NatShare must encode the image to JPEG and share the encoded image.

Adding Media Files

/// <summary>
/// Add a media file to the payload.
/// </summary>
/// <param name="path">Path to media file to be shared.</param>
ISharePayload AddMedia (string path);

It is often desirable to share media files which live on the file system. This method allows for doing so. You can share audio files, image files, video files, and more with this method.

NatShare only supports sharing media files on the file system, not remote URL's.

Committing the Payload

/// <summary>
/// Commit the payload and return success value.
/// </summary>
Task<bool> Commit ();

Once you are done adding items to the payload, you can use this method to trigger the sharing action associated with the payload. The sharing action is asynchronous, and returns a bool indicating whether the items were successfully shared. It can be used like so:

// Create a payload and add items
var payload = new ...;
...
// Share and check whether sharing succeeded
var success = await payload.Commit();

Once the payload has been committed, it must not be used. Violating this rule will lead to a hard crash.