m broken link |
dont specify sync types, leave it up to the user to decide |
||
Line 18: | Line 18: | ||
# 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|synced equivelent]] of your original type. Such as <code>Sync<T></code>. | ||
#* If you | #* If you do not want your variable to show up in game: | ||
#* | #** It should be private | ||
#** It should not be tagged as <code>readonly</code> | |||
#** It does not need to be a [[How_To_Create_Plugins#Variable_types_relevant_for_Components|synced type]]. | |||
#* '''Do not assign default values.''' These should be assigned in <code>OnAttach()</code> | #* '''Do not assign default values.''' These should be assigned in <code>OnAttach()</code> | ||
#* Examples: | #* Examples: |
Revision as of 17:02, 16 July 2024
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.
- If this is your first component, you can make up a namespace! Just ensure it starts with
FrooxEngine
. If you want to be extra sure that your plugin does not conflict with others, make your namespaceFrooxEngine.MyPlugin
(whereMyPlugin
is your plugin's custom namespace, of course.) - If you already have a namespace set up, use that!
- If this is your first component, you can make up a namespace! Just ensure it starts with
- Set your category, this is where your component is placed in the browser.
- This is done by adding a
[Category(new string [] { "PATH" })]
before your component class. - Some examples:
[Category(new string [] { "MyPlugin/Transform" })]
[Category(new string [] { "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 equivelent 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 should not be tagged as
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. |