1. Shares and referrals
2. GIF customization
3. Save recordings
4. Testing
5. Troubleshooting

1. Shares and referrals

1.1 Custom sharing text

Make the default sharing text personal and custom for each place you use it

Megacool.Instance.SharingText = "Try to beat my score!";

1.2 Share object

MegacoolShare is an object for everything related to a share. It contains a State of the share, CreatedAt, UpdatedAt, Data and an Url. With this, you can add your own data and a path and query which will be merged with the final link like this: 'https://mgcl.co/appId/level5/battle?_m=12345678&username=nbroby'.

string urlString = "level5/battle?username=nbroby";
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add ("welcomeText", "Nick has invited you!");
MegacoolShare share = new MegacoolShare(urlString, data);
Megacool.Instance.Share(new MegacoolShareConfig {
Share = share
});

The share object can be passed as an argument to Megacool.Instance.Share as shown above. When the receiving user presses the link, the app will open and the share object will be received through a MegacoolEvent in start(Action<MegacoolEvent> eventHandler) which you can read more about in 1.2 below.

1.2 Tracking shares

In addition to customizing the link and adding data from the sender, you can fetch this information on the receiving side to e.g.:

  • reward your users for referring friends,
  • send users to a specific place in the app, and
  • automatically make two users friends.

start(Action<MegacoolEvent> eventHandler) is a function passing an array of MegacoolEvent from the server. A MegacoolEvent can contain a MegacoolShare object.

There are three main events to handle when a receiving user clicks a link:

1.2.1 Received share opened

When a receiving user clicks a link to either open or install your app, start(Action<MegacoolEvent> eventHandler) will receive the MegacoolEvent from the server right after the app is opened. The MegacoolEvent.Type is ReceivedShareOpened. FirstSession is a boolean telling whether the app was opened for the first time (new install) or just opened. The MegacoolEvent.Share contains the MegacoolShare object that was sent. With the data from the MegacoolShare object you can reward the user and give a custom onboarding experience.

You can improve the experience for existing users by sending them to the right place in your app immediately after they've clicked the link through Universal Link. E.g. to a game session. This is only for users that have the app installed. A MegacoolEvent where MegacoolEvent.Type is LinkClicked will be triggered. The MegacoolEvent has a MegacoolEvent.Data with the Path, Query, ReferralCode and URL from the link. In this case, the MegacoolShare object is nil because it has to be fetched from the server which is handled in Received Share Opened above.

1.2.3 Sent share opened

The sender gets a MegacoolEvent of the type SentShareOpened when the receiver has opened the app from the shared link. The MegacoolEvent contains FirstSession to indicate whether the app was installed or just opened. This can be used to reward the sender. In addition MegacoolEvent.Data contains the receiving user's id from receiverUserId. This can be used to add the receiving user as a friend.

1.2.4 Implementation

Replace the initializer code from Quickstart with the following:

void Start() {
Megacool.Instance.Start(e => {
switch (e.Type) {
/* THIS DEVICE */
// ReceivedShareOpened
// This device has received a share to the app, including a share object
case MegacoolEvent.MegacoolEventType.ReceivedShareOpened:
Debug.Log("Event ReceivedShareOpened");
Debug.Log(e);
string invitedById = e.Share.ReferralCode.InviteId;
if(e.FirstSession){
//First session means it's a new install
Debug.Log("WelcomeText " + e.Share.Data["welcomeText"]);
//Add your friend to the friends list - based on InviteId
Debug.Log("New install for this device, invited by: "+ invitedById);
}
else{
//The app is already installed
Debug.Log("WelcomeText " + e.Share.Data["welcomeText"]);
Debug.Log("Open app, invited by: "+ invitedById);
}
break;
// LinkClicked
// The app has been opened from a link click, send the user instantly to
// the right scene if the URL path exists
case MegacoolEvent.MegacoolEventType.LinkClicked:
Debug.Log("Event LinkClicked");
Debug.Log("Url: " + e.Data["url"]);
Debug.Log("Invited by: " + ((MegacoolReferralCode)e.Data["referralCode"]).InviteId);
break;
// SentShareOpened
// A Friend has received a share from your device
case MegacoolEvent.MegacoolEventType.SentShareOpened:
Debug.Log("Event SentShareOpened");
string sentInviteToId = e.Data["receiverUserId"];
if(e.FirstSession){
//First session means your friend just installed the app
Debug.Log("First session for friend with id: "+ sentInviteToId);
}
else{
//The app was already installed and the friend opened it from your link
Debug.Log("New session for friend with id: "+ sentInviteToId);
}
break;
}
});
}

