@hugebug4ever/react-native-unity 0.0.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.
Files changed (70) hide show
  1. package/README.md +77 -0
  2. package/android/build.gradle +38 -0
  3. package/android/consumer-rules.pro +3 -0
  4. package/android/src/main/AndroidManifest.xml +4 -0
  5. package/android/src/main/java/com/hugebug4ever/rnunity/RNUnityBridge.kt +5 -0
  6. package/android/src/main/java/com/hugebug4ever/rnunity/RNUnityHostView.kt +95 -0
  7. package/android/src/main/java/com/hugebug4ever/rnunity/RNUnityPackage.kt +31 -0
  8. package/android/src/main/java/com/hugebug4ever/rnunity/RNUnityViewManager.kt +30 -0
  9. package/android/src/main/java/com/hugebug4ever/rnunity/UnityPlayerAdapter.kt +58 -0
  10. package/android/src/main/java/com/hugebug4ever/rnunity/UnityRuntimeController.kt +329 -0
  11. package/android/src/main/java/com/hugebug4ever/rnunity/UnityRuntimeModule.kt +46 -0
  12. package/android/src/main/java/com/hugebug4ever/rnunity/UnityRuntimeState.kt +16 -0
  13. package/app.plugin.js +2 -0
  14. package/cli/index.js +140 -0
  15. package/ios/RNUnityNativeBridge.mm +6 -0
  16. package/ios/RNUnityRuntimeController.h +29 -0
  17. package/ios/RNUnityRuntimeController.mm +316 -0
  18. package/ios/RNUnityView.h +17 -0
  19. package/ios/RNUnityView.mm +105 -0
  20. package/ios/UnityRuntime.mm +49 -0
  21. package/lib/commonjs/UnityRuntime.js +53 -0
  22. package/lib/commonjs/UnityRuntime.js.map +1 -0
  23. package/lib/commonjs/UnityView.js +35 -0
  24. package/lib/commonjs/UnityView.js.map +1 -0
  25. package/lib/commonjs/index.js +20 -0
  26. package/lib/commonjs/index.js.map +1 -0
  27. package/lib/commonjs/package.json +1 -0
  28. package/lib/commonjs/specs/NativeUnityRuntime.js +9 -0
  29. package/lib/commonjs/specs/NativeUnityRuntime.js.map +1 -0
  30. package/lib/commonjs/specs/NativeUnityView.js +10 -0
  31. package/lib/commonjs/specs/NativeUnityView.js.map +1 -0
  32. package/lib/commonjs/types.js +6 -0
  33. package/lib/commonjs/types.js.map +1 -0
  34. package/lib/typescript/UnityRuntime.d.ts +12 -0
  35. package/lib/typescript/UnityRuntime.d.ts.map +1 -0
  36. package/lib/typescript/UnityView.d.ts +3 -0
  37. package/lib/typescript/UnityView.d.ts.map +1 -0
  38. package/lib/typescript/index.d.ts +4 -0
  39. package/lib/typescript/index.d.ts.map +1 -0
  40. package/lib/typescript/specs/NativeUnityRuntime.d.ts +15 -0
  41. package/lib/typescript/specs/NativeUnityRuntime.d.ts.map +1 -0
  42. package/lib/typescript/specs/NativeUnityView.d.ts +32 -0
  43. package/lib/typescript/specs/NativeUnityView.d.ts.map +1 -0
  44. package/lib/typescript/types.d.ts +63 -0
  45. package/lib/typescript/types.d.ts.map +1 -0
  46. package/package/UnityRuntime.ts +64 -0
  47. package/package/UnityView.tsx +32 -0
  48. package/package/index.ts +20 -0
  49. package/package/specs/NativeUnityRuntime.ts +17 -0
  50. package/package/specs/NativeUnityView.ts +27 -0
  51. package/package/types.ts +85 -0
  52. package/package.json +90 -0
  53. package/plugin/build/index.js +132 -0
  54. package/plugin/ios/configure_unity.rb +108 -0
  55. package/plugin/src/index.ts +175 -0
  56. package/plugin/tsconfig.json +13 -0
  57. package/react-native-unity.podspec +34 -0
  58. package/react-native.config.js +9 -0
  59. package/unity-package/Editor/Exporter.cs +91 -0
  60. package/unity-package/Editor/Exporter.cs.meta +2 -0
  61. package/unity-package/Editor/ReactNativeUnity.Editor.asmdef +8 -0
  62. package/unity-package/Editor/ReactNativeUnity.Editor.asmdef.meta +7 -0
  63. package/unity-package/Editor.meta +8 -0
  64. package/unity-package/Runtime/ReactNativeBridge.cs +48 -0
  65. package/unity-package/Runtime/ReactNativeBridge.cs.meta +2 -0
  66. package/unity-package/Runtime/ReactNativeUnity.Runtime.asmdef +6 -0
  67. package/unity-package/Runtime/ReactNativeUnity.Runtime.asmdef.meta +7 -0
  68. package/unity-package/Runtime.meta +8 -0
  69. package/unity-package/package.json +11 -0
  70. package/unity-package/package.json.meta +7 -0
@@ -0,0 +1,91 @@
1
+ using System;
2
+ using System.IO;
3
+ using System.Linq;
4
+ using UnityEditor;
5
+ using UnityEditor.Build;
6
+ using UnityEditor.SceneManagement;
7
+ using UnityEngine;
8
+ using UnityEngine.Rendering;
9
+ using UnityEngine.SceneManagement;
10
+
11
+ namespace ReactNativeUnity.Editor
12
+ {
13
+ public static class Exporter
14
+ {
15
+ private const string GeneratedScene = "Assets/Scenes/RNUnitySample.unity";
16
+
17
+ public static void ExportFromCommandLine()
18
+ {
19
+ var platform = ReadArgument("-rnUnityPlatform");
20
+ var output = ReadArgument("-rnUnityOutput");
21
+ if (string.IsNullOrWhiteSpace(platform) || string.IsNullOrWhiteSpace(output))
22
+ throw new ArgumentException("-rnUnityPlatform and -rnUnityOutput are required");
23
+
24
+ output = Path.GetFullPath(output);
25
+ Directory.CreateDirectory(output);
26
+ var scene = EnsureScene();
27
+
28
+ BuildTarget target;
29
+ if (platform.Equals("android", StringComparison.OrdinalIgnoreCase))
30
+ {
31
+ target = BuildTarget.Android;
32
+ EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
33
+ PlayerSettings.Android.targetArchitectures =
34
+ AndroidArchitecture.ARM64 | AndroidArchitecture.X86_64;
35
+ PlayerSettings.SetGraphicsAPIs(
36
+ BuildTarget.Android,
37
+ new[] { GraphicsDeviceType.OpenGLES3 });
38
+ }
39
+ else if (platform.Equals("ios", StringComparison.OrdinalIgnoreCase))
40
+ {
41
+ target = BuildTarget.iOS;
42
+ }
43
+ else
44
+ {
45
+ throw new ArgumentException($"Unsupported platform: {platform}");
46
+ }
47
+
48
+ var report = BuildPipeline.BuildPlayer(new BuildPlayerOptions
49
+ {
50
+ scenes = new[] { scene },
51
+ locationPathName = output,
52
+ target = target,
53
+ options = BuildOptions.AcceptExternalModificationsToPlayer,
54
+ });
55
+ if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)
56
+ throw new BuildFailedException($"Unity export failed: {report.summary.result}");
57
+ }
58
+
59
+ private static string EnsureScene()
60
+ {
61
+ if (File.Exists(GeneratedScene)) return GeneratedScene;
62
+ Directory.CreateDirectory(Path.GetDirectoryName(GeneratedScene)!);
63
+ var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
64
+
65
+ var cameraObject = new GameObject("Main Camera");
66
+ cameraObject.tag = "MainCamera";
67
+ var camera = cameraObject.AddComponent<Camera>();
68
+ camera.backgroundColor = new Color(0.035f, 0.055f, 0.075f);
69
+ cameraObject.transform.position = new Vector3(0f, 0f, -6f);
70
+
71
+ var lightObject = new GameObject("Directional Light");
72
+ lightObject.AddComponent<Light>().type = LightType.Directional;
73
+ lightObject.transform.rotation = Quaternion.Euler(45f, -30f, 0f);
74
+
75
+ var bridge = GameObject.CreatePrimitive(PrimitiveType.Cube);
76
+ bridge.name = "Bridge";
77
+ bridge.AddComponent<ReactNativeBridgeReceiver>();
78
+
79
+ EditorSceneManager.SaveScene(scene, GeneratedScene);
80
+ AssetDatabase.SaveAssets();
81
+ return GeneratedScene;
82
+ }
83
+
84
+ private static string ReadArgument(string name)
85
+ {
86
+ var args = Environment.GetCommandLineArgs();
87
+ var index = Array.IndexOf(args, name);
88
+ return index >= 0 && index + 1 < args.Length ? args[index + 1] : string.Empty;
89
+ }
90
+ }
91
+ }
@@ -0,0 +1,2 @@
1
+ fileFormatVersion: 2
2
+ guid: 57578edbee01d0d4282da01639387740
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "ReactNativeUnity.Editor",
3
+ "rootNamespace": "ReactNativeUnity.Editor",
4
+ "references": ["ReactNativeUnity.Runtime"],
5
+ "includePlatforms": ["Editor"],
6
+ "autoReferenced": true
7
+ }
8
+
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 8a95e3053734c4349b7dc7b80bf0ede2
3
+ AssemblyDefinitionImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 20bf2985e8987f848be72d3c28e70b48
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,48 @@
1
+ using System;
2
+ using System.Runtime.InteropServices;
3
+ using UnityEngine;
4
+
5
+ namespace ReactNativeUnity
6
+ {
7
+ public static class ReactNativeBridge
8
+ {
9
+ #if UNITY_IOS && !UNITY_EDITOR
10
+ [DllImport("__Internal")]
11
+ private static extern void RNUnitySendMessage(string message);
12
+ #endif
13
+
14
+ public static void SendMessage(string message)
15
+ {
16
+ message ??= string.Empty;
17
+ #if UNITY_ANDROID && !UNITY_EDITOR
18
+ using var bridge = new AndroidJavaClass("com.hugebug4ever.rnunity.RNUnityBridge");
19
+ bridge.CallStatic("sendMessage", message);
20
+ #elif UNITY_IOS && !UNITY_EDITOR
21
+ RNUnitySendMessage(message);
22
+ #else
23
+ Debug.Log($"[RNUnity] {message}");
24
+ #endif
25
+ }
26
+ }
27
+
28
+ public sealed class ReactNativeBridgeReceiver : MonoBehaviour
29
+ {
30
+ [SerializeField] private bool rotate = true;
31
+
32
+ private void Start()
33
+ {
34
+ ReactNativeBridge.SendMessage("unity-ready");
35
+ }
36
+
37
+ private void Update()
38
+ {
39
+ if (rotate) transform.Rotate(20f * Time.deltaTime, 35f * Time.deltaTime, 0f);
40
+ }
41
+
42
+ public void OnMessage(string message)
43
+ {
44
+ ReactNativeBridge.SendMessage($"echo:{message}");
45
+ }
46
+ }
47
+ }
48
+
@@ -0,0 +1,2 @@
1
+ fileFormatVersion: 2
2
+ guid: 8fd3c1c2d0cc3944eac46293a5bd1f50
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "ReactNativeUnity.Runtime",
3
+ "rootNamespace": "ReactNativeUnity",
4
+ "autoReferenced": true
5
+ }
6
+
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 83fd68dc3528c8247aeb821c223c171b
3
+ AssemblyDefinitionImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 74342cb764500dc46b1c113b5e2a1437
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "com.hugebug4ever.react-native-unity",
3
+ "version": "0.1.0",
4
+ "displayName": "React Native Unity Bridge",
5
+ "description": "Message bridge and batch exporter for @hugebug4ever/react-native-unity",
6
+ "unity": "6000.3",
7
+ "author": {
8
+ "name": "hugebug4ever"
9
+ }
10
+ }
11
+
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 719fa100c2f080d4da9d372febabe7b2
3
+ PackageManifestImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant: