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 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. |