@dolami-inc/react-native-expo-unity 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,6 +5,7 @@ import android.util.Log
|
|
|
5
5
|
import android.view.ViewGroup
|
|
6
6
|
import android.widget.FrameLayout
|
|
7
7
|
import expo.modules.kotlin.AppContext
|
|
8
|
+
import expo.modules.kotlin.viewevent.EventDispatcher
|
|
8
9
|
import expo.modules.kotlin.views.ExpoView
|
|
9
10
|
|
|
10
11
|
class ExpoUnityView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
|
|
@@ -8,6 +8,7 @@ import android.view.View
|
|
|
8
8
|
import com.expounity.bridge.NativeCallProxy
|
|
9
9
|
import com.unity3d.player.IUnityPlayerLifecycleEvents
|
|
10
10
|
import com.unity3d.player.UnityPlayer
|
|
11
|
+
import com.unity3d.player.UnityPlayerForActivityOrService
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Singleton managing the UnityPlayer lifecycle.
|
|
@@ -43,17 +44,18 @@ class UnityBridge private constructor() : IUnityPlayerLifecycleEvents, NativeCal
|
|
|
43
44
|
get() = unityPlayer != null
|
|
44
45
|
|
|
45
46
|
/**
|
|
46
|
-
* Returns the UnityPlayer view for embedding.
|
|
47
|
+
* Returns the UnityPlayer view for embedding.
|
|
48
|
+
* Unity 6+ made UnityPlayer abstract; use getView() to get the renderable view.
|
|
47
49
|
*/
|
|
48
50
|
val unityPlayerView: View?
|
|
49
|
-
get() = unityPlayer
|
|
51
|
+
get() = unityPlayer?.view
|
|
50
52
|
|
|
51
53
|
fun initialize(activity: Activity) {
|
|
52
54
|
if (isInitialized) return
|
|
53
55
|
|
|
54
56
|
val runInit = Runnable {
|
|
55
57
|
try {
|
|
56
|
-
val player =
|
|
58
|
+
val player = UnityPlayerForActivityOrService(activity, this)
|
|
57
59
|
unityPlayer = player
|
|
58
60
|
|
|
59
61
|
NativeCallProxy.registerListener(this)
|
package/app.plugin.js
CHANGED
|
@@ -3,10 +3,32 @@ const {
|
|
|
3
3
|
withSettingsGradle,
|
|
4
4
|
withProjectBuildGradle,
|
|
5
5
|
withAppBuildGradle,
|
|
6
|
+
withGradleProperties,
|
|
6
7
|
} = require('@expo/config-plugins');
|
|
7
8
|
const path = require('path');
|
|
8
9
|
const fs = require('fs');
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Parse a Java .properties file into an array of { type, key, value } entries.
|
|
13
|
+
*/
|
|
14
|
+
function parsePropertiesFile(filePath) {
|
|
15
|
+
if (!fs.existsSync(filePath)) return [];
|
|
16
|
+
const lines = fs.readFileSync(filePath, 'utf8').split('\n');
|
|
17
|
+
const entries = [];
|
|
18
|
+
for (const line of lines) {
|
|
19
|
+
const trimmed = line.trim();
|
|
20
|
+
if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith('!')) continue;
|
|
21
|
+
const eqIndex = trimmed.indexOf('=');
|
|
22
|
+
if (eqIndex === -1) continue;
|
|
23
|
+
entries.push({
|
|
24
|
+
type: 'property',
|
|
25
|
+
key: trimmed.slice(0, eqIndex).trim(),
|
|
26
|
+
value: trimmed.slice(eqIndex + 1).trim(),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return entries;
|
|
30
|
+
}
|
|
31
|
+
|
|
10
32
|
/**
|
|
11
33
|
* Expo Config Plugin for @dolami-inc/react-native-expo-unity.
|
|
12
34
|
*
|
|
@@ -17,6 +39,7 @@ const fs = require('fs');
|
|
|
17
39
|
*
|
|
18
40
|
* Android:
|
|
19
41
|
* - Includes the :unityLibrary Gradle module and .androidlib subprojects in settings.gradle
|
|
42
|
+
* - Copies Unity gradle properties (unity.*, unityStreamingAssets) to host gradle.properties
|
|
20
43
|
* - Adds flatDir repos for Unity's .aar/.jar libs in root build.gradle
|
|
21
44
|
* - Adds the unityLibrary dependency and NDK abiFilters in app/build.gradle
|
|
22
45
|
*
|
|
@@ -121,6 +144,40 @@ const withExpoUnity = (config, options = {}) => {
|
|
|
121
144
|
return config;
|
|
122
145
|
});
|
|
123
146
|
|
|
147
|
+
// -- Android: gradle.properties (copy Unity properties to host project) --
|
|
148
|
+
// Unity's build.gradle references properties like `unityStreamingAssets` and
|
|
149
|
+
// `unity.*` that are defined in the Unity export's gradle.properties. When the
|
|
150
|
+
// unityLibrary is included as a subproject, it inherits the host's properties,
|
|
151
|
+
// so we need to copy the required ones over.
|
|
152
|
+
config = withGradleProperties(config, (config) => {
|
|
153
|
+
const projectRoot = config.modRequest.projectRoot;
|
|
154
|
+
const androidUnityPath =
|
|
155
|
+
options.androidUnityPath ||
|
|
156
|
+
process.env.EXPO_UNITY_ANDROID_PATH ||
|
|
157
|
+
path.join(projectRoot, 'unity', 'builds', 'android');
|
|
158
|
+
|
|
159
|
+
const unityPropsPath = path.join(androidUnityPath, 'gradle.properties');
|
|
160
|
+
const unityProps = parsePropertiesFile(unityPropsPath);
|
|
161
|
+
|
|
162
|
+
// Only copy unity-specific properties (unity.* and unityStreamingAssets)
|
|
163
|
+
const existingKeys = new Set(
|
|
164
|
+
config.modResults
|
|
165
|
+
.filter((p) => p.type === 'property')
|
|
166
|
+
.map((p) => p.key)
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
for (const prop of unityProps) {
|
|
170
|
+
if (
|
|
171
|
+
(prop.key.startsWith('unity.') || prop.key === 'unityStreamingAssets' || prop.key === 'unityTemplateVersion') &&
|
|
172
|
+
!existingKeys.has(prop.key)
|
|
173
|
+
) {
|
|
174
|
+
config.modResults.push(prop);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return config;
|
|
179
|
+
});
|
|
180
|
+
|
|
124
181
|
// -- Android: build.gradle (flatDir repos for Unity's native libs) --
|
|
125
182
|
// This must go in the root build.gradle (not settings.gradle) because
|
|
126
183
|
// `allprojects` is not a valid method in settings.gradle on Gradle 8+.
|