Skip to content

Components

Robin van Ee edited this page Jan 22, 2023 · 3 revisions

Explanation

WolfRPG.Core stores data using an object-component model. Objects are generic containers that store components, and components store data. Every component must be a class inheriting from the IRPGComponent interface.

Both public and private fields and properties are supported.

After creating a class (and compiling, make sure the project compiles!), WolfRPG will automatically detect the component and you will be able to add it to objects.

Examples

Basic components

public class BasicComponent : IRPGComponent
{
    public string MyString { get; set; }
    public int MyInt { get; set; }
}

image

Unity types

WolfRPG supports all types that can be serialized in the Unity inspector

public class CharacterProgression : IRPGComponent
{
    public int BaseLevel { get; set; }
    public AnimationCurve XPCurve { get; set; }
}

image

Referencing Unity assets

The AssetReference type and AssetReferenceAttribute are used to reference assets in WolfRPG. These assets must be marked as Addressable in order to be included.

public class UnityAssets : IRPGComponent
{
    [AssetReference(typeof(Sprite))]
    public AssetReference MySprite { get; set; }
	
    [AssetReference(typeof(GameObject))]
    public AssetReference MyPrefab { get; set; }
}

image