TypeSelect

Library

A editor tool that adds a [TypeSelector] attribute, enabling easy selection of inherited types in the inspector.

thedimin updated 1y ago 0 MB engine 17
thumb_up 2 open_in_new View on sbox.game
TypeSelect

About

Type select adds `[TypeSelector]` attribute putting this on a property will allow you to select an inherited type in the editor as shown here:

sbox-dev_ks2OJhqbwf.mp4 148.51 KB


WARNING

to make sure your types get serialized correctly you need to make use of the `[JsonPolymorphic]` and `[JsonDerivedType]` attributes. 
And for the latter make sure to set a typeDiscirimnator or it wil not work !!!!



EXAMPLE CODE


[GameResource( "Quest", "quest", "A quest given to the user !", Category = "quest" )]
public class Quest : GameResource
{
    [Property,InlineEditor,TypeSelector] public TaskBase Task { get; set; }
}

//The two attributes here are from .net

[JsonPolymorphic] 
[JsonDerivedType( typeof(Collect), "Collect" )] // Yeah you have to do this for every type. blame C#, not me.
public abstract class TaskBase //Because this class is abstract it will not showup in the menu.
{
   [Property] public string QuestName {get;set};// all types will show this
}

public class Collect : TaskBase
{
   [Property] public int AmountToCollect {get;set;}
}

public class TalkTo : TaskBase
{
   [Property] public GameObject Target {get;set;}
}

TODO

   ☐ Search functionality in the menu
No usage statistics available
This package may be new or not widely used yet. Usage data becomes available as more users install and play with the package.
0 recorded entries
Rank Player Score Recorded
refresh
Discovering package leaderboards...
Package ID: thedimin.typeselect
Created: 2025-03-17 10:29 UTC
Updated: 2025-03-17 10:50 UTC
Type: library
Public: Yes
Version: 92351
files: 6
Size: 0.0 MB
Engine Version: 17
Asset Version ID: 92351
Version Created: 2025-03-17 10:50 UTC
Hash: 6948468691826709497
Manifest: Open manifest
new_releases Latest Update Mar 17, 2025
Removed unused code & logging
92351 Mar 17, 2025
Removed unused code & logging
92350 Mar 17, 2025
Small code cleanup
92349 Mar 17, 2025
Initial Release of TypeSelect
info Live API Passthrough & Removal Notice

This file manifest and asset metadata are retrieved live directly from the official Facepunch s&box public API. s&box Explorer does not host, store, or redistribute any package files. All download links route directly to Facepunch CDN servers.