m fix typo |
fix incorrect information |
||
Line 4: | Line 4: | ||
#* FrooxEngine | #* FrooxEngine | ||
#* Elements.Core | #* Elements.Core | ||
# Next, assign a namespace to your component. | # Next, assign a namespace to your component. It can be anything but creating a custom one for your plugin is recommended to avoid conflicts. A good example is <code><nowiki>MyPlugin.Components</nowiki></code>. Making the namespace follow the category inside of the game is recommended. | ||
# Set your category, this is where your component is placed in the browser. | # Set your category, this is where your component is placed in the browser. | ||
#* This is done by adding a <code><nowiki>[Category( | #* This is done by adding a <code><nowiki>[Category("PATH")]</nowiki></code> before your component class. | ||
#* Some examples: | #* Some examples: | ||
#** <code><nowiki>[Category( | #** <code><nowiki>[Category("MyPlugin/Transform")]</nowiki></code> | ||
#** <code><nowiki>[Category( | #** <code><nowiki>[Category("MyPlugin/Users")]</nowiki></code> | ||
== Creating the component class == | == Creating the component class == | ||
# Create a new class inside of your namespace | # Create a new class inside of your namespace |
Revision as of 14:59, 28 January 2025
Creating components is one of the easiest part of making a plugin.
Creating the component file
- Add references to
- FrooxEngine
- Elements.Core
- Next, assign a namespace to your component. It can be anything but creating a custom one for your plugin is recommended to avoid conflicts. A good example is
MyPlugin.Components
. Making the namespace follow the category inside of the game is recommended. - Set your category, this is where your component is placed in the browser.
- This is done by adding a
[Category("PATH")]
before your component class. - Some examples:
[Category("MyPlugin/Transform")]
[Category("MyPlugin/Users")]
- This is done by adding a
Creating the component class
- Create a new class inside of your namespace
- It should be a public class which inherits the
Component
class. - So your code should look like:
public class MyComponent : Component
- It should be a public class which inherits the
- Create your variables
- These go immediately after you start the class and follow a few rules to show up in the in game inspector:
- It must be public
- It must be readonly
- It must be a synced equivalent of your original type. Such as
Sync<T>
.
- If you do not want your variable to show up in game:
- It should be private
- It does not need to be
readonly
- It does not need to be a synced type.
- Do not assign default values. These should be assigned in
OnAttach()
- Examples:
public readonly SyncRef<Slot> MySlotReference;
public readonly Sync<bool> MyBoolValue;
private bool AnInternalValue;
- These go immediately after you start the class and follow a few rules to show up in the in game inspector:
Adding functionality
FrooxEngine has many events you can hook your functionality into, to do this you need to add a protected override
to each of these. Do not return any values.
You can see a full list of functions at Custom Components
For this guide, we'll focus on the basics
Function | Description |
---|---|
OnAttach() | Called when the component is attached. If you want any default values, you assign them here. |
OnEnabled() | Called when the component is enabled |
OnDisabled() | Called when the component is disbaled |
OnCommonUpdate() | Called every update, or approximately 60 times per second. |
OnDestroying() | Called just before the component is destroyed. Usually used to unlink drives. |