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>
/// <param name="text">Plain text to add.</param>
void AddText (string text);

Some payloads support adding plain text to be shared.

Adding Images

/// <summary>
/// Add an image to the payload from a pixel buffer.
/// The pixel buffer MUST have an RGBA8888 pixel layout.
/// </summary>
/// <param name="pixelBuffer">Pixel buffer containing image to add.</param>
/// <param name="width">Image width.</param>
/// <param name="height">Image height.</param>
void AddImage<T> (T[] pixelBuffer, int width, int height) where T : struct;

This method can be used to add images using raw pixel data. It accepts any array that can be interpreted as a pixel buffer with an RGBA8888 pixel layout. It can be used like so:

// Start a webcam texture
var webcamTexture = new WebCamTexture(...);
// Add the current frame to the payload
var payload = ...;
payload.AddImage(webCamTexture.GetPixels32(), webCamTexture.width, webCamTexture.height);

There is an overload which accepts a Texture2D, provided for convenience:

/// <summary>
/// Add an image to the payload.
/// </summary>
/// <param name="image">Image to add.</param>
void 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 add.</param>
void 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.