1.3 Share state

Call GetShares to get the latest State of a sent share. The locally cached shares will be returned immediately and are useful to determine the total number of shares. If the function is non-nil a request will be sent to the server to get the latest State update for each share.

States can be:

  • MegacoolShare.MegacoolShareState.Sent
  • MegacoolShare.MegacoolShareState.Clicked
  • MegacoolShare.MegacoolShareState.Opened
  • MegacoolShare.MegacoolShareState.Installed
Megacool.Instance.GetShares(shares => {
for (int i = 0; i < shares.Count; i++) {
if (shares[i].State == MegacoolShare.MegacoolShareState.Clicked){
Debug.Log("Share sent on " + shares[i].CreatedAt + " was clicked");
}
}
});

You can use the share state to show the user how many friends users have invited and what the state is:

To delete local shares you don’t need updates from anymore, simply call DeleteShares, where filter is a function with MegacoolShare as an argument. Based on State, CreatedAt, UpdatedAt etc. you can return true to delete the share object or false to keep it. If you call this method around GetShares, make sure GetShares has completed the request to the server, otherwise the deleted shares will just be re-added.

Megacool.Instance.DeleteShares(share => {
return share.State == MegacoolShare.MegacoolShareState.Installed;
});

1.4 Share directly to channels

iOS only

Ready to integrate a breathtaking solution? Megacool makes it possible to get deeply integrated into the most popular services for a better user experience. Instead of showing the share modal view with a lot of options, it's possible to add your own buttons that share directly to the channels.

It's possible to customize the share channels below by passing a config as argument. More on that in the following sections.

We recommend to show buttons for the channels below and a general button that calls Megacool.Instance.Share using this icon .

1.4.1 Messenger

Megacool has integrated the Messenger API. To share to Messenger you simply create a button with a Messenger icon that calls this method instead of Megacool.Instance.Share:

Megacool.Instance.ShareToMessenger();

In addition you also have to configure XCode according to Facebook's Getting Started guide: Configure Xcode Project

There are two ways for a user to share a GIF to Messenger, either by selecting friend(s) or send it as a reply to a previous conversation. Sending as a reply to a previous conversation requires that the user has opened your app from a conversation in Messenger.

Note: Sharing directly to Messenger doesn't support only sharing a URL. You have to provide a GIF and a fallback image, in case the GIF fails, or just a fallback image. Go to Fallback image to learn how to add a fallback image.

Note 2: When your app is installed from a direct Messenger share, the receiver will never get a Received share opened event. Hence you shouldn't use this for rewarded referrals. Opening shares with your app already installed works as expected.

1.4.2 Twitter

The native share feature to Twitter has a tiny issue. It converts GIFs to JPG. For users running <iOS11 we are solving this with the following function:

Megacool.Instance.ShareToTwitter();

Note: The first time a user choose Twitter, a prompt will ask to get access to their Twitter account.

Note 2: We are working on a solution for users on iOS11.

1.4.3 iMessage

Sharing directly to iMessage gives a better user experience.

Megacool.Instance.ShareToMessages();

1.4.4 Mail

Sharing directly to Mail gives a better user experience.

Megacool.Instance.ShareToMail();

1.5 Delegates after a share

iOS only

To know when the share view completes add this code:

Megacool.Instance.CompletedSharing += () => {
Debug.Log("Did Complete Share");
};
Megacool.Instance.DismissedSharing += () => {
Debug.Log("Did Dismiss Share");
};

2. GIF customization

2.1 Rendering preview

This creates a rendered preview of the GIF that can be displayed to the user before sharing.

  1. Drag the MegacoolPreviewCanvas Prefab to your scene

  2. In the script where you want to control the preview, add a public field with type MegacoolGifPreview. This will expose the megacoolGifPreview field in the inspector for the GameObject.

    public MegacoolGifPreview megacoolGifPreview;
  3. Drag the MegacoolGifPreview GameObject onto the open field in the inspector of the GameObject you use. This will attach an instance of the MegacoolGifPreview object to the public field.

