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

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lforner committed Jul 8, 2022
0 parents commit 9a82fed
Show file tree
Hide file tree
Showing 28 changed files with 3,797 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Mm]emoryCaptures/

# Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties

48 changes: 48 additions & 0 deletions Assets/CrossDK/CrossDK.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &8139806205299797674
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8139806205299797672}
- component: {fileID: 8139806205299797675}
m_Layer: 0
m_Name: CrossDK
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8139806205299797672
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8139806205299797674}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &8139806205299797675
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8139806205299797674}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 86ae828927208024289c04f4b9b3b36f, type: 3}
m_Name:
m_EditorClassIdentifier:
_appId:
_apiKey:
_idfv:
85 changes: 85 additions & 0 deletions Assets/CrossDK/CrossDKConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System.Runtime.InteropServices;
using UnityEngine;

namespace CrossDK
{
public class CrossDKConverter
{
/* Interface to native implementation */

#if UNITY_IOS
[DllImport("__Internal")]
private static extern void crossDKConfigWithAppId(string appId, string apiKey, string userId);

[DllImport("__Internal")]
private static extern void dismissOverlay();

[DllImport("__Internal")]
private static extern void displayOverlayWithFormat(int format, int position, bool withCloseButton, bool isRewarded);
#elif UNITY_ANDROID
private static AndroidJavaObject crossDKWrapper;
private const string CONFIG = "config";
private const string DISMISS = "dismissOverlay";
private const string DISPLAY = "displayOverlay";
//[DllImport("CrossDK")]
//private static extern void crossDKConfigWithAppId(string appId, string apiKey, string userId);

//[DllImport("CrossDK")]
//private static extern void dismissOverlay();

//[DllImport("CrossDK")]
//private static extern void displayOverlayWithFormat(int format, int position, bool withCloseButton, bool isRewarded);
#endif

/* Public interface for use inside C# code */

public static void CrossDKConfigWithAppId(string appId = "", string apiKey = "", string userId = "")
{
#if UNITY_EDITOR
Debug.Log("CrossDKConfigWithAppId called in editor");
#elif UNITY_IOS
crossDKConfigWithAppId(appId, apiKey, userId);
#endif
#if UNITY_ANDROID
crossDKWrapper = new AndroidJavaObject("com.adikteev.unityadapter.CrossDKBridge");

object[] parameters = new object[3];
parameters[0] = appId;
parameters[1] = apiKey;
parameters[2] = userId;

crossDKWrapper.Call(CONFIG, parameters);
#endif
}

public static void DismissOverlay()
{
#if UNITY_EDITOR
Debug.Log("DismissOverlay called in editor");
#elif UNITY_IOS
dismissOverlay();
#endif
#if UNITY_ANDROID
crossDKWrapper.Call(DISMISS);
#endif
}

public static void DisplayOverlayWithFormat(OverlayFormat format, OverlayPosition position, bool withCloseButton, bool isRewarded)
{
#if UNITY_EDITOR
Debug.Log("DisplayOverlayWithFormat called in editor");
#elif UNITY_IOS
displayOverlayWithFormat((int)format, (int)position, withCloseButton, isRewarded);
#endif
#if UNITY_ANDROID
object[] parameters = new object[4];
parameters[0] = (int)format;
parameters[1] = (int)position;
parameters[2] = withCloseButton;
parameters[3] = isRewarded;

crossDKWrapper.Call(DISPLAY, parameters);
#endif
}
}
}
140 changes: 140 additions & 0 deletions Assets/CrossDK/CrossDKSingleton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using UnityEngine;

namespace CrossDK
{
public class CrossDKSingleton : MonoBehaviour
{
private static CrossDKSingleton _instance;

public delegate void CrossDKDelegate(string message);
public static CrossDKDelegate overlayWillStartPresentationDelegate;
public static CrossDKDelegate overlayDidFinishPresentationDelegate;
public static CrossDKDelegate overlayWillStartDismissalDelegate;
public static CrossDKDelegate overlayDidFinishDismissalDelegate;
public static CrossDKDelegate overlayStartsPlayingVideoDelegate;
public static CrossDKDelegate overlayPlayedHalfVideoDelegate;
public static CrossDKDelegate overlayDidFinishPlayingVideoDelegate;
public static CrossDKDelegate overlayShowsRecommendedAppInAppStoreDelegate;
public static CrossDKDelegate overlayDidRewardUserWithRewardDelegate;
public static CrossDKDelegate overlayDidFailToLoadWithErrorDelegate;
public static CrossDKDelegate overlayUnavailableWithErrorDelegate;

[Header("SDK settings")]
[SerializeField] private bool _autoCallConfig;
[SerializeField] private string _appId;
[SerializeField] private string _apiKey;
[SerializeField] private string _idfv;

private void Awake()
{
if (_instance != null)
{
Destroy(this);
return;
}
_instance = this;
DontDestroyOnLoad(gameObject);

if (_autoCallConfig)
{
Config(_appId, _apiKey, _idfv);
}
}

#region CrossDK Methods

public static void Config(string appId = "", string apiKey = "", string userId = "")
{
CrossDKConverter.CrossDKConfigWithAppId(appId, apiKey, userId);
}

public static void DismissOverlay()
{
CrossDKConverter.DismissOverlay();
}

public static void DisplayOverlay(OverlayFormat format = OverlayFormat.Interstitial, OverlayPosition position = OverlayPosition.Bottom, bool withCloseButton = true, bool isRewarded = true)
{
CrossDKConverter.DisplayOverlayWithFormat(format, position, withCloseButton, isRewarded);
}

#endregion

#region CrossDK Delegates

//internal void Log(string message)
//{
// Logger.Log(message);
//}

internal void OverlayWillStartPresentation(string message)
{
overlayWillStartPresentationDelegate?.Invoke(message);
}

internal void OverlayDidFinishPresentation(string message)
{
overlayDidFinishPresentationDelegate?.Invoke(message);
}

internal void OverlayWillStartDismissal(string message)
{
overlayWillStartDismissalDelegate?.Invoke(message);
}

internal void OverlayDidFinishDismissal(string message)
{
overlayDidFinishDismissalDelegate?.Invoke(message);
}

internal void OverlayStartsPlayingVideo(string message)
{
overlayStartsPlayingVideoDelegate?.Invoke(message);
}

internal void OverlayPlayedHalfVideo(string message)
{
overlayPlayedHalfVideoDelegate?.Invoke(message);
}

internal void OverlayDidFinishPlayingVideo(string message)
{
overlayDidFinishPlayingVideoDelegate?.Invoke(message);
}

internal void OverlayShowsRecommendedAppInAppStore(string message)
{
overlayShowsRecommendedAppInAppStoreDelegate?.Invoke(message);
}

internal void OverlayDidRewardUserWithReward(string message)
{
overlayDidRewardUserWithRewardDelegate?.Invoke(message);
}

internal void OverlayDidFailToLoadWithError(string message)
{
overlayDidFailToLoadWithErrorDelegate?.Invoke(message);
}

internal void OverlayUnavailableWithError(string message)
{
overlayUnavailableWithErrorDelegate?.Invoke(message);
}

#endregion
}

public enum OverlayFormat
{
Banner = 0,
MidSize = 1,
Interstitial = 2
}

public enum OverlayPosition
{
Bottom = 0,
BottomRaised = 1
}
}
43 changes: 43 additions & 0 deletions Assets/CrossDK/Editor/CrossDKDependencies.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<dependencies>
<androidPackages>
<!--<androidPackage spec="com.adikteev:crossdk-android:1.0.1" />-->
</androidPackages>
<!-- iOS Cocoapod dependencies can be specified by each iosPod element. -->
<iosPods>
<!-- iosPod supports the following attributes:
* "name" (required)
Name of the Cocoapod.
* "path" (optional)
Path to the local Cocoapod.
NOTE: This is expanded to a local path when the Podfile is generated.
For example, if a Unity project has the root path "/my/game" and the
pod the path is "foo/bar", this will be will be expanded to
"/my/game/foo/bar" when the Podfile is generated.
* "version" (optional)
Cocoapod version specification for the named pod.
If this is not specified the latest version is used.
NOTE: This can't be used when "path" is set.
* "bitcodeEnabled" (optional)
Whether this Cocoapod requires bitcode to be enabled in Unity's
generated Xcode project. This is "true" by default.
* "minTargetSdk" (optional)
The minimum iOS SDK required by this Cocoapod.
* "addToAllTargets" (optional)
Whether to add this pod to all targets when multiple target is
supported. This is "false" by default.
* "configurations" (optional)
Podfile formatted list of configurations to include this pod in.
* "modular_headers" (optional)
Set to true to enable modular headers, false to disable.
* "source" (optional)
Source repo to fetch the pod from.
* "subspecs" (optional)
Subspecs to include for the pod.
-->
<iosPod name="CrossDK" version="3.2.0" addToAllTargets="true">
<sources>
<source>https://github.com/CocoaPods/Specs</source>
</sources>
</iosPod>
</iosPods>
</dependencies>
Loading

0 comments on commit 9a82fed

Please sign in to comment.