@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.
- package/README.md +77 -0
- package/android/build.gradle +38 -0
- package/android/consumer-rules.pro +3 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/hugebug4ever/rnunity/RNUnityBridge.kt +5 -0
- package/android/src/main/java/com/hugebug4ever/rnunity/RNUnityHostView.kt +95 -0
- package/android/src/main/java/com/hugebug4ever/rnunity/RNUnityPackage.kt +31 -0
- package/android/src/main/java/com/hugebug4ever/rnunity/RNUnityViewManager.kt +30 -0
- package/android/src/main/java/com/hugebug4ever/rnunity/UnityPlayerAdapter.kt +58 -0
- package/android/src/main/java/com/hugebug4ever/rnunity/UnityRuntimeController.kt +329 -0
- package/android/src/main/java/com/hugebug4ever/rnunity/UnityRuntimeModule.kt +46 -0
- package/android/src/main/java/com/hugebug4ever/rnunity/UnityRuntimeState.kt +16 -0
- package/app.plugin.js +2 -0
- package/cli/index.js +140 -0
- package/ios/RNUnityNativeBridge.mm +6 -0
- package/ios/RNUnityRuntimeController.h +29 -0
- package/ios/RNUnityRuntimeController.mm +316 -0
- package/ios/RNUnityView.h +17 -0
- package/ios/RNUnityView.mm +105 -0
- package/ios/UnityRuntime.mm +49 -0
- package/lib/commonjs/UnityRuntime.js +53 -0
- package/lib/commonjs/UnityRuntime.js.map +1 -0
- package/lib/commonjs/UnityView.js +35 -0
- package/lib/commonjs/UnityView.js.map +1 -0
- package/lib/commonjs/index.js +20 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/NativeUnityRuntime.js +9 -0
- package/lib/commonjs/specs/NativeUnityRuntime.js.map +1 -0
- package/lib/commonjs/specs/NativeUnityView.js +10 -0
- package/lib/commonjs/specs/NativeUnityView.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/typescript/UnityRuntime.d.ts +12 -0
- package/lib/typescript/UnityRuntime.d.ts.map +1 -0
- package/lib/typescript/UnityView.d.ts +3 -0
- package/lib/typescript/UnityView.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +4 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/specs/NativeUnityRuntime.d.ts +15 -0
- package/lib/typescript/specs/NativeUnityRuntime.d.ts.map +1 -0
- package/lib/typescript/specs/NativeUnityView.d.ts +32 -0
- package/lib/typescript/specs/NativeUnityView.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +63 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/package/UnityRuntime.ts +64 -0
- package/package/UnityView.tsx +32 -0
- package/package/index.ts +20 -0
- package/package/specs/NativeUnityRuntime.ts +17 -0
- package/package/specs/NativeUnityView.ts +27 -0
- package/package/types.ts +85 -0
- package/package.json +90 -0
- package/plugin/build/index.js +132 -0
- package/plugin/ios/configure_unity.rb +108 -0
- package/plugin/src/index.ts +175 -0
- package/plugin/tsconfig.json +13 -0
- package/react-native-unity.podspec +34 -0
- package/react-native.config.js +9 -0
- package/unity-package/Editor/Exporter.cs +91 -0
- package/unity-package/Editor/Exporter.cs.meta +2 -0
- package/unity-package/Editor/ReactNativeUnity.Editor.asmdef +8 -0
- package/unity-package/Editor/ReactNativeUnity.Editor.asmdef.meta +7 -0
- package/unity-package/Editor.meta +8 -0
- package/unity-package/Runtime/ReactNativeBridge.cs +48 -0
- package/unity-package/Runtime/ReactNativeBridge.cs.meta +2 -0
- package/unity-package/Runtime/ReactNativeUnity.Runtime.asmdef +6 -0
- package/unity-package/Runtime/ReactNativeUnity.Runtime.asmdef.meta +7 -0
- package/unity-package/Runtime.meta +8 -0
- package/unity-package/package.json +11 -0
- 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,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,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
|
+
|