### Start development server Source: https://reactunity.github.io/reference Launches the Webpack Dev Server with Fast Refresh enabled. ```bash react-unity-scripts start ``` -------------------------------- ### Install Material Design Package Source: https://reactunity.github.io/reference/material Install the package using npm. ```bash npm i @reactunity/material ``` -------------------------------- ### Install ClearScript via OpenUPM Source: https://reactunity.github.io/learn/howto/debug Command to add the ClearScript package to your Unity project root. ```bash npx openupm-cli add com.reactunity.clearscript ``` -------------------------------- ### String Media Query Example Source: https://reactunity.github.io/reference/media-queries Compare string-typed properties against specific valid values. ```css @media (system: windows) or (platform: iphoneplayer) { ... } ``` -------------------------------- ### Rendering a root component Source: https://reactunity.github.io/reference/api/render Example of importing the render function and mounting a component at the top level of an application. ```javascript import { render } from '@reactunity/renderer'; function Hello() { return

Hello, world!

; } render(); ``` -------------------------------- ### CSS Pointer Events Styles Source: https://reactunity.github.io/reference/css/pointer-events Example CSS configuration for layout alignment and button spacing. ```css :root { align-items: center; } .test { flex-direction: row; align-items: center; } .test > button { margin: 20px; } ``` -------------------------------- ### Numeric Media Query Example Source: https://reactunity.github.io/reference/media-queries Perform numeric comparisons using min/max prefixes or standard comparison operators. ```css @media (aspect-ratio: 1.6) and (1024 >= window-width >= 2160) { ... } ``` -------------------------------- ### Boolean Media Query Example Source: https://reactunity.github.io/reference/media-queries Use boolean properties to check for the existence of specific environment states. ```css @media (full-screen and ugui) { ... } ``` -------------------------------- ### Implement a Todo App in ReactUnity Source: https://reactunity.github.io/ A complete example demonstrating component structure, state management with hooks, and event handling for a Todo application. ```javascript import { render } from '@reactunity/renderer'; import { useRef, useState } from 'react'; export function TodoItem(props) { return {props.item.text} ; } export function TodoPage() { const lastId = useRef(3); const [items, setItems] = useState([ { id: 0, text: 'Take a walk' }, { id: 1, text: 'Buy groceries' }, { id: 2, text: 'Prepare dinner' }, ]); const inputRef = useRef(); function addTodo(item) { inputRef.current.Value = ''; setItems(oldItems => { const newItems = [...oldItems]; newItems.push({ id: lastId.current++, text: item }); return newItems; }); } function removeTodo(id) { setItems(oldItems => oldItems.filter(x => x.id !== id)); } return TODO app example addTodo(sender.Value)} /> {items.map((item) => )} ; } render(); ``` -------------------------------- ### Apply z-index in CSS Source: https://reactunity.github.io/reference/css/z-index Example showing z-index applied to elements on hover to bring them to the front. ```css :root { align-items: center; } .items { flex-direction: row; align-items: center; margin-top: 20px; } .item1 { width: 100px; height: 100px; background-color: coral; } .item2 { width: 80px; height: 80px; margin-left: -20px; background-color: slategray; } .item1, .item2 { transition: scale 200ms; } .item1:hover, .item2:hover { cursor: pointer; z-index: 10; scale: 1.1; } ``` -------------------------------- ### CSS Rotate Animation Example Source: https://reactunity.github.io/reference/css/rotate Demonstrates various rotation units and 3D rotation syntax within a keyframe animation. ```css .items { flex-direction: column; align-self: flex-start; margin: 100px auto; border: 1px solid gray; } .item { width: 100px; height: 100px; background-color: coral; animation: rotateAnim 5s infinite; } @keyframes rotateAnim { 0% { rotate: 1; } 20% { rotate: 30deg; } 40% { rotate: 1.2rad; } 60% { rotate: 0.625turn; } 80% { rotate: 45deg 45deg 0.625turn; } } ``` -------------------------------- ### Define CSS styles for ReactUnity elements Source: https://reactunity.github.io/reference/css Example of defining root styles and specific view element styles including hover states. ```css :root { justify-content: space-around; text-align: center; background-color: #a9b2ba; } view { align-self: center; width: 100px; height: 100px; background-color: coral; cursor: pointer; } view:hover { background-color: blue; } ``` -------------------------------- ### CSS Translate Animation Example Source: https://reactunity.github.io/reference/css/translate Demonstrates using the translate property within keyframes to move an element across different coordinates over time. ```css .items { flex-direction: column; align-self: flex-start; margin: 100px auto; border: 1px solid gray; } .item { width: 100px; height: 100px; background-color: coral; animation: translateAnim 4s infinite; } @keyframes translateAnim { 0% { translate: 0px 0px; } 25% { translate: 220px 40px; } 50% { translate: 200px 200px; } 75% { translate: -50px 80px; } 100% { translate: 0px 0px; } } ``` -------------------------------- ### Component Usage Source: https://reactunity.github.io/reference/components/svg Example of how to use the component to render a vector graphic with specific dimensions and styling. ```APIDOC ## Component ### Description The `` component is used to render inline SVG graphics. It requires the `Unity.VectorGraphics` package to be installed in the project. ### Usage ```jsx ``` ``` -------------------------------- ### Render an inline SVG Source: https://reactunity.github.io/reference/components/svg Example of using the component to render a vector graphic with specific dimensions and styling. ```javascript export default function App() { return }; ``` -------------------------------- ### CSS visibility property usage Source: https://reactunity.github.io/reference/css/visibility Example showing how to use the visibility property to hide non-hovered elements within a container. ```css :root { align-items: center; } .items { flex-direction: row; align-items: center; margin-top: 20px; cursor: pointer; } .items > * { width: 100px; height: 100px; margin: 20px; } .items:hover :not(:hover) { visibility: hidden; } ``` -------------------------------- ### Build project for production Source: https://reactunity.github.io/reference Compiles the project into static files for production deployment. ```bash react-unity-scripts build ``` -------------------------------- ### Basic Toggle Implementation Source: https://reactunity.github.io/reference/components/toggle Demonstrates a toggle component controlling a global light state. ```javascript export default function App() { const light = Globals.Light; return light.enabled = val} value={light.enabled} /> Toggle light ; }; ``` -------------------------------- ### Implementing a Video Player with Playback Controls Source: https://reactunity.github.io/reference/components/video Uses a ref to access the VideoPlayer instance for manual play/pause control and handles video source loading. ```javascript import { useState, useEffect } from 'react'; export default function App() { const videoAddress = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4'; const [videoRef, setVideoRef] = useState(); useEffect(() => { if (videoRef) { videoRef.VideoPlayer.Play(); } }, [videoRef]); const toggleVideo = () => { const vp = videoRef.VideoPlayer; if (vp.isPlaying) vp.Pause(); else vp.Play(); }; return <> ; }; ``` -------------------------------- ### Applying box-shadow styles Source: https://reactunity.github.io/reference/css/box-shadow Demonstrates various box-shadow configurations including standard, multi-layered, inset, and blurred shadows. ```css :root { padding: 10px; } view { flex-grow: 1; margin: 20px auto; background-color: white; width: 300px; } view:nth-child(1) { box-shadow: 1px 1px 4px 0 black; } view:nth-child(2) { box-shadow: 0 5px 5px -3px rgb(0 0 0 / 20%), 0 8px 10px 1px rgb(0 0 0 / 14%), 0 3px 14px 2px rgb(0 0 0 / 12%); } view:nth-child(3) { border-radius: 50px; box-shadow: 1px 1px 4px 0 black inset; } view:nth-child(4) { box-shadow: 0 0 4px 3px black; } ``` -------------------------------- ### Implement Tooltips with useDataTooltip Source: https://reactunity.github.io/reference/material/tooltip Demonstrates how to register buttons with different tooltip triggers (hover, press, click) and configure positioning using data attributes. ```javascript import { useDataTooltip, Button } from '@reactunity/material'; import '@reactunity/material/styles'; export default function App() { const ttHover = useDataTooltip('hover'); const ttPress = useDataTooltip('press'); const ttClick = useDataTooltip('click'); return Hover Press Click ; } ``` -------------------------------- ### Instantiate a Prefab in React Source: https://reactunity.github.io/reference/components/prefab Basic usage of the component to render a prefab loaded from globals or resources. ```javascript export default function App() { // Load the prefab using globals const { prefab } = useGlobals(); // or alternatively you can load the prefab from resources // const prefab = useMemo(() => Interop.UnityEngine.Resources.Load('MyPrefab') as UnityEngine.GameObject, []); return ; }; ``` -------------------------------- ### Applying Opacity with CSS Source: https://reactunity.github.io/reference/css/opacity Demonstrates using opacity values with hover states for interactive elements. ```css :root { align-items: center; } .items { flex-direction: row; align-items: center; } .item1, .item2, .item3 { width: 100px; height: 100px; transition: opacity 200ms; cursor: pointer; margin: 20px; } .item1:hover { opacity: 0.4; } .item2:hover { opacity: 80%; } .item3:hover { opacity: 5%; } ``` -------------------------------- ### Implement Select Component in React Source: https://reactunity.github.io/reference/material/select Demonstrates basic usage of the Select component, including single selection, multiple selection, and chip-based multi-selection. ```javascript import { Select } from '@reactunity/material'; import '@reactunity/material/styles'; export default function App() { return ; } ``` -------------------------------- ### Toggle and ToggleGroup Usage Source: https://reactunity.github.io/reference/material/toggle Demonstrates basic checkbox, indeterminate state, and grouped toggle configurations. ```javascript import { Toggle, ToggleGroup } from '@reactunity/material'; import '@reactunity/material/styles'; export default function App() { return Checkbox Indeterminate Radio Group: Option 1 Option 2 Option 3 Checkbox Group: Option 1 Option 2 Option 3 ; } ``` -------------------------------- ### Basic RawImage implementation Source: https://reactunity.github.io/reference/components/rawimage Displays an image from a URL with a fixed height. ```javascript import { useState, useEffect } from 'react'; export default function App() { return ( ); }; ``` -------------------------------- ### Basic Input Component Usage Source: https://reactunity.github.io/reference/components/input Demonstrates a standard text input with a default value, margin styling, and an onChange event handler. ```javascript const defaultValue = 'Default value'; export default function App() { return rich-text here`} ; }; ``` -------------------------------- ### Animating Border Radius in CSS Source: https://reactunity.github.io/reference/css/border-radius Demonstrates using keyframes to animate the border-radius property and individual corner radii over time. ```css .test { width: 240px; height: 160px; margin: 40px auto; background-color: cornflowerblue; animation: borderRadiusAnim 6s infinite; } @keyframes borderRadiusAnim { 0% { border-radius: 20%; } 25% { border-radius: 50%; } 50% { border-radius: 50%; border-top-left-radius: 20%; border-bottom-right-radius: 20%; } 75% { border-radius: 20%; border-bottom-left-radius: 0; } 100% { border-radius: 20%; } } ``` -------------------------------- ### Basic Accordion Implementation Source: https://reactunity.github.io/reference/material/accordion A standard implementation of the Accordion component using the @reactunity/material library. ```javascript import { Accordion } from '@reactunity/material'; import '@reactunity/material/styles'; export default function App() { return This is the accordion summary Accordion content ; } ``` -------------------------------- ### Load HTML content from a URL Source: https://reactunity.github.io/reference/components/html Use the source property to fetch and render HTML content from a remote URL. ```javascript const url = 'https://reactunity.github.io/examples/html-content.html'; export default function App() { return ; }; ``` -------------------------------- ### Slider Component Implementation Source: https://reactunity.github.io/reference/material/slider Demonstrates various Slider configurations including horizontal and vertical orientations, normal and diff modes, and step increments. ```javascript import { Slider } from '@reactunity/material'; import '@reactunity/material/styles'; export default function App() { return ; } ``` -------------------------------- ### Applying content to elements and pseudo-elements Source: https://reactunity.github.io/reference/css/content Demonstrates using the content property within CSS classes and pseudo-element selectors. ```css .test { border: 1px solid black; padding: 12px; flex-direction: row; } .test:hover text { content: "Inside content!"; } .test:before { content: "Before content!"; margin-right: 10px; } .test:after { content: "After content!"; margin-left: 10px; } ``` -------------------------------- ### Pass Custom Properties and Events to a Prefab Source: https://reactunity.github.io/reference/components/prefab Configure the component with custom properties and event listeners to interact with the target component. ```javascript export default function App() { const prefab = useMemo(() => Interop.UnityEngine.Resources.Load('MyPrefab') as UnityEngine.GameObject, []); return ( console.log('Something happened', val)} /> ); }; ``` -------------------------------- ### Applying appearance property in React Source: https://reactunity.github.io/reference/css/appearance Demonstrates applying the appearance property directly to button elements using inline styles. ```javascript export default function App() { return <> Click the buttons to see style differences ; } ``` -------------------------------- ### Applying Scale in CSS Keyframes Source: https://reactunity.github.io/reference/css/scale Demonstrates using the scale property within a keyframe animation to transition between uniform and non-uniform scaling states. ```css .items { flex-direction: column; align-self: flex-start; margin: 100px auto; border: 1px solid gray; } .item { width: 100px; height: 100px; background-color: coral; animation: scaleAnim 4s infinite; } @keyframes scaleAnim { 0% { scale: 1; } 25% { scale: 2.2; } 50% { scale: 3.4 1; } 75% { scale: 0.5; } 100% { scale: 1; } } ``` -------------------------------- ### Apply CSS color property Source: https://reactunity.github.io/reference/css/color Demonstrates applying different color formats including named colors, hex codes, and rgba values to elements. ```css view { flex-grow: 1; justify-content: center; font-size: 48px; } view:nth-child(1) { color: crimson; } view:nth-child(2) { color: #a5a5a5; } view:nth-child(3) { color: rgba(10, 10, 235, 0.7); } view:nth-child(4) { color: #550055aa; } ``` -------------------------------- ### Animating Border Colors in CSS Source: https://reactunity.github.io/reference/css/border-color Demonstrates using border-color and specific side-color properties within a keyframe animation to change border appearance over time. ```css .test { width: 240px; height: 160px; margin: 40px auto; background-color: cornflowerblue; border-width: 30px; animation: borderColorAnim 8s infinite; } @keyframes borderColorAnim { 0% { border-color: black; } 25% { border-color: transparent; border-bottom-color: #ff7edb; } 50% { border-color: black; border-right-color: rgba(130, 85, 255, 0.363); border-bottom-color: hsla(46, 100%, 50%, 0.8); border-radius: 0; } 75% { border-color: gold; border-bottom-color: red; border-radius: 60px; } 100% { border-color: black; border-radius: 0; } } ``` -------------------------------- ### Load script content from a URL Source: https://reactunity.github.io/reference/components/script Uses the source property to fetch and execute JavaScript from an external URL. ```javascript const url = 'https://reactunity.github.io/examples/script-content.js'; export default function App() { return <> Styled text