-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSdkrtUnityCsWrapper.cs
90 lines (72 loc) · 2.88 KB
/
SdkrtUnityCsWrapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class SDKRTTest : MonoBehaviour
{
public TextMeshProUGUI textToChange;
private bool changed = false;
public void LoadSdk()
{
// Get the current Android Activity
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
// Create an instance of UnitySdkBridge class
AndroidJavaObject existingSdkObject = new AndroidJavaObject("com.example.unitybridge.UnitySdkBridge", currentActivity);
// Create an Action that will handle the callback from Kotlin
System.Action<bool> callback = (result) => {
if (result) {
textToChange.text = "SDK initialised.";
} else {
textToChange.text = "SDK not initialised.";
}
};
AndroidJavaProxy callbackProxy = new InitializationCallbackProxy(callback);
// Call the initializeSync method with the runnable - Name needs to match
existingSdkObject.Call("initializeSync", callbackProxy);
}
public void CreateFile()
{
// Get the current Android Activity
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
// Create an instance of UnitySdkBridge class
AndroidJavaObject existingSdkObject = new AndroidJavaObject("com.example.unitybridge.UnitySdkBridge", currentActivity);
// Create an Action that will handle the callback from Kotlin
System.Action<string> callback = (result) => {
textToChange.text = result;
};
AndroidJavaProxy callbackProxy = new CreateFileCallbackProxy(callback);
// Call the initializeSync method with the runnable
existingSdkObject.Call("createFileSync", 2, callbackProxy);
}
}
public class InitializationCallbackProxy : AndroidJavaProxy
{
private System.Action<bool> _callback;
public InitializationCallbackProxy(System.Action<bool> callback)
: base("com.example.unitybridge.InitializationCallback")
{
_callback = callback;
}
public void onInitializationComplete(bool result)
{
Debug.Log("and the result is: " + result);
_callback(result);
}
}
public class CreateFileCallbackProxy : AndroidJavaProxy
{
private System.Action<string> _callback;
public CreateFileCallbackProxy(System.Action<string> callback)
: base("com.example.unitybridge.FileCreationCallback")
{
_callback = callback;
}
public void onFileCreationComplete(string result)
{
Debug.Log("and the result is: " + result);
_callback(result);
}
}