This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Adikteev/release/v2.3.0
release/v2.3.0
- Loading branch information
Showing
2 changed files
with
108 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters