2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-06-30 19:03:42 -04:00

Convert android project to example project

This commit is contained in:
2023-09-05 07:20:02 +01:00
parent df2b089119
commit d716a80775
9 changed files with 21 additions and 13 deletions

View File

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0-android;net7.0-android</TargetFrameworks>
<RootNamespace>Examples.Android</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<PropertyGroup>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<ApplicationId>com.raylibcs.android</ApplicationId>
<ApplicationVersion>1</ApplicationVersion>
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../Raylib-cs/Raylib-cs.csproj" />
<ProjectReference Include="../Examples/Examples.csproj" />
</ItemGroup>
<Import Project="../Raylib-cs/Build.props" />
</Project>

View File

@ -0,0 +1,17 @@
using System.Runtime.InteropServices;
namespace Examples.Android;
public abstract class RaylibActivity : NativeActivity
{
protected override void OnCreate(Bundle? savedInstanceState)
{
RaylibSetAndroidCallback(OnReady);
base.OnCreate(savedInstanceState);
}
protected abstract void OnReady();
[DllImport(Raylib.NativeLibName, CallingConvention = CallingConvention.Cdecl)]
private static extern void RaylibSetAndroidCallback(Action callback);
}

View File

@ -0,0 +1,27 @@
diff --git a/src/rcore.c b/src/rcore.c
index eae4951..4400b22 100644
--- a/src/rcore.c
+++ b/src/rcore.c
@@ -1,3 +1,22 @@
+#if defined (PLATFORM_ANDROID)
+#include <stdlib.h>
+
+typedef void (*RaylibAndroidCallback)();
+static RaylibAndroidCallback _androidCallback = NULL;
+
+void RaylibSetAndroidCallback(RaylibAndroidCallback callback) {
+ _androidCallback = callback;
+}
+
+int main(int argc, char *argv[]) {
+ (void)argc;
+ (void)argv;
+ while (_androidCallback == NULL) {
+ }
+ _androidCallback();
+}
+#endif
+
/**********************************************************************************************
*
* rcore - Basic functions to manage windows, OpenGL context and input on multiple platforms