creating_components page is done! i think i need a break. |
not all variable types are synced, such as raw output & add citation needed for *why* default values are assigned in OnAttach rather than the variable reference |
||
(7 intermediate revisions by the same user not shown) | |||
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 | ||
Line 18: | Line 16: | ||
# Create your variables | # Create your variables | ||
#* These go immediately after you start the class and follow a few rules to show up in the in game inspector: | #* 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 [[How_To_Create_Plugins#Variable_types_relevant_for_Components|FrooxEngine generic type]]{{Citation needed}} wrapping your original type. Such as <code>Sync<T></code>. | ||
#* If you | #* If you do not want your variable to show up in game: | ||
#* '''Do not assign default values.''' These should be assigned in <code>OnAttach()</code> | #** It should be private | ||
#** It does not need to be <code>readonly</code> | |||
#** It does not need to be a [[How_To_Create_Plugins#Variable_types_relevant_for_Components|FrooxEngine generic type]]{{Citation needed}}. | |||
#* '''Do not assign default values.''' These should be assigned in <code>OnAttach()</code>{{Citation needed}} | |||
#* Examples: | #* Examples: | ||
#** <code><nowiki>public readonly SyncRef<Slot> MySlotReference;</nowiki></code> | #** <code><nowiki>public readonly SyncRef<Slot> MySlotReference;</nowiki></code> | ||
#** <code><nowiki>public readonly Sync<bool> MyBoolValue;</nowiki></code> | #** <code><nowiki>public readonly Sync<bool> MyBoolValue;</nowiki></code> | ||
#** <code><nowiki>private bool AnInternalValue;</nowiki></code> | |||
== Adding functionality == | == Adding functionality == | ||
FrooxEngine has many events you can hook your functionality into, to do this you need to add a <code>protected override</code> to each of these. Do not return any values. | FrooxEngine has many events you can hook your functionality into, to do this you need to add a <code>protected override</code> to each of these. Do not return any values. | ||
You can see a full list of functions at [[ | You can see a full list of functions at [[How_To_Create_Plugins/Custom_Components|Custom Components]] | ||
For this guide, we'll focus on the basics | For this guide, we'll focus on the basics |
Latest revision as of 09:11, 3 April 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 FrooxEngine generic type[Citation needed] wrapping 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 FrooxEngine generic type[Citation needed].
- Do not assign default values. These should be assigned in
OnAttach()
[Citation needed] - 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. |