How To Create Plugins/Creating Components

From Resonite Wiki
Revision as of 15:16, 15 July 2024 by Paradox19 (talk | contribs) (creating_components page is done! i think i need a break.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Creating components is one of the easiest part of making a plugin.

Creating the component file

  1. Add references to
    • FrooxEngine
    • Elements.Core
  2. 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 namespace FrooxEngine.MyPlugin (where MyPlugin is your plugin's custom namespace, of course.)
    • If you already have a namespace set up, use that!
  3. 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" })]

Creating the component class

  1. 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
  2. Create your variables
    • These go immediately after you start the class and follow a few rules to show up in the in game inspector:
      • They need to be public
      • They need to be readonly
    • If you're creating a value, the data must be of type Sync<T> where T is your type.
    • If you're creating a reference, the data must be of type SyncRef<T> where T is your type.
    • Do not assign default values. These should be assigned in OnAttach()
    • Examples:
      • public readonly SyncRef<Slot> MySlotReference;
      • public readonly Sync<bool> MyBoolValue;

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.