Class ComponentBase

Inheritance Relationships

Derived Types

Class Documentation

class ComponentBase

The base class for all components, provides mechanisms for dirtying properties and subscribing to events on property changes.

Subclassed by csp::multiplayer::AnimatedModelSpaceComponent, csp::multiplayer::AudioSpaceComponent, csp::multiplayer::AvatarSpaceComponent, csp::multiplayer::ButtonSpaceComponent, csp::multiplayer::CinematicCameraSpaceComponent, csp::multiplayer::CollisionSpaceComponent, csp::multiplayer::ConversationSpaceComponent, csp::multiplayer::CustomSpaceComponent, csp::multiplayer::ECommerceSpaceComponent, csp::multiplayer::ExternalLinkSpaceComponent, csp::multiplayer::FiducialMarkerSpaceComponent, csp::multiplayer::FogSpaceComponent, csp::multiplayer::GaussianSplatSpaceComponent, csp::multiplayer::HotspotSpaceComponent, csp::multiplayer::ImageSpaceComponent, csp::multiplayer::LightSpaceComponent, csp::multiplayer::PortalSpaceComponent, csp::multiplayer::ReflectionSpaceComponent, csp::multiplayer::ScriptSpaceComponent, csp::multiplayer::SplineSpaceComponent, csp::multiplayer::StaticModelSpaceComponent, csp::multiplayer::TextSpaceComponent, csp::multiplayer::VideoPlayerSpaceComponent

Public Types

typedef std::function<void(ComponentBase*, const csp::common::String&, const csp::common::String&)> EntityActionHandler

A callback that can be registered to be called when an action of a given name is invoked.

Contains a pointer to the component, the action name as a string and parameters as a string.

Public Functions

virtual ~ComponentBase()

Virtual destructor for the component.

uint16_t GetId()

Get the ID for this component.

This is set when calling SpaceEntity::AddComponent and is autogenerated with the intention of being unique within the context of the entity it is attached to.

Returns

The ID.

ComponentType GetComponentType()

Get the ComponentType of the component.

Returns

The type of the component as an enum.

const csp::common::Map<uint32_t, ReplicatedValue> *GetProperties()

Get a map of the replicated values defined for this component.

The index of the map represents a unique index for the property, intended to be defined in the inherited component as an enum of available properties keys.

Returns

A map of the replicated values, keyed by their unique key.

SpaceEntity *GetParent()

Get the parent SpaceEntity for this component.

Components can only attach to one parent.

Returns

A pointer to the parent SpaceEntity.

void SubscribeToPropertyChange(uint32_t PropertyKey, csp::common::String Message)

Part of the scripting interface, allows you to subscribe to a property change and assign a script message to execute when activated.

Parameters
  • PropertyKey – uint32_t : The key of the property to subscribe to.

  • Messagecsp::common::String : The message to be sent to the script.

void RegisterActionHandler(const csp::common::String &InAction, EntityActionHandler ActionHandler)

Register an action handler callback to be called when the given action is invoked.

Parameters
  • InActioncsp::common::String : The identifying name of the action.

  • ActionHandler – EntityActionHandler : Callback to be called when the action is invoked, contains a pointer to this component, the name of the action and a string of parameters for the action.

void UnregisterActionHandler(const csp::common::String &InAction)

Removes the action handler callback for the given action.

Parameters

InActioncsp::common::String : The identifying name of the action.

void InvokeAction(const csp::common::String &InAction, const csp::common::String &InActionParams)

Calls the registered action handler callback for the given action and passes the given parameters.

Parameters
  • InActioncsp::common::String : The identifying name of the action.

  • InActionParamscsp::common::String : Parameters for the action that will be passed to the action handler callback.

const csp::common::String &GetComponentName() const

Gets the name of the component.

void SetComponentName(const csp::common::String &Value)

Sets the name for the component.

Parameters

Value – - The new name to assign to the componenent.

Protected Functions

ComponentBase()
ComponentBase(ComponentType Type, SpaceEntity *Parent)
const ReplicatedValue &GetProperty(uint32_t Key) const
const bool GetBooleanProperty(uint32_t Key) const
const int64_t GetIntegerProperty(uint32_t Key) const
const float GetFloatProperty(uint32_t Key) const
const csp::common::String &GetStringProperty(uint32_t Key) const
const csp::common::Vector2 &GetVector2Property(uint32_t Key) const
const csp::common::Vector3 &GetVector3Property(uint32_t Key) const
const csp::common::Vector4 &GetVector4Property(uint32_t Key) const
const csp::common::Map<csp::common::String, ReplicatedValue> &GetStringMapProperty(uint32_t Key) const
void SetProperty(uint32_t Key, const ReplicatedValue &Value)
void RemoveProperty(uint32_t Key)
void SetProperties(const csp::common::Map<uint32_t, ReplicatedValue> &Value)
virtual void SetPropertyFromPatch(uint32_t Key, const ReplicatedValue &Value)
virtual void OnRemove()
virtual void OnLocalDelete()
void SetScriptInterface(ComponentScriptInterface *ScriptInterface)
ComponentScriptInterface *GetScriptInterface()

Protected Attributes

SpaceEntity *Parent
uint16_t Id
ComponentType Type
csp::common::Map<uint32_t, ReplicatedValue> Properties
csp::common::Map<uint32_t, ReplicatedValue> DirtyProperties
ComponentScriptInterface *ScriptInterface
csp::common::Map<csp::common::String, EntityActionHandler> ActionMap