Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reload unity instance #103

Open
primekhan555 opened this issue Feb 24, 2024 · 0 comments
Open

How to reload unity instance #103

primekhan555 opened this issue Feb 24, 2024 · 0 comments

Comments

@primekhan555
Copy link

I have kept androidKeepPlayerMounted this false , so first time unity loads but when i navigate to any other screen and come back again to unity screen then unity does not load below is the code. Thank you for taking a look.

import {
ImageBackground,
StatusBar,
Image,
TouchableOpacity,
View,
TextInput,
SafeAreaView,
Button,
} from 'react-native';
import React, {useRef, useEffect, useState} from 'react';
import Images from '../../../Styles/Images';
import styles from './Styles';
import UnityView from '@azesmway/react-native-unity';
import {useNavigation, useFocusEffect} from '@react-navigation/native';
import Styles from '../../Auth/Login/Styles';
import {Colors} from 'react-native/Libraries/NewAppScreen';
export default function FaceInteraction(props): React.JSX.Element {
const {navigation} = props;
const unityRef = useRef(null);
const [message, setMessage] = useState('');
const [showTextField, setShowTextField] = useState(false);
console.log(unityRef);
const handleInputChange = inputValue => {
setMessage(inputValue);
};

const submitHandler = () => {
const unityData = {
name: message,
age: 3,
};
let jsonedData = JSON.stringify(unityData);
console.log(unityData)
SendData(jsonedData);
};
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
async function SendData(data: any) {
await delay(500);
console.log('data is sended from react native');
unityRef.current?.postMessage('ReactToUnity', 'GetDatas', data);
}

useEffect(() => {
return () => {
unityRef.current?.componentWillUnmount();
};
}, []);

return (

<View style={{backgroundColor: 'black'}}>
<UnityView
ref={unityRef}
style={{ height: 100%', width: '100%'}}
androidKeepPlayerMounted={false}
onUnityMessage={result => {
console.log('Message Here : ', result.nativeEvent.message);
let d = result.nativeEvent.message;
if (d.includes('home')) {
navigation.navigate('BottomNavigation', {screen: 'HomeTab'});
}
}}
/>

);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant