How To Create Plugins/Creating Components: Difference between revisions

From Resonite Wiki
creating_components page is done! i think i need a break.
 
add distinction for private variables
Line 22: Line 22:
#* If you're creating a value, the data must be of type <code><nowiki>Sync<T></nowiki></code> where <code>T</code> is your type.
#* If you're creating a value, the data must be of type <code><nowiki>Sync<T></nowiki></code> where <code>T</code> is your type.
#* If you're creating a reference, the data must be of type <code><nowiki>SyncRef<T></nowiki></code> where <code>T</code> is your type.
#* If you're creating a reference, the data must be of type <code><nowiki>SyncRef<T></nowiki></code> where <code>T</code> is your type.
#* ''Private variables do not need to be <code>readonly</code> and so can be of any 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:
#** <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 ==

Revision as of 16:15, 15 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:
      • 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.
    • Private variables do not need to be readonly and so can be of any 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.