UI Editors

Overview

This section outlines the development of custom UI elements for game object properties and settings in the OGLR project.

The goal is to provide a flexible and extensible framework for creating user interfaces that are tailored to the specific needs of different game objects and their properties.

Core Concepts

  • Editor Interface: Provides a consistent interface for editing game objects and their properties.
  • Property Editors: Responsible for displaying and editing specific types of properties. These editors can be custom-built to handle different data types and user interactions.
  • Property Binding: Establishes a connection between UI elements and the underlying game object properties. Changes to the UI elements directly update the corresponding properties, and vice versa.

Implementation

Property Editors

  • Base Editor: The foundation for all property editors.
  • Property Editor Interface: Defines the interface that all property editors must implement.
  • Standard Property Editors: Provide default implementations for common data types.
    • String Editor: Edits string values.
    • Integer Editor: Edits integer values.
    • Float Editor: Edits floating-point values.
    • Boolean Editor: Edits boolean values.
    • Color Editor: Edits color values.
    • Vector Editor: Edits vector values.
  • Custom Property Editors: Developed for specialized property types that require unique UI elements or behavior.

Example:

//  A custom property editor for a "Health" property.
          class HealthEditor : public PropertyEditor 
          {
          public:
              virtual void OnGUI() override; 
              virtual void Bind(Property& property) override; 
          private:
              float healthValue; 
          };
          
          //  Implementation of OnGUI()
          void HealthEditor::OnGUI()
          {
              healthValue = EditorGUI.Slider(healthValue, 0.0f, 100.0f);
              //  Update the bound property with the new healthValue
          }
          
          //  Implementation of Bind()
          void HealthEditor::Bind(Property& property)
          {
              //  Bind the "healthValue" member variable to the given property.
              property.BindValue(healthValue); 
          }
          

Property Binding

The Property class manages the connection between UI elements and game object properties.

Example:

// Create a new property.
          Property healthProperty = Property("Health");
          
          // Create a HealthEditor and bind it to the property.
          HealthEditor healthEditor = HealthEditor();
          healthEditor.Bind(healthProperty); 
          
          // Update the property value through the UI element.
          healthEditor.healthValue = 50.0f; 
          
          // Access the updated value from the property.
          float health = healthProperty.GetValue<float>(); // health will be 50.0f
          

Customization

Creating Custom Property Editors

Developers can create custom property editors to handle unique property types.

  • Inherit from the PropertyEditor class.
  • Implement the OnGUI() and Bind() methods.
  • Define the UI elements and logic for editing the specific property type.

Registering Custom Property Editors

To ensure custom property editors are recognized by the system, they must be registered. This registration allows the system to determine the appropriate editor for a given property type.

// Example of registering a custom editor for a property with type "CustomType".
          PropertyEditorManager.RegisterEditor<CustomType>(new CustomTypeEditor()); 
          

Notes

  • The UI Editors are designed to be extensible, allowing for the creation of custom editors for any property type.
  • The system provides a consistent interface for editing game object properties.
  • Property binding ensures that changes made in the UI are reflected in the game object’s properties and vice versa.