Getting Started
Up and Running in No Time
To begin, import the API with the Unity Package Manager by adding the following lines to your
Packages/manifest.json
file:{
"scopedRegistries": [
{
"name": "NatML",
"url": "https://registry.npmjs.com",
"scopes": ["ai.natml"]
}
],
"dependencies": {
"ai.natml.natshare": "1.3.0",
...
}
}
In order to use NatShare, you need a NatML access key. Retrieve your access key from NatML Hub:
https://hub.natml.ai/profile
Retrieve your access key on NatML Hub.
Once you have your access key, add it in
Project Settings > NatML
:
Specifying your NatML access key in Project Settings.
With NatShare imported, let's write a quick script to share a screenshot:
ShareScreenshot.cs
using UnityEngine;
using NatML.Sharing;
public class ShareScreenshot : MonoBehaviour {
void Start () {
// Capture a screenshot
var screenshot = ScreenCapture.CaptureScreenshotAsTexture();
// Create a share payload
using var payload = new SharePayload();
// Add the image
payload.AddImage(screenshot);
// Share!
payload.Share();
}
}
Add this component to any game object in your scene; build onto an iOS or Android device, and run. You should get a native popup asking the user to share the item!
Last modified 4mo ago