From bec5b35e3cf9289f81d54c9c7ecefacf0f1232b7 Mon Sep 17 00:00:00 2001 From: Ahmed TARAFI Date: Fri, 2 Dec 2022 11:51:47 +0100 Subject: [PATCH 1/2] release/v2.3.0 --- .../Editor/ModifyUnityAndroidAppManifest.cs | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Assets/CrossDK/Editor/ModifyUnityAndroidAppManifest.cs diff --git a/Assets/CrossDK/Editor/ModifyUnityAndroidAppManifest.cs b/Assets/CrossDK/Editor/ModifyUnityAndroidAppManifest.cs new file mode 100644 index 0000000..acb605c --- /dev/null +++ b/Assets/CrossDK/Editor/ModifyUnityAndroidAppManifest.cs @@ -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 \ No newline at end of file From 07b94d4ee406f7ba9a6e6339bbea220d064260a0 Mon Sep 17 00:00:00 2001 From: Ahmed TARAFI Date: Fri, 2 Dec 2022 11:59:47 +0100 Subject: [PATCH 2/2] update readme file --- README.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index cde28ba..7ba5f95 100644 --- a/README.md +++ b/README.md @@ -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 @@ -69,7 +69,8 @@ public class CrossDKSample : MonoBehaviour CrossDKSingleton.Config( , , - ); + , + ); } } ``` @@ -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) @@ -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) @@ -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: @@ -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 ``` @@ -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!