save state
This commit is contained in:
@@ -23,7 +23,6 @@ class MyKotlinPlugin {
|
||||
override fun onServiceConnected(className: ComponentName, service: IBinder) {
|
||||
Log.d("MosisTest", "Service Connected")
|
||||
remote_service = IMosisService.Stub.asInterface(service)
|
||||
Log.d("MosisTest", "Number: ${remote_service?.number}")
|
||||
serviceConnected(service)
|
||||
}
|
||||
override fun onServiceDisconnected(arg0: ComponentName) {
|
||||
|
||||
@@ -14,10 +14,29 @@ set(PLUGIN_API "${UNITY_ROOT}/PluginAPI")
|
||||
set(BINDER_DIR "${ANDROID_SDK}/platforms/android-36/optional/libbinder_ndk_cpp")
|
||||
|
||||
set(SHARED_SRC_DIR "${UNITY_PROJECT_DIR}/../MosisService/src/main/cpp/")
|
||||
set(AIDL_EXE "${ANDROID_SDK}/build-tools/36.1.0/aidl.exe")
|
||||
set(AIDL_BASE_ARGS --lang=ndk --min_sdk_version=36
|
||||
-o ${CMAKE_CURRENT_BINARY_DIR} -h ${CMAKE_CURRENT_BINARY_DIR} -I ..\\aidl)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/com/omixlab/mosis/IMosisService.cpp"
|
||||
COMMAND ${AIDL_EXE} ${AIDL_BASE_ARGS} ..\\aidl\\com\\omixlab\\mosis\\IMosisService.aidl
|
||||
DEPENDS ../aidl/com/omixlab/mosis/IMosisService.aidl
|
||||
WORKING_DIRECTORY ${SHARED_SRC_DIR}
|
||||
VERBATIM
|
||||
)
|
||||
add_custom_command(
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/com/omixlab/mosis/IMosisListener.cpp"
|
||||
COMMAND ${AIDL_EXE} ${AIDL_BASE_ARGS} ..\\aidl\\com\\omixlab\\mosis\\IMosisListener.aidl
|
||||
DEPENDS ../aidl/com/omixlab/mosis/IMosisListener.aidl
|
||||
WORKING_DIRECTORY ${SHARED_SRC_DIR}
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_library(my_native_lib SHARED
|
||||
my_native_code.cpp
|
||||
${SHARED_SRC_DIR}/com/omixlab/mosis/IMosisService.cpp
|
||||
${SHARED_SRC_DIR}/com/omixlab/mosis/IMosisListener.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/com/omixlab/mosis/IMosisService.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/com/omixlab/mosis/IMosisListener.cpp
|
||||
${SHARED_SRC_DIR}/logger.cpp
|
||||
${SHARED_SRC_DIR}/external_texture.cpp
|
||||
${SHARED_SRC_DIR}/render_target.cpp
|
||||
@@ -28,6 +47,7 @@ target_link_libraries(my_native_lib ${log-lib} binder_ndk EGL GLESv2 nativewindo
|
||||
target_include_directories(my_native_lib PUBLIC
|
||||
${SHARED_SRC_DIR}
|
||||
${SHARED_SRC_DIR}/glad/include
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${BINDER_DIR}
|
||||
${PLUGIN_API}
|
||||
)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
using namespace aidl::com::omixlab::mosis;
|
||||
using namespace aidl::android::hardware;
|
||||
|
||||
std::shared_ptr<class IMosisService> g_service;
|
||||
std::shared_ptr<IMosisService> g_service;
|
||||
std::shared_ptr<class ServiceContext> g_context;
|
||||
|
||||
class TextureBlitter
|
||||
@@ -145,6 +145,14 @@ extern "C" void SetNativeCallbacks(const NativeCallbacks& ptr)
|
||||
g_callbacks = ptr;
|
||||
}
|
||||
|
||||
extern "C" void SendTouchMove(float x, float y)
|
||||
{
|
||||
if (g_service)
|
||||
{
|
||||
g_service->onTouchMove(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" UnityRenderingEvent InitGLAD()
|
||||
{
|
||||
return [](int eventId){
|
||||
|
||||
@@ -6,7 +6,6 @@ using System.Runtime.InteropServices;
|
||||
public class KotlinBridge : MonoBehaviour
|
||||
{
|
||||
static KotlinBridge Instance;
|
||||
Texture2D texture;
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct NativeCallbacks
|
||||
{
|
||||
@@ -16,17 +15,19 @@ public class KotlinBridge : MonoBehaviour
|
||||
public IntPtr OnBufferReady;
|
||||
public IntPtr OnTextureReady;
|
||||
}
|
||||
public delegate void OnMessageDelegate(string message);
|
||||
public delegate void OnServiceInitializedDelegate(bool success);
|
||||
public delegate void OnFrameAvailableDelegate();
|
||||
public delegate void OnBufferReadyDelegate();
|
||||
public delegate void OnTextureReadyDelegate(uint gl_texture);
|
||||
delegate void OnMessageDelegate(string message);
|
||||
delegate void OnServiceInitializedDelegate(bool success);
|
||||
delegate void OnFrameAvailableDelegate();
|
||||
delegate void OnBufferReadyDelegate();
|
||||
delegate void OnTextureReadyDelegate(uint gl_texture);
|
||||
[DllImport("my_native_lib")]
|
||||
private static extern void SetNativeCallbacks(ref NativeCallbacks callbacks);
|
||||
static extern void SetNativeCallbacks(ref NativeCallbacks callbacks);
|
||||
[DllImport("my_native_lib")]
|
||||
private static extern IntPtr InitGLAD();
|
||||
public static extern void SendTouchMove(float u, float v);
|
||||
[DllImport("my_native_lib")]
|
||||
private static extern IntPtr UpdateTexture();
|
||||
static extern IntPtr InitGLAD();
|
||||
[DllImport("my_native_lib")]
|
||||
static extern IntPtr UpdateTexture();
|
||||
|
||||
[AOT.MonoPInvokeCallback(typeof(OnMessageDelegate))]
|
||||
static void OnMessage(string message)
|
||||
@@ -63,7 +64,6 @@ public class KotlinBridge : MonoBehaviour
|
||||
Debug.Log("Texture Ready: " + gl_texture);
|
||||
UnityMainThreadDispatcher.Enqueue(() => {
|
||||
var renderer = Instance.GetComponent<Renderer>();
|
||||
//renderer.material = new Material(Instance.oesShader);
|
||||
renderer.materials[2].mainTexture = Texture2D.CreateExternalTexture(1024, 1024,
|
||||
TextureFormat.RGBA32, false, false, (IntPtr)gl_texture);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user