-
-
Notifications
You must be signed in to change notification settings - Fork 248
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
Introduce Prefab System #10047
Introduce Prefab System #10047
Changes from all commits
a0422c3
aeed25c
f7d04c3
8bcfd8e
807cf84
0b07cae
96f3aa9
abe8404
842489c
e94e3dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
CPAL-1.0 License | ||
|
||
The contents of this file are subject to the Common Public Attribution License | ||
Version 1.0. (the "License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE. | ||
The License is based on the Mozilla Public License Version 1.1, but Sections 14 | ||
and 15 have been added to cover use of software over a computer network and | ||
provide for limited attribution for the Original Developer. In addition, | ||
Exhibit A has been modified to be consistent with Exhibit B. | ||
|
||
Software distributed under the License is distributed on an "AS IS" basis, | ||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the | ||
specific language governing rights and limitations under the License. | ||
|
||
The Original Code is Ethereal Engine. | ||
|
||
The Original Developer is the Initial Developer. The Initial Developer of the | ||
Original Code is the Ethereal Engine team. | ||
|
||
All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023 | ||
Ethereal Engine. All Rights Reserved. | ||
*/ | ||
import { Component } from '@etherealengine/ecs/src/ComponentFunctions' | ||
import { LoopAnimationComponent } from '@etherealengine/engine/src/avatar/components/LoopAnimationComponent' | ||
import { EnvmapComponent } from '@etherealengine/engine/src/scene/components/EnvmapComponent' | ||
import { ModelComponent } from '@etherealengine/engine/src/scene/components/ModelComponent' | ||
import { PostProcessingComponent } from '@etherealengine/engine/src/scene/components/PostProcessingComponent' | ||
import { ShadowComponent } from '@etherealengine/engine/src/scene/components/ShadowComponent' | ||
import { SkyboxComponent } from '@etherealengine/engine/src/scene/components/SkyboxComponent' | ||
import { VariantComponent } from '@etherealengine/engine/src/scene/components/VariantComponent' | ||
import { defineState } from '@etherealengine/hyperflux' | ||
import { ColliderComponent } from '@etherealengine/spatial/src/physics/components/ColliderComponent' | ||
import { RigidBodyComponent } from '@etherealengine/spatial/src/physics/components/RigidBodyComponent' | ||
import { TriggerComponent } from '@etherealengine/spatial/src/physics/components/TriggerComponent' | ||
import { AmbientLightComponent } from '@etherealengine/spatial/src/renderer/components/AmbientLightComponent' | ||
import { DirectionalLightComponent } from '@etherealengine/spatial/src/renderer/components/DirectionalLightComponent' | ||
import { FogSettingsComponent } from '@etherealengine/spatial/src/renderer/components/FogSettingsComponent' | ||
import { HemisphereLightComponent } from '@etherealengine/spatial/src/renderer/components/HemisphereLightComponent' | ||
import { PointLightComponent } from '@etherealengine/spatial/src/renderer/components/PointLightComponent' | ||
import { SpotLightComponent } from '@etherealengine/spatial/src/renderer/components/SpotLightComponent' | ||
|
||
export const PrefabShelfCategories = defineState({ | ||
name: 'ee.editor.PrefabShelfCategories', | ||
initial: () => { | ||
return { | ||
'Light Prefab': [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. beyond this state, we need to also have the infrastructure to swap the component used inside the light editor, this alone doesn't make sense. We only want one of these components on an entity, and we want to have a dropdown in the properties editor for this. Same goes for the others. |
||
AmbientLightComponent, | ||
DirectionalLightComponent, | ||
HemisphereLightComponent, | ||
PointLightComponent, | ||
SpotLightComponent | ||
], | ||
'Physics Prefab': [ColliderComponent, RigidBodyComponent, TriggerComponent], | ||
'Model Prefab': [ModelComponent, LoopAnimationComponent, VariantComponent, EnvmapComponent, ShadowComponent], | ||
'Setting Prefab': [SkyboxComponent, FogSettingsComponent, PostProcessingComponent, FogSettingsComponent] | ||
//will continue to add more prefabs | ||
} as Record<string, Component[]> | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
CPAL-1.0 License | ||
|
||
The contents of this file are subject to the Common Public Attribution License | ||
Version 1.0. (the "License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE. | ||
The License is based on the Mozilla Public License Version 1.1, but Sections 14 | ||
and 15 have been added to cover use of software over a computer network and | ||
provide for limited attribution for the Original Developer. In addition, | ||
Exhibit A has been modified to be consistent with Exhibit B. | ||
|
||
Software distributed under the License is distributed on an "AS IS" basis, | ||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the | ||
specific language governing rights and limitations under the License. | ||
|
||
The Original Code is Ethereal Engine. | ||
|
||
The Original Developer is the Initial Developer. The Initial Developer of the | ||
Original Code is the Ethereal Engine team. | ||
|
||
All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023 | ||
Ethereal Engine. All Rights Reserved. | ||
*/ | ||
|
||
import { startCase } from 'lodash' | ||
import React, { useRef } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import { getMutableState, getState, useHookstate } from '@etherealengine/hyperflux' | ||
|
||
import PlaceHolderIcon from '@mui/icons-material/GroupAddOutlined' | ||
import { List, ListItemButton, ListItemIcon, ListItemText } from '@mui/material' | ||
|
||
import InputText from '@etherealengine/client-core/src/common/components/InputText' | ||
import { Component } from '@etherealengine/ecs/src/ComponentFunctions' | ||
import { ComponentJsonType } from '@etherealengine/engine/src/scene/types/SceneTypes' | ||
import Typography from '@etherealengine/ui/src/primitives/mui/Typography' | ||
import { ComponentEditorsState } from '../../functions/ComponentEditors' | ||
import { EditorControlFunctions } from '../../functions/EditorControlFunctions' | ||
import { usePopoverContextClose } from '../element/PopoverContext' | ||
import { PrefabShelfCategories } from './PrefabEditors' | ||
|
||
const PrefabListItem = ({ item }: { item: string }) => { | ||
const { t } = useTranslation() | ||
const Icon = getState(ComponentEditorsState)[item]?.iconComponent ?? PlaceHolderIcon | ||
const handleClosePopover = usePopoverContextClose() | ||
|
||
return ( | ||
<ListItemButton | ||
sx={{ pl: 4, bgcolor: 'var(--dockBackground)' }} | ||
onClick={() => { | ||
const PrefabNameShelfCategories = getState(PrefabShelfCategories) | ||
const componentJsons: ComponentJsonType[] = [] | ||
PrefabNameShelfCategories[item].forEach((component) => { | ||
componentJsons.push({ name: component.jsonID as string }) | ||
}) | ||
EditorControlFunctions.createObjectFromSceneElement(componentJsons) | ||
handleClosePopover() | ||
}} | ||
> | ||
<ListItemIcon style={{ color: 'var(--textColor)' }}> | ||
<Icon /> | ||
</ListItemIcon> | ||
<ListItemText | ||
primary={ | ||
<Typography variant="subtitle1" color={'var(--textColor)'}> | ||
{startCase(item.replace('-', ' ').toLowerCase())} | ||
</Typography> | ||
} | ||
secondary={ | ||
<Typography variant="caption" color={'var(--textColor)'}> | ||
{t(`editor:layout.assetGrid.component-detail.${item}`)} | ||
</Typography> | ||
} | ||
/> | ||
</ListItemButton> | ||
) | ||
} | ||
const ScenePrefabListItem = ({ categoryItems }: { categoryItems: string[]; isCollapsed: boolean }) => { | ||
return ( | ||
<> | ||
<List component={'div'} sx={{ bgcolor: 'var(--dockBackground)', width: '100%' }} disablePadding> | ||
{categoryItems.map((item) => ( | ||
<PrefabListItem item={item} /> | ||
))} | ||
</List> | ||
</> | ||
) | ||
} | ||
|
||
const usePrefabShelfCategories = (search: string) => { | ||
useHookstate(getMutableState(PrefabShelfCategories)).value | ||
|
||
if (!search) { | ||
return Object.entries(getState(PrefabShelfCategories)) | ||
} | ||
|
||
const searchRegExp = new RegExp(search, 'gi') | ||
|
||
return Object.entries(getState(PrefabShelfCategories)) | ||
.map(([category, items]) => { | ||
const filteredcategory = category.match(searchRegExp)?.length ? category : '' | ||
return [filteredcategory, items] as [string, Component[]] | ||
}) | ||
.filter(([_, items]) => !!items.length) | ||
} | ||
|
||
export function PrefabList() { | ||
const { t } = useTranslation() | ||
const search = useHookstate({ local: '', query: '' }) | ||
const searchTimeout = useRef<ReturnType<typeof setTimeout> | null>(null) | ||
const shelves = usePrefabShelfCategories(search.query.value) | ||
const shelveslist: string[] = [] | ||
shelves.map(([category, items]) => { | ||
shelveslist.push(category) | ||
}) | ||
|
||
const onSearch = (text: string) => { | ||
search.local.set(text) | ||
if (searchTimeout.current) clearTimeout(searchTimeout.current) | ||
searchTimeout.current = setTimeout(() => { | ||
search.query.set(text) | ||
}, 50) | ||
} | ||
|
||
return ( | ||
<List | ||
sx={{ width: 300, height: 900, bgcolor: 'var(--dockBackground)' }} | ||
subheader={ | ||
<div style={{ padding: '0.5rem' }}> | ||
<Typography style={{ color: 'var(--textColor)', textAlign: 'center', textTransform: 'uppercase' }}> | ||
{t('editor:layout.assetGrid.prefab')} | ||
</Typography> | ||
<InputText | ||
placeholder={t('editor:layout.assetGrid.prefab-search')} | ||
value={search.local.value} | ||
sx={{ mt: 1 }} | ||
onChange={(e) => onSearch(e.target.value)} | ||
/> | ||
</div> | ||
} | ||
> | ||
<ScenePrefabListItem categoryItems={shelveslist} isCollapsed={!!search.query.value} /> | ||
</List> | ||
) | ||
} | ||
|
||
export default PrefabList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should change the language here for Add Entity in simple mode to Add Object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lines mean if user select Advanced mode the studio will be same.
When select simple mode the fuctions of add object are in PrefabList.tsx which was called in HierarchyPanelContainer.tsx line 523.