Urho.Component Class

Base class for components. Components can be attached to scene nodes.

See Also: Component

Syntax

public class Component : Animatable

Remarks

Use the Component is the base class for custom components, it is a low-level interface.   A simpler version to use is LogicComponent which provides various convenience features.   

The next section for details on how to connect to various events in the life cycle of a component.

Events

You can catch the time where the component is attached to a Node by overwriting the Component.OnAttachedToNode method.   To receive Scene update messages, you should first set the Component.ReceiveSceneUpdates property to true on your constructor, and then override the Component.OnUpdate method.

If you are interest in updates from the physics engine, you should connect directly to the PhysicsWorld.PhysicsPreStep event for your world. 

If you are interested in receiving the scene post-update, subscribe to the Scene.ScenePostUpdate event.

Serialization

To implement serialization you would override the OnSerialize and OnDeserialize methods and store your component state on the provided serializer and deserializer objects.

C# Example

class MyComponent : Component { // Constructor needed for deserialization public MyComponent(IntPtr handle) : base(handle) { } public MyComponent() { } // user defined properties (managed state): public Quaternion MyRotation { get; set; } public string MyName { get; set; } public override void OnSerialize(IComponentSerializer ser) { // register our properties with their names as keys using nameof() ser.Serialize(nameof(MyRotation), MyRotation); ser.Serialize(nameof(MyName), MyName); } public override void OnDeserialize(IComponentDeserializer des) { MyRotation = des.Deserialize<Quaternion>(nameof(MyRotation)); MyName = des.Deserialize<string>(nameof(MyName)); } // called when the component is attached to some node public override void OnAttachedToNode() { var node = this.Node; } }

Requirements

Namespace: Urho
Assembly: Urho (in Urho.dll)
Assembly Versions: 1.0.0.0

The members of Urho.Component are listed below.

See Also: Animatable

Public Constructors

Constructs a new instance of Urho.Component which is tied to the Application.CurrentContext.
Constructs a new instance of Urho.Component, given a raw pointer to an unmanaged object
Constructs a new instance of Urho.Component linked to a specific Context.

Protected Constructors

Empty constructor, chain to this constructor when you provide your own constructor that sets the handle field.

Public Properties

[read-only]
ApplicationApplication.
EnabledBoolean. Controls whether the component is enabled or not, additionally, the node might not be enabled, see EnabledEffective for a computation that takes both into account.
[read-only]
EnabledEffectiveBoolean. Return whether is effectively enabled, that is, both the component and its containing Node are enabled.
[read-only]
IDUInt32. Return ID.
[read-only]
NodeNode. Return scene node.
[read-only]
SceneScene. Return the scene the node belongs to.
[read-only]
override
TypeStringHash. Urho's type system type.
[read-only]
override
TypeNameString. Urho's low-level type name.
[read-only]
static
TypeNameStaticString. Urho's low-level type name, accessible as a static method.
[read-only]
static
TypeStaticStringHash. Urho's low-level type, accessible as a static method.

Protected Properties

Public Methods

AddReplicationState(ComponentReplicationState*)
Add a replication state that is tracking this component.
CleanupConnection(Connection)
Clean up all references to a network connection that is about to be removed.
DrawDebugGeometry(DebugRenderer, Boolean)
Visualize the component as debug geometry.
GetComponent(StringHash) : Component
Return component in the same scene node by type. If there are several, returns the first.
GetComponent<T>() : T
override
MarkNetworkUpdate()
Mark for attribute check on the next network update.
OnAttachedToNode(Node)
OnCloned(Scene, Component)
OnDeserialize(IComponentDeserializer)
Overridable method to deserialize the component state
OnNodeSetEnabled()
OnSceneSet(Scene)
OnSerialize(IComponentSerializer)
Overridable method to serialize the component state
OnSetEnabled()
Handle enabled/disabled state change.
PrepareNetworkUpdate()
Prepare network update by comparing attributes and marking replication states dirty as necessary.
Remove()
Remove from the scene node. If no other shared pointer references exist, causes immediate deletion.
override
Save(File) : Boolean
override
Save(MemoryBuffer) : Boolean
override
SaveXml(XmlElement) : Boolean

Protected Methods

override
OnDeleted()
OnUpdate(Single)
Make sure to set the Component.ReceiveSceneUpdates property to true in order to receive update events