Using Custom Types in the Editor

SunBurn 2.0.11 was just released and now the new editor features are available. A more complex feature is custom type support for the editor. This blog covers how to get your custom types or components to show up in-editor and how to control how they are displayed.

Getting Started

To get a custom type into the editor, it should first have a default constructor and derive from SceneEntity/SceneObject or implement IEditorCreatedObject<SceneEntity>. Secondly, the class must have the EditorCreatedObject attribute applied to it, which tells the editor that the object can be created. Lastly, you must add the Serializable attribute and override GetObjectData/SetObjectData to serialize your type's properties when the editor saves/loads objects.

Types inheriting from SceneEntity do not have models and are not rendered (except for the editor gizmo), so they should be used for markers, waypoints, etc. Types inheriting from SceneObject do have models/meshes and will render if assigned one. The editor will automatically recognize this (and other types implementing the interface IEditorCreatedModelObject) and prompt the user to select a model when added to the scene.

To get a component into the editor, derive from BaseComponentAutoSerialization or BaseComponentManualSerialization and have a default constructor. Then add the Serializable attribute to the class and use SerializeMember attributes on the properties you want saved (AutoSerialization) or override GetObjectData/SetObjectData to serialize your component’s properties (ManualSerialization). An example of an AutoSerialization component can be found in the HDR example.

Controlling Properties

By default, any public properties for the type will be displayed in the editor but this can be controlled through the EditorProperty attribute. This attribute controls if a property is visible, its position in the editor's properties panel and the text description/tooltip

[EditorProperty(true, Description="Description Text", ToolTipText="Hover-Over ToolTip", MajorGrouping=3, MinorGrouping=2, HorizontalAlignment=true)]

Description sets the text that is displayed next to the control. MajorGrouping, MinorGrouping and HorizontalAlignment define the position and orientation of the property’s control. MajorGroups are for organizing related properties and all properties with the same MajorGroup number will go into the same divider panel. The MinorGrouping determines the order of properties within each MajorGroup. With these two options you can control the layout of your properties.

The last option, HorizontalAlignment, determines the position of the description text for a property control, either appearing next to the control (horizontal) or above the control (vertical).

Advanced Options

You can have more advanced options for specific controls through ControlOptions attributes. For example, you can use the EditorNumberPadOptions attribute to define how the numberpad control will behave for floats and integers. Supported control options and their properties are:

  • EditorNumberPadOptions: sets decimal places to display, min value, max value and increment amount for a numberpad.
  • EditorCheckboxOptions: sets return integer value to define whether a checkbox returns true/false or 1/0.
  • EditorDropDownOptions: sets the width for a drop-down box.
  • EditorTextBoxOptions: sets the width and error display for a textbox.
  • EditorEnumDescription: used on enum values to define human-readable descriptions or to ignore the value altogether.

Custom Type Example

Here is an example type that will show up in the editor (in the Content Repository panel), that can be added to the scene (by dragging-dropping onto a Scene Group) and will have its property editable. Note that it has two properties but only one of them is visible to the editor.

[Serializable]
[EditorCreatedObject]
public class MyCustomEntity : SceneEntity
{
    private float _MyValue;

    [EditorProperty(true, Description="My Value", ToolTipText="This is the tooltip")]
    public float MyValue { get { return _MyValue; } set { _MyValue = value; } }


    //This Property will not be displayed in the editor.
    [EditorProperty(false)]
    public bool SomeBoolean { get; set; }


    public override void SetObjectData( SerializationInfo info, StreamingContext c )
    {
        base.SetObjectData( info, c );
        SerializationHelper.DeserializeField( ref _MyValue, info, "MyValue", true );
    }

    public override void GetObjectData( SerializationInfo info, StreamingContext c )
    {
        base.GetObjectData( info, c );
        info.AddValue( "MyValue", _MyValue );
    }
}


Create Your Own Custom Types

Check out these latest features in SunBurn 2.0.11 and we hope they give you the tools you need to expand the editor to suit your needs. As always, any questions are welcome (that's what we are here for). Now create your own custom types and make some amazing scenes!


Posted 02-04-2011 8:16 PM by Ross "FiveSidedBarrel"

Comments

Philippe Da Silva wrote re: Using Custom Types in the Editor
on 02-04-2011 8:29 PM

Thanks Ross for this helpful information.

However, could you add a small note on how we CAN setup the custom type so that it loads a model when we drop it to the scene as otherwise it won't render anything ;)

Ross "FiveSidedBarrel" wrote re: Using Custom Types in the Editor
on 02-04-2011 8:36 PM

Philippe,

Good call, I added some information about the distinction between inheriting from SceneEntity and SceneObject. Basically, inherit from SceneObject if you want to assign a model/mesh to your type and have it renderable.

Philippe Da Silva wrote re: Using Custom Types in the Editor
on 02-04-2011 8:55 PM

So if I want to assign a model, I can't use SceneEntity? Too bad! I need to find a "hack" then to provide Editor support for my Alpha Blended SceneEntities. :(

Ross "FiveSidedBarrel" wrote re: Using Custom Types in the Editor
on 02-04-2011 10:07 PM

Philippe,

Sorry for the confusion, but you can instead use the interfaces.

In your case you can still inherit from SceneEntity then implement IEditorCreatedModelObject and the editor will then prompt you to choose a model.

Philippe Da Silva wrote re: Using Custom Types in the Editor
on 02-04-2011 10:12 PM

Wow! That's great! You'll soon see some stuff from me usig this scheme ;)

Tom wrote re: Using Custom Types in the Editor
on 02-05-2011 11:00 AM

Really nice. I was about to start with my own custom entities. This is a nice introduction for it. I might have a video of it soon, with all the new features...

PixelClover wrote re: Using Custom Types in the Editor
on 02-09-2011 8:56 AM

Very good. but how can we retrieve the values entered in the editor in code?

I don't see an example.

Tom wrote re: Using Custom Types in the Editor
on 02-09-2011 2:44 PM

Btw, this would be a great thing to do more often with new features to the product. It's often a bit vague on how new stuff is supposed to be used/implemented etc. having articles like this would be a great help.

azure77 wrote re: Using Custom Types in the Editor
on 02-17-2011 12:06 PM

I have a question.  How would I inherit from sceneobject and add a BEPU rigidbody.  In order to create this new scene object the rigidbody would require the BEPU physics space.  I can't pass in a parameter in the constructor so I am not sure.  There might be one way of doing it but I am not sure if it is right because I have little experience with Sunburn.  I could include a constructor with no arguments and inside I make use of a static singleton for the physics space.  Is this correct?



Please login to post comments.