@dolami-inc/react-native-expo-unity 0.3.4 → 0.4.1

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. UnityPlayer extends FrameLayout.
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 = UnityPlayer(activity, this)
58
+ val player = UnityPlayerForActivityOrService(activity, this)
57
59
  unityPlayer = player
58
60
 
59
61
  NativeCallProxy.registerListener(this)
package/app.plugin.js CHANGED
@@ -4,6 +4,7 @@ const {
4
4
  withProjectBuildGradle,
5
5
  withAppBuildGradle,
6
6
  withGradleProperties,
7
+ withDangerousMod,
7
8
  } = require('@expo/config-plugins');
8
9
  const path = require('path');
9
10
  const fs = require('fs');
@@ -41,6 +42,7 @@ function parsePropertiesFile(filePath) {
41
42
  * - Includes the :unityLibrary Gradle module and .androidlib subprojects in settings.gradle
42
43
  * - Copies Unity gradle properties (unity.*, unityStreamingAssets) to host gradle.properties
43
44
  * - Adds flatDir repos for Unity's .aar/.jar libs in root build.gradle
45
+ * - Strips LAUNCHER intent from Unity's AndroidManifest (prevents duplicate app icon)
44
46
  * - Adds the unityLibrary dependency and NDK abiFilters in app/build.gradle
45
47
  *
46
48
  * @param {object} config - Expo config
@@ -144,6 +146,49 @@ const withExpoUnity = (config, options = {}) => {
144
146
  return config;
145
147
  });
146
148
 
149
+ // -- Android: Strip LAUNCHER intent from Unity's AndroidManifest --
150
+ // Unity exports include a LAUNCHER intent filter on UnityPlayerGameActivity,
151
+ // which creates a duplicate app icon. Since Unity is embedded (not standalone),
152
+ // we remove it so only the host app's launcher entry exists.
153
+ config = withDangerousMod(config, [
154
+ 'android',
155
+ (config) => {
156
+ const projectRoot = config.modRequest.projectRoot;
157
+ const androidUnityPath =
158
+ options.androidUnityPath ||
159
+ process.env.EXPO_UNITY_ANDROID_PATH ||
160
+ path.join(projectRoot, 'unity', 'builds', 'android');
161
+
162
+ const manifestPath = path.join(
163
+ androidUnityPath,
164
+ 'unityLibrary',
165
+ 'src',
166
+ 'main',
167
+ 'AndroidManifest.xml'
168
+ );
169
+
170
+ if (fs.existsSync(manifestPath)) {
171
+ let manifest = fs.readFileSync(manifestPath, 'utf8');
172
+
173
+ // Remove the entire <intent-filter> block containing LAUNCHER
174
+ const launcherRegex =
175
+ /\s*<intent-filter>\s*<category[^>]*LAUNCHER[^>]*\/>\s*<action[^>]*MAIN[^>]*\/>\s*<\/intent-filter>/g;
176
+ const altLauncherRegex =
177
+ /\s*<intent-filter>\s*<action[^>]*MAIN[^>]*\/>\s*<category[^>]*LAUNCHER[^>]*\/>\s*<\/intent-filter>/g;
178
+
179
+ const patched = manifest
180
+ .replace(launcherRegex, '')
181
+ .replace(altLauncherRegex, '');
182
+
183
+ if (patched !== manifest) {
184
+ fs.writeFileSync(manifestPath, patched, 'utf8');
185
+ }
186
+ }
187
+
188
+ return config;
189
+ },
190
+ ]);
191
+
147
192
  // -- Android: gradle.properties (copy Unity properties to host project) --
148
193
  // Unity's build.gradle references properties like `unityStreamingAssets` and
149
194
  // `unity.*` that are defined in the Unity export's gradle.properties. When the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolami-inc/react-native-expo-unity",
3
- "version": "0.3.4",
3
+ "version": "0.4.1",
4
4
  "description": "Unity as a Library (UaaL) bridge for React Native / Expo",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",