How To Create Plugins/Creating Components: Difference between revisions

From Resonite Wiki
reword for clarification
m fix typo
 
Line 20: Line 20:
#** It must be public
#** It must be public
#** It must be readonly
#** 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>.
#** It must be a [[How_To_Create_Plugins#Variable_types_relevant_for_Components|synced equivalent]] of your original type. Such as <code>Sync<T></code>.
#* If you do not want your variable to show up in game:
#* If you do not want your variable to show up in game:
#** It should be private
#** It should be private

Latest revision as of 15:43, 17 July 2024

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:
      • 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;

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.