This is an experimental project integrating ReactJS with unity UIElements.
Add a dependency into your manifest.json
.
{
"dependencies": {
"com.mkmarek.uielements.react": "https://github.com/mkmarek/unity-react-uielements.git#releases/vX.X.X",
}
}
For released version numbers check the releases tab.
- In your unity
Assets
folder create aResources
folder. - Using whatever file editor you like create a
index.jsx
file inside thatResources
folder. - Paste the following content inside the
index.jsx
file.
import React from 'react';
import { render } from 'unity-renderer';
const style = {
width: "80%",
height: "80%",
backgroundColor: "#ffffff",
fontSize: 21,
alignSelf: 'Center',
alignItems: 'Center',
justifyContent: 'Center'
}
function App() {
return <visualElement style={style}>
Hello Unity!
</visualElement>
}
render(<App />)
- In your Unity scene create a new empty object and add
PanelRenderer
andEventSystem
monobehaviours to it as you would normaly do for runtime UIElements. - Attach
ReactRuntime
monobehaviour to the object and drag yourindex.jsx
into theRoot
field.
Set the root property to your index.jsx
. Just drag it from your Resources
folder into the field.
For bigger example look into the examples folder.
Check the wiki for more information.