import React from 'react' import { useTranslation } from 'react-i18next' import { useComponent } from '@xrengine/engine/src/ecs/functions/ComponentFunctions' import { LoadState, PrefabComponent } from '@xrengine/engine/src/scene/components/PrefabComponent' import { loadPrefab, unloadPrefab } from '@xrengine/engine/src/scene/functions/loaders/PrefabComponentFunctions' import { dispatchAction } from '@xrengine/hyperflux' import { exportPrefab } from '../../functions/assetFunctions' import { EditorAction } from '../../services/EditorServices' import { SelectionAction } from '../../services/SelectionServices' import { PropertiesPanelButton } from '../inputs/Button' import InputGroup from '../inputs/InputGroup' import PrefabInput from '../inputs/PrefabInput' import NodeEditor from './NodeEditor' import { EditorComponentType, updateProperty } from './Util' export const PrefabNodeEditor: EditorComponentType = (props) => { const { t } = useTranslation() const entity = props.entity const prefab = useComponent(entity, PrefabComponent) const isLoaded = prefab.loaded.value const onUnload = async () => { unloadPrefab(entity) await new Promise((resolve) => setTimeout(resolve, 1)) dispatchAction(EditorAction.sceneModified({ modified: true })) dispatchAction(SelectionAction.changedSceneGraph({})) } const onLoad = async () => { await loadPrefab(entity) dispatchAction(EditorAction.sceneModified({ modified: true })) dispatchAction(SelectionAction.changedSceneGraph({})) } const onReload = async () => { await onUnload() await onLoad() } const onExportAsset = async () => { await exportPrefab(entity) } return ( {isLoaded === LoadState.UNLOADED && ( {t('editor:properties:prefab.lbl-load')} )} {isLoaded === LoadState.LOADING &&

{t('Loading...')}

} {isLoaded === LoadState.LOADED && ( {t('editor:properties:prefab.lbl-unload')} {t('editor:properties:prefab.lbl-reload')} )} {isLoaded !== LoadState.LOADING && ( {t('editor:properties:prefab.lbl-export')} )}
) }