Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Add support for prefabs #33

Open
AndrewPrifer opened this issue Nov 15, 2020 · 0 comments
Open

Add support for prefabs #33

AndrewPrifer opened this issue Nov 15, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@AndrewPrifer
Copy link
Owner

AndrewPrifer commented Nov 15, 2020

We could and we should support prefabs with overrides.

I was thinking of the following API:

const MyPrefab = prefab("My Prefab", ReactComponentContainingEditables);
const MyOtherPrefab = prefab("My Other Prefab", SomeOtherReactComponentContainingEditables);
<Canvas>
  <EditableManager prefabs=[MyPrefab, MyOtherPrefab] />
  <MyPrefab uniqueName="Prefab Instance" />
  <MyPrefab uniqueName="Prefab Instance 2" />
</Canvas>

What happens in the above code is that we create prefabs from two r3f React components. These prefabs themselves are also just React components. These are then registered with the EditableManager in the respective Canvases where they are used. From then on, they can be freely used wherever we want inside the Canvas, and a new instance will be created.

When we open the editor, there will be a separate section for prefabs, where they can be opened and edited. Instances in the normal scene editor will reflect changes made to the prefabs, and they themselves will be editable, with all their editable subelements, which will override the respective transform/property. These overrides can be reset or synced back to the prefab.

How does all this work?

When we create a prefab through the prefab() function, a React component is created. When this component is passed to EditableManager, it renders the prefab component in a portal, which lets it be part of the normal React component hierarchy, gaining access to context, while only actually showing it in the prefabs section of the editor, allowing it to be edited, without actually being part of the scene.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant