menu_bookDocumentation
GameResource Extensions: Appending Data to Existing Assets Without Modification
ResourceExtensions in s&box append additional data to existing GameResources without modifying the original class or assets. Useful for adding properties to Clothing, Surfaces, Models, etc.
Creating a ResourceExtension
CSHARP
[GameResource("Clothing Extension", "extcloth", "Extra Clothing Stuff", Category = "Citizen", Icon = "iron")]
public class ClothingExtension : ResourceExtension<Clothing, ClothingExtension>
{
public string CustomName { get; set; }
public string CustomCategory { get; set; } = "Other";
public int CostToUnlock { get; set; } = 100;
}The first generic parameter is the resource being extended.
Extending Assets
Create the extension asset, set values, then use the "Extends" tab to specify which assets it applies to. Enable "Default" to return this extension for any asset without a specific one.Accessing Extensions
CSHARP
// Returns default if no specific extension exists
var ext = ClothingExtension.FindForResourceOrDefault( PlayerHat );
// Returns null if no extension exists
var ext = ClothingExtension.FindForResource( PlayerHat );
// Returns all extensions targeting the resource
var all = ClothingExtension.FindAllForResource( PlayerHat );
// Returns the default extension
var def = ClothingExtension.FindDefault();
Was this helpful?