You can now call StartPreview and StopPreview to display or hide the preview.

megacoolGifPreview.StartPreview();
megacoolGifPreview.StopPreview();

2.2 Recording frame rate

Set numbers of frames to record per second. Recommended range: 1 - 10. The default is 10:

Megacool.Instance.FrameRate = 5;

Set the frame rate right before calling Megacool.Instance.StartRecording.
NB: This only applies to recordings made with Megacool.Instance.StartRecording, not Megacool.Instance.CaptureFrame.

Frame rate examples (with Playback frame rate: 10):

Frame rate: 5
Frame rate: 10
Frame rate: 25

2.3 Playback frame rate

Set the number of frames per second when playing the GIF. The default is 10 frames / second. The GIF will be exported with this frame rate and it doesn't affect the recording frame rate.

Megacool.Instance.PlaybackFrameRate = 5;

Make sure to call setPlaybackFrameRate before Megacool.Instance.Share when sharing the GIF.

Playback frame rate: 5
Playback frame rate: 10
Playback frame rate: 25

2.4 Max frames

Max number of frames to record, default is 50 frames. Change the maximum amount of captured frames by setting:

Megacool.Instance.MaxFrames = 25;
Max frames: 25
Max frames: 50
Max frames: 100

2.5 Delay last frame

Set a delay (in milliseconds) for the last frame of the GIF. The default is 1 second to give a natural break before the GIF loops again.

Megacool.Instance.LastFrameDelay = 2000;
No extra delay on the last frame
1000 ms delay (default)
2000 ms delay

2.6 Last frame overlay

iOS only

With last frame overlay you can add a transparent image on top of the last GIF frame.

+ =

Create a folder called StreamingAssets if you don't have it already and add the overlay image to the folder. Then call:

Megacool.Instance.setDefaultLastFrameOverlay("overlay.png");

Note 1: Given that the GIF color space is 256 colors, additional colors in the overlay image might mess up your coloring when the GIF is generated. Make sure to test this properly.

Note 2: On some channels GIFs may get cropped depending on the aspect ratio. To be on the safe side, make sure to place the text within the visible preview area on different channels with the following aspect ratio:

  • (1:1.4) Facebook, iMessage
  • (1:1.1) Twitter

->

2.7 Fallback image

iOS only

Fallback image let's you share a predefined image in cases where you don't want a recording or if a recording has failed. The fallback image can be JPG, PNG or even a GIF!

Create a folder called StreamingAssets if you don't have it already and add the fallback image to the folder. Include the parameter FallbackImage when calling Share:

Megacool.Instance.Share(new MegacoolShareConfig {
FallbackImage = "fallbackImage.png"
});

When choosing your image please keep in mind that there's a size limit for each social media platform, so use a reasonable size. E.g. Twitter has a 3MB limit for uploading an image.

Note: The image will not be uploaded on the following platforms because they only support sharing links:

  • Facebook
  • Facebook Messenger

2.9 Timelapse

Identical to the normal captureFrame, but timelapse has different behavior when overflowing MaxFrames. If it's about to overflow, it will delete every other frame captured so far, and half the rate of capturing (thus only storing every second image on the first overflow, every fourth image on the next, and so on).

Megacool.Instance.CaptureFrame(new MegacoolFrameCaptureConfig {
OverflowStrategy = MegacoolOverflowStrategy.TIMELAPSE
});

Timelapse

2.9.1 Force add

iOS only

If you want to guarantee that a frame is added to the timelapse (like an end screen or final state of the game), pass a ForceAdd = true parameter in config like this:

Megacool.Instance.CaptureFrame(new MegacoolFrameCaptureConfig {
OverflowStrategy = MegacoolOverflowStrategy.TIMELAPSE,
ForceAdd = true
});

Important: Only pass this parameter once! Normally this function returns as soon as it has spawned a thread to do the actual capture, but if you pass ForceAdd = true it will run synchronously (e.g. not return until it has actually stored the frame. This is because usually this is called as the last step before a session ends and then GIF is created, thus we need the call to complete before creating the GIF. This enables you to change visible elements on the screen after this call completes and be sure that it's not going to be included in the GIF.

2.10 Color table

iOS only

A gif consists of 256 colors and there are two ways to set the color table. We recommend testing both options to see which looks best for your particular app. Default is Color table fixed.

2.10.1 Fixed

This is a fixed color table, which is very fast since no analysis is needed and performs well in the general case, but usually underperforms when representing nuanced differences and gradients.

Go to Megacool -> Configuration -> GIF Color Table and select Gif Color Table Fixed

2.10.2 Analyze first frame

The first frame is analyzed to generate a representative color table. This requires more CPU to create the GIF, but often yields better results when a GIF contains many shades of the same color. If new colors are introduced later in the GIF they will not be as accurately represented.

Go to Megacool -> Configuration -> GIF Color Table and select Gif Color Table Analyze First


3. Save recordings

Save and resume recordings is useful for combining multiple game sessions together. These recordings are stored to disk to be retrieved and potentially resumed later. This is a great case for games like Words with Friends where waiting for the other user to finish the round could take many hours, and still create a GIF of the whole game play.

3.1 Start and resume a recording

All completed recordings will by default be deleted whenever a new recording is started with either Megacool.Instance.CaptureFrame or Megacool.Instance.StartRecording. To save a recording you can set Megacool.Instance.KeepCompletedRecordings = true;.

To save multiple recordings you can set a recording id RecordingId in the config dictionary at StartRecording(MegacoolRecordingConfig config) or CaptureFrame(MegacoolFrameCaptureConfig config). The RecordingId can be anything you prefer, for instance a name of the current level like "level3".

A recording with a given RecordingId can be resumed until Megacool.Instance.StopRecording is called. After calling Megacool.Instance.StopRecording you can either share the recording or start a new one from scratch with the same RecordingId.

//Save recording of level 3 to disk
Megacool.Instance.KeepCompletedRecordings = true;
Megacool.Instance.StartRecording(new MegacoolRecordingConfig(
recordingId: "level3"
));

3.2 Pause recording

When you want to pause a recording that can be continued later, you call PauseRecording.

Megacool.Instance.PauseRecording();

3.3 Delete recording

DeleteRecording will remove any frames of the recording in memory and on disk. Both completed and incomplete recordings will take space on disk, thus particularly if you're using Megacool.Instance.KeepCompletedRecordings = true; you might want to provide an interface to your users for removing recordings they don't care about anymore to free up space for new recordings.

Megacool.Instance.DeleteRecording("level3");

3.4 Show a GIF from a specific recording

To show a GIF from a specific recording you pass the RecordingId parameter to Megacool.Instance.StartPreview.

Megacool.Instance.StartPreview("level3");

3.5 Share a GIF from a specific recording

To share a GIF from a specific recording you pass the RecordingId as a parameter to Share(ShareConfig config).

Megacool.Instance.Share(new MegacoolShareConfig {
RecordingId = "level3"
});

Note: Megacool.Instance.Share calls PauseRecording automatically, so if you haven't called Megacool.Instance.StopRecording before next time you call Megacool.Instance.StartRecording, the recording will continue from where you paused.


4. Testing

4.1 Reset device identity

If you are testing the invite/sharing process local on your devices it would be great to reset them so they act as new devices. To reset the device identity for the Megacool SDK you simply call ResetIdentity as the first thing when your app starts, before start(Action<MegacoolEvent> eventHandler). Also clear all cookies in Safari as this is used to identify the device from the link click.

Megacool.Instance.ResetIdentity();

5. Troubleshooting

When I find myself in times of trouble
Mother Mary comes to me
Speaking words of wisdom:
"submit a detailed debug log"
Paul McCartney

When things turn sour, and you're done running in circles screaming and shouting, you can swap the SDK over in debug mode to let it capture detailed call traces of what's happening, and automatically submit a debug report to us. Do this by calling Megacool.Debug = true as early as possible in the session, and when your problem has been reproduced (or you believe it is about to happen), call Megacool.Instance.SubmitDebugData("halp!"); to share the issue with us. Please try to explain in the message what you expected to happen, and what happened instead. If you follow this procedure it will be much easier for us to reproduce the issue you're having and get it fixed ASAP.

We appreciate you taking the time to help us find the cause of the bugs, and we're very sorry that we didn't find them ourselves.