Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Adikteev/crossdk-unity-ios

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

CrossDK for Unity

Warning

This repository is now deprecated. Please visit the new repository, supporting both iOS and Android : https://github.com/Adikteev/crossdk-unity

Overview

This repo contains the CrossDK interface for Unity. It allows you to cross-promote your application catalog in your Unity project.

Requirements

Unity version >= 2018.4.36

iOS version >= 11.0

CrossDK for Unity is available with iOS 11 minimal target version, but the CrossDKOverlay is only available since iOS 14. CrossDK provides support in order to handle cases where the CrossDKOverlay is not available (see Overlay Delegate).

Installation

CocoaPods

To install CocoaPods on MacOS, add the following entry:

$ sudo gem install cocoapods

The CrossDK pod is automatically installed in the Xcode project when building with Unity, thanks to External Dependency Manager for Unity.

If you already use CocoaPods in your Unity project, you should consider adding your pods with EDM4U as well.

Configuration

To use CrossDK in your Unity project, you must download the CrossDK.unitypackage on the releases page, then import it into your project. Once it's finished, drag the CrossDK prefab (located in Assets\CrossDK\CrossDK) into your scene.

All the methods you'll need to call are in the CrossDKSingleton script on this prefab, and they all are public and static. Thus, you can call them from anywhere at anytime just by adding import CrossDK; at the top of any script.

In order to display an overlay properly, CrossDK requires some information. Since CrossDK won't work without these, you should set them up as soon as possible. In the following example, we use the setup function inside a Start event, but it's up to you to set it up wherever you like:

CrossDKSingleton.CrossDKConfigWithAppId(string appId, string apiKey, string userId)
using UnityEngine;
using CrossDK;

public class CrossDKSample : MonoBehaviour
{
    private void Start()
    {
        CrossDKSingleton.Config(
            <YOUR APP ID>,
            <YOUR API KEY>,
            <USER ID (optional)>);
    }
}

You can also enter this information on the CrossDK prefab and check autoCallConfig to let it call the config method automatically during the Awake event.

Note: The CrossDK prefab is not destroyed during scenes changes, so you only need to drag it into your first scene.

Usage

Here are the configurations for each overlay format :

  • OverlayFormat.Banner: settle its position between OverlayPosition.Bottom or OverlayPosition.BottomRaised.
  • OverlayFormat.MidSize: settle its position between OverlayPosition.Bottom or OverlayPosition.BottomRaised, with or without a close button .
  • OverlayFormat.Interstitial: settle it with or without a close button, with or without a rewarded.
CrossDKSingleton.DisplayOverlayWithFormat(OverlayFormat format, OverlayPosition position, bool withCloseButton, bool isRewarded)
using UnityEngine;
using CrossDK;

public class CrossDKSample : MonoBehaviour
{
    public void DisplayMidSizeOverlayExample()
    {
        CrossDKSingleton.DisplayOverlay(
            OverlayFormat.MidSize, 
            OverlayPosition.Bottom, 
            true, 
            false);
    }
}

A DismissOverlay() method is available in order to prevent screen changes :

CrossDKSingleton.DismissOverlay()
using UnityEngine;
using CrossDK;

public class CrossDKSample : MonoBehaviour
{
    public void DismissExample()
    {
        CrossDKSingleton.DismissOverlay();
    }
}

Overlay Delegate

Additionally, many delegates are available if you want to monitor what is happening with the CrossDKOverlay:

For instance, you can track when the user is rewarded with the delegate:

CrossDKSingleton.overlayDidRewardUserWithRewardDelegate
using UnityEngine;
using CrossDK;

public class CrossDKDelegatesSample : MonoBehaviour
{
    private void Start()
    {
        CrossDKSingleton.overlayDidRewardUserWithRewardDelegate += OverlayDidRewardUserWithRewardExample;
    }

    private void OnDestroy()
    {
        CrossDKSingleton.overlayDidRewardUserWithRewardDelegate -= OverlayDidRewardUserWithRewardExample;
    }

    private void OverlayDidRewardUserWithRewardExample(string message)
    {
        Debug.Log("User was rewarded");
    }
}

You can check the crossdk-ios repository to know more about the available delegate.

That’s all you need to know !

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •