move to package
This commit is contained in:
93
Packages/com.omarator.mosissdk/Editor/AppendCmake.cs
Normal file
93
Packages/com.omarator.mosissdk/Editor/AppendCmake.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.Android;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Xml;
|
||||
|
||||
public class AndroidPostProcess : IPostGenerateGradleAndroidProject
|
||||
{
|
||||
public int callbackOrder => 0;
|
||||
|
||||
public void OnPostGenerateGradleAndroidProject(string buildPath)
|
||||
{
|
||||
// 1. Get the path to the Unity-generated CMakeLists.txt in the build folder
|
||||
// path parameter is: PROJECT_ROOT/Library/Bee/Android/Prj/Mono2x/Gradle/unityLibrary
|
||||
string targetCmakeFile = Path.Combine(buildPath, "src/main/cpp/CMakeLists.txt");
|
||||
|
||||
if (!File.Exists(targetCmakeFile)) return;
|
||||
|
||||
// 2. Locate your custom C++ folder in Assets
|
||||
// Application.dataPath gives the absolute path to "Assets"
|
||||
string myCppFolder = Path.GetFullPath(Path.Combine(Application.dataPath, "../Packages/com.omarator.mosissdk/Plugins/Android/cpp"));
|
||||
|
||||
// 3. Calculate the relative path from the build's CMake location to your source
|
||||
// We need the directory where the target CMake file lives to calculate relative from it
|
||||
string targetCmakeDir = Path.GetDirectoryName(targetCmakeFile);
|
||||
string relativePathToMyCpp = GetRelativePath(targetCmakeDir, myCppFolder).Replace("\\", "/");
|
||||
|
||||
// 4. Prepare the command
|
||||
string commandName = "my_plugin_build";
|
||||
string lineToAdd = $"\nadd_subdirectory(\"{relativePathToMyCpp}\" \"{commandName}\")\n";
|
||||
|
||||
// 5. Prevent multiple additions
|
||||
string currentContent = File.ReadAllText(targetCmakeFile);
|
||||
if (!currentContent.Contains(relativePathToMyCpp))
|
||||
{
|
||||
File.AppendAllText(targetCmakeFile, lineToAdd);
|
||||
Debug.Log($"[CMake] Added {relativePathToMyCpp} to build.");
|
||||
}
|
||||
ModifyManifest(buildPath);
|
||||
}
|
||||
|
||||
// Helper for cross-platform relative paths
|
||||
private string GetRelativePath(string fromPath, string toPath)
|
||||
{
|
||||
Uri fromUri = new Uri(AppendSlash(fromPath));
|
||||
Uri toUri = new Uri(AppendSlash(toPath));
|
||||
Uri relativeUri = fromUri.MakeRelativeUri(toUri);
|
||||
return Uri.UnescapeDataString(relativeUri.ToString());
|
||||
}
|
||||
|
||||
private string AppendSlash(string path)
|
||||
{
|
||||
if (!path.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
path += Path.DirectorySeparatorChar;
|
||||
return path;
|
||||
}
|
||||
|
||||
public void ModifyManifest(string path)
|
||||
{
|
||||
// The manifest is located in the unityLibrary module
|
||||
string manifestPath = Path.Combine(path, "src/main/AndroidManifest.xml");
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(manifestPath);
|
||||
|
||||
XmlNode root = doc.DocumentElement;
|
||||
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
|
||||
nsmgr.AddNamespace("android", "http://schemas.android.com/apk/res/android");
|
||||
|
||||
// 1. Check/Add Queries tag
|
||||
XmlNode queriesNode = root.SelectSingleNode("queries");
|
||||
if (queriesNode == null)
|
||||
{
|
||||
queriesNode = doc.CreateElement("queries");
|
||||
root.AppendChild(queriesNode);
|
||||
}
|
||||
|
||||
// 2. Add the specific package if it's not there
|
||||
string targetPackage = "com.omixlab.mosis";
|
||||
if (queriesNode.SelectSingleNode($"package[@android:name='{targetPackage}']", nsmgr) == null)
|
||||
{
|
||||
XmlElement packageElem = doc.CreateElement("package");
|
||||
packageElem.SetAttribute("name", "http://schemas.android.com/apk/res/android", targetPackage);
|
||||
queriesNode.AppendChild(packageElem);
|
||||
}
|
||||
|
||||
doc.Save(manifestPath);
|
||||
Debug.Log("[Manifest] Successfully injected <queries> tag.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 813722810ec374244ad7f0fbd8b40b7e
|
||||
30
Packages/com.omarator.mosissdk/Editor/EditorExample.cs
Normal file
30
Packages/com.omarator.mosissdk/Editor/EditorExample.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Use this editor example C# file to develop editor (non-runtime) code.
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace Omarator.Mosissdk.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Provide a general description of the public class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Packages require XmlDoc documentation for ALL Package APIs.
|
||||
/// https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/xml-documentation-comments
|
||||
/// </remarks>
|
||||
public class MyPublicEditorExampleClass
|
||||
{
|
||||
/// <summary>
|
||||
/// Provide a description of what this private method does.
|
||||
/// </summary>
|
||||
/// <param name="parameter1"> Description of parameter 1 </param>
|
||||
/// <param name="parameter2"> Description of parameter 2 </param>
|
||||
/// <param name="parameter3"> Description of parameter 3 </param>
|
||||
/// <returns> Description of what the function returns </returns>
|
||||
public int CountThingsAndDoStuff(int parameter1, int parameter2, bool parameter3)
|
||||
{
|
||||
return parameter3 ? (parameter1 + parameter2) : (parameter1 - parameter2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98e9eff0dd13f4379b8069286df2eb7f
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "Omarator.Mosissdk.Editor",
|
||||
"references": [
|
||||
"Omarator.Mosissdk"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": []
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0137830c41d4a4cfea332d24c6f9074f
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user