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

Commit

Permalink
Merge pull request #6 from Adikteev/release/v2.3.0
Browse files Browse the repository at this point in the history
release/v2.3.0
  • Loading branch information
atarafi authored Dec 2, 2022
2 parents 415c92e + 07b94d4 commit 309f2ae
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 11 deletions.
98 changes: 98 additions & 0 deletions Assets/CrossDK/Editor/ModifyUnityAndroidAppManifest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#if UNITY_ANDROID
using System.IO;
using System.Text;
using System.Xml;
using UnityEditor.Android;

public class ModifyUnityAndroidAppManifestSample : IPostGenerateGradleAndroidProject
{

public void OnPostGenerateGradleAndroidProject(string basePath)
{

var androidManifest = new AndroidManifest(GetManifestPath(basePath));
androidManifest.SetHardwareAcceleration();
androidManifest.Save();
}

public int callbackOrder { get { return 1; } }

private string _manifestFilePath;

private string GetManifestPath(string basePath)
{
if (string.IsNullOrEmpty(_manifestFilePath))
{
var pathBuilder = new StringBuilder(basePath);
pathBuilder.Append(Path.DirectorySeparatorChar).Append("src");
pathBuilder.Append(Path.DirectorySeparatorChar).Append("main");
pathBuilder.Append(Path.DirectorySeparatorChar).Append("AndroidManifest.xml");
_manifestFilePath = pathBuilder.ToString();
}
return _manifestFilePath;
}
}


internal class AndroidXmlDocument : XmlDocument
{
private string m_Path;
protected XmlNamespaceManager nsMgr;
public readonly string AndroidXmlNamespace = "http://schemas.android.com/apk/res/android";
public AndroidXmlDocument(string path)
{
m_Path = path;
using (var reader = new XmlTextReader(m_Path))
{
reader.Read();
Load(reader);
}
nsMgr = new XmlNamespaceManager(NameTable);
nsMgr.AddNamespace("android", AndroidXmlNamespace);
}

public string Save()
{
return SaveAs(m_Path);
}

public string SaveAs(string path)
{
using (var writer = new XmlTextWriter(path, new UTF8Encoding(false)))
{
writer.Formatting = Formatting.Indented;
Save(writer);
}
return path;
}
}


internal class AndroidManifest : AndroidXmlDocument
{
private readonly XmlElement ApplicationElement;

public AndroidManifest(string path) : base(path)
{
ApplicationElement = SelectSingleNode("/manifest/application") as XmlElement;
}

private XmlAttribute CreateAndroidAttribute(string key, string value)
{
XmlAttribute attr = CreateAttribute("android", key, AndroidXmlNamespace);
attr.Value = value;
return attr;
}

internal XmlNode GetActivityWithLaunchIntent()
{
return SelectSingleNode("/manifest/application/activity[intent-filter/action/@android:name='android.intent.action.MAIN' and " +
"intent-filter/category/@android:name='android.intent.category.LAUNCHER']", nsMgr);
}

internal void SetHardwareAcceleration()
{
GetActivityWithLaunchIntent().Attributes.Append(CreateAndroidAttribute("hardwareAccelerated", "true"));
}
}
#endif
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ All the methods you'll need to call are in the `CrossDKSingleton` script on this
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:

```csharp
CrossDKSingleton.CrossDKConfigWithAppId(string appId, string apiKey, string userId)
CrossDKSingleton.CrossDKConfigWithAppId(string appId, string apiKey, string userId, string deviceId)
```

```csharp
Expand All @@ -69,7 +69,8 @@ public class CrossDKSample : MonoBehaviour
CrossDKSingleton.Config(
<YOUR APP ID>,
<YOUR API KEY>,
<USER ID (optional)>);
<USER ID (optional)>,
<DEVICE ID (optional)>);
}
}
```
Expand All @@ -81,10 +82,9 @@ Note: The CrossDK prefab is not destroyed during scenes changes, so you only nee
## Usage

Here are the configurations for each overlay format :

- `OverlayFormat.Banner`: settle its position between `OverlayPosition.Bottom` or `OverlayPosition.BottomRaised`, with or without a close button (the close button is Android only).
- `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 (the reward is iOS only at the moment).
- `OverlayFormat.Interstitial`: settle it with or without a close button, with or without a rewarded.

```csharp
CrossDKSingleton.DisplayOverlayWithFormat(OverlayFormat format, OverlayPosition position, bool withCloseButton, bool isRewarded)
Expand All @@ -99,15 +99,15 @@ public class CrossDKSample : MonoBehaviour
public void DisplayMidSizeOverlayExample()
{
CrossDKSingleton.DisplayOverlay(
OverlayFormat.MidSize,
OverlayPosition.Bottom,
true,
OverlayFormat.MidSize,
OverlayPosition.Bottom,
true,
false);
}
}
```

A `SetDeviceId()` method is available in order to use custom device id. You can see the recommendations using another device id than yours. Set it before `DisplayOverlayWithFormat()` function call:
For IOS only a `SetDeviceId()` method is available in order to use custom device id. You can see the recommendations using another device id than yours. Set it before `DisplayOverlayWithFormat()` function call:

```csharp
CrossDKSingleton.SetDeviceId(string deviceId)
Expand All @@ -126,6 +126,7 @@ public class CrossDKSample : MonoBehaviour
}
}
```
For Android you can directly config the sdk with the desired device ID.

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

Expand All @@ -151,7 +152,6 @@ public class CrossDKSample : MonoBehaviour
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:

```csharp
CrossDKSingleton.overlayDidRewardUserWithRewardDelegate
```
Expand All @@ -178,7 +178,6 @@ public class CrossDKDelegatesSample : MonoBehaviour
}
}
```

You can check the [crossdk-ios](https://github.com/Adikteev/crossdk-ios) and the [crossdk-android](https://github.com/Adikteev/crossdk-android) repositories to know more about the available delegates for each platform.
You can check the [crossdk-ios](https://github.com/Adikteev/crossdk-ios) and the [crossdk-android](https://github.com/Adikteev/crossdk-android) repositories to know more about the available delegate for each platforms.

That’s all you need to know!

0 comments on commit 309f2ae

Please sign in to comment.