Skip to content

Commit 7b9942b

Browse files
committedNov 25, 2023
fix ios podspec and readme.md
1 parent 7816491 commit 7b9942b

File tree

6 files changed

+62
-28
lines changed

6 files changed

+62
-28
lines changed
 

‎README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
The plugin that allows you to embed a UNITY project into the react native as a full-fledged component
44

5-
<span style="color: red; font-size: 20px; font-weight: bold"> ATTENTION! </span>
5+
### ATTENTION!
66

77
The plugin now supports the new architecture as well.
88
For iOS, it is no longer necessary to embed a project created with Unity. Only the built UnityFramework.framework is used. It should be placed in the plugin folder at the path -
9-
```node_modules/@azesmway/react-native-unity/ios/``` or change the path in the ```react-native-unity.podspec``` file.
9+
```<YOUR_PROJECT>/unity/builds/ios``` or change the path in the ```react-native-unity.podspec``` file.
1010

1111
```
12+
s.prepare_command =
13+
<<-CMD
14+
cp -R ../../../unity/builds/ios/ ios/
15+
CMD
16+
1217
s.vendored_frameworks = ["ios/UnityFramework.framework"].
1318
```
1419

@@ -78,7 +83,7 @@ public class ButtonBehavior : MonoBehaviour
7883
3. Select Data folder and set a checkbox in the "Target Membership" section to "UnityFramework" ![image info](./docs/step1.jpg)
7984
4. You need to select the NativeCallProxy.h inside the `Unity-iPhone/Libraries/Plugins/iOS` folder of the Unity-iPhone project and change UnityFramework’s target membership from Project to Public. Don’t forget this step! ![image info](./docs/step2.jpg)
8085
5. If required - sign the project ```UnityFramework.framework``` and build a framework ![image info](./docs/step3.jpg)
81-
6. Open the folder with the built framework (by right-clicking) and move it to the plugin folder (```node_modules/@azesmway/react-native-unity/ios/```) ![image info](./docs/step4.jpg)
86+
6. Open the folder with the built framework (by right-clicking) and move it to the plugin folder (```<YOUR_PROJECT>/unity/builds/ios```) ![image info](./docs/step4.jpg)
8287

8388
### Android
8489

‎android/src/main/java/com/azesmwayreactnativeunity/ReactNativeUnityViewManager.java

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
@ReactModule(name = ReactNativeUnityViewManager.NAME)
2828
public class ReactNativeUnityViewManager extends ReactNativeUnityViewManagerSpec<ReactNativeUnityView> implements LifecycleEventListener, View.OnAttachStateChangeListener {
29-
ReactApplicationContext reactContext;
3029
ReactApplicationContext context;
3130
static ReactNativeUnityView view;
3231
public static final String NAME = "RNUnityView";

‎react-native-unity.podspec

+7
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,12 @@ Pod::Spec.new do |s|
4141
end
4242
end
4343

44+
# Copy the framework to the plugin folder so that xcode can install it
45+
# The framework should be placed in the <YOUR_PROJECT>/unity/builds/ios folder.
46+
s.prepare_command =
47+
<<-CMD
48+
cp -R ../../../unity/builds/ios/ ios/
49+
CMD
50+
4451
s.vendored_frameworks = ["ios/UnityFramework.framework"]
4552
end

‎src/UnityView.tsx

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22

3-
import NativeUnityView, { Commands } from './specs/UnityViewNativeComponent'
3+
import NativeUnityView, { Commands } from './specs/UnityViewNativeComponent';
44
import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
55
import { Platform } from 'react-native';
66

77
type UnityViewContentUpdateEvent = Readonly<{
8-
message: string
9-
}>
8+
message: string;
9+
}>;
1010

1111
type RNUnityViewProps = {
1212
androidKeepPlayerMounted?: boolean;
@@ -16,40 +16,44 @@ type RNUnityViewProps = {
1616
onPlayerQuit?: DirectEventHandler<UnityViewContentUpdateEvent>;
1717
};
1818

19-
type ComponentRef = InstanceType<typeof NativeUnityView>
19+
type ComponentRef = InstanceType<typeof NativeUnityView>;
2020

2121
export default class UnityView extends React.Component<RNUnityViewProps> {
22-
ref = React.createRef<ComponentRef>()
22+
ref = React.createRef<ComponentRef>();
2323

24-
public postMessage = (gameObject: string, methodName: string, message: string) => {
24+
public postMessage = (
25+
gameObject: string,
26+
methodName: string,
27+
message: string
28+
) => {
2529
if (this.ref.current) {
26-
Commands.postMessage(this.ref.current, gameObject, methodName, message)
30+
Commands.postMessage(this.ref.current, gameObject, methodName, message);
2731
}
28-
}
32+
};
2933

3034
public unloadUnity = () => {
3135
if (this.ref.current) {
32-
Commands.unloadUnity(this.ref.current)
36+
Commands.unloadUnity(this.ref.current);
3337
}
34-
}
38+
};
3539

3640
public pauseUnity(pause: boolean) {
3741
if (this.ref.current) {
38-
Commands.pauseUnity(this.ref.current, pause)
42+
Commands.pauseUnity(this.ref.current, pause);
3943
}
4044
}
4145

4246
public resumeUnity() {
4347
if (this.ref.current) {
44-
Commands.resumeUnity(this.ref.current)
48+
Commands.resumeUnity(this.ref.current);
4549
}
4650
}
4751

4852
public windowFocusChanged(hasFocus = true) {
4953
if (Platform.OS !== 'android') return;
5054

5155
if (this.ref.current) {
52-
Commands.windowFocusChanged(this.ref.current, hasFocus)
56+
Commands.windowFocusChanged(this.ref.current, hasFocus);
5357
}
5458
}
5559

@@ -61,7 +65,7 @@ export default class UnityView extends React.Component<RNUnityViewProps> {
6165

6266
componentWillUnmount() {
6367
if (this.ref.current) {
64-
Commands.unloadUnity(this.ref.current)
68+
Commands.unloadUnity(this.ref.current);
6569
}
6670
}
6771

‎src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import UnityView from './UnityView'
1+
import UnityView from './UnityView';
22

3-
export default UnityView
3+
export default UnityView;

‎src/specs/UnityViewNativeComponent.ts

+27-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { HostComponent, ViewProps } from 'react-native';
44
import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
55

66
export type UnityViewContentUpdateEvent = Readonly<{
7-
message: string
8-
}>
7+
message: string;
8+
}>;
99

1010
export interface NativeProps extends ViewProps {
1111
androidKeepPlayerMounted?: boolean;
@@ -16,15 +16,34 @@ export interface NativeProps extends ViewProps {
1616
}
1717

1818
export interface NativeCommands {
19-
postMessage: (viewRef: React.ElementRef<HostComponent<NativeProps>>, gameObject: string, methodName: string, message: string) => void;
19+
postMessage: (
20+
viewRef: React.ElementRef<HostComponent<NativeProps>>,
21+
gameObject: string,
22+
methodName: string,
23+
message: string
24+
) => void;
2025
unloadUnity: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
21-
pauseUnity: (viewRef: React.ElementRef<HostComponent<NativeProps>>, pause: boolean) => void;
22-
resumeUnity: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
23-
windowFocusChanged: (viewRef: React.ElementRef<HostComponent<NativeProps>>, hasFocus: boolean) => void;
26+
pauseUnity: (
27+
viewRef: React.ElementRef<HostComponent<NativeProps>>,
28+
pause: boolean
29+
) => void;
30+
resumeUnity: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
31+
windowFocusChanged: (
32+
viewRef: React.ElementRef<HostComponent<NativeProps>>,
33+
hasFocus: boolean
34+
) => void;
2435
}
2536

2637
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
27-
supportedCommands: ['postMessage', 'unloadUnity', 'pauseUnity', 'resumeUnity', 'windowFocusChanged'],
38+
supportedCommands: [
39+
'postMessage',
40+
'unloadUnity',
41+
'pauseUnity',
42+
'resumeUnity',
43+
'windowFocusChanged',
44+
],
2845
});
2946

30-
export default codegenNativeComponent<NativeProps>('RNUnityView') as HostComponent<NativeProps>
47+
export default codegenNativeComponent<NativeProps>(
48+
'RNUnityView'
49+
) as HostComponent<NativeProps>;

0 commit comments

Comments
 (0)
Please sign in to comment.