Skip to content
This repository has been archived by the owner on Aug 4, 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 Apr 20, 2022
1 parent 0cb2966 commit b9bd432
Show file tree
Hide file tree
Showing 17 changed files with 2,879 additions and 0 deletions.
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:
43 changes: 43 additions & 0 deletions Assets/CrossDK/CrossDKConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Runtime.InteropServices;

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

#if UNITY_IOS && !UNITY_EDITOR
[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);
#endif

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

public static void CrossDKConfigWithAppId(string appId = "", string apiKey = "", string userId = "")
{
#if UNITY_IOS && !UNITY_EDITOR
crossDKConfigWithAppId(appId, apiKey, userId);
#endif
}

public static void DismissOverlay()
{
#if UNITY_IOS && !UNITY_EDITOR
dismissOverlay();
#endif
}

public static void DisplayOverlayWithFormat(OverlayFormat format, OverlayPosition position, bool withCloseButton, bool isRewarded)
{
#if UNITY_IOS && !UNITY_EDITOR
displayOverlayWithFormat((int)format, (int)position, withCloseButton, isRewarded);
#endif
}
}
}
135 changes: 135 additions & 0 deletions Assets/CrossDK/CrossDKSingleton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
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 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
}
}
40 changes: 40 additions & 0 deletions Assets/CrossDK/Editor/CrossDKDependencies.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<dependencies>
<!-- 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>
24 changes: 24 additions & 0 deletions Assets/CrossDK/Editor/IOSPostProcess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;

public static class IOSPostProcess
{
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
{
if (buildTarget == BuildTarget.iOS)
{
string pbxProjectPath = PBXProject.GetPBXProjectPath(buildPath);
PBXProject project = new PBXProject();
project.ReadFromFile(pbxProjectPath);

project.SetBuildProperty(project.ProjectGuid(), "VALIDATE_WORKSPACE", "YES");
project.SetBuildProperty(project.ProjectGuid(), "CLANG_ENABLE_MODULES", "YES");
project.SetBuildProperty(project.ProjectGuid(), "CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER", "YES");
project.SetBuildProperty(project.ProjectGuid(), "ALWAYS_SEARCH_USER_PATHS", "NO");

project.WriteToFile(pbxProjectPath);
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit b9bd432

Please sign in to comment.