What is a GizmoBehaviour?

In RLD all gizmos are implemented using a component based model. A gizmo is defined by the Gizmo class and instances of this class can have gizmo behaviours attached to them to define the behaviour of the gizmo. You can think of the Gizmo class as the equivalent of Unity's GameObject class. The GizmoBehaviour is the equaivalent of MonoBehaviour.

A Simple Example

The following code creates a gizmo instance and then it creates 2 gizmo behaviours (MoveGizmo and ObjectTransformGizmo) to make the gizmo behave like a move gizmo that can be used to transform objects.

Gizmo gizmo = RTGizmoEngine.Get.CreateGizmo();
MoveGizmo moveGizmoBhv = gizmo.AddBehaviour<MoveGizmo>();
ObjectTransformGizmo transformGizmoBhv = gizmo.AddBehaviour<ObjectTransformGizmo>();

In the example above, the MoveGizmo and ObjectTransformGizmo behaviours derive from the GizmoBehaviour class.

Available Gizmo Behaviours in RLD

In RLD the following gizmo behaviours exist:

  • MoveGizmo;
  • RotationGizmo;
  • ScaleGizmo;
  • BoxGizmo;
  • UniversalGizmo;
  • ObjectTransformGizmo;
  • ObjectExtrudeGizmo;
  • SceneGizmo;

Accessing Behaviours

The following examples show you how you can access a gizmo's behaviours:

// Retrieve all behaviours of of type MyCustomBehaviour
var behaviours = gizmo.GetBehavioursOfType<MyCustomBehaviour>();

// Retrieve the first behaviour of type MyCustomBehaviour
var firstBHVOfType = gizmo.GetFirstBehaviourOfType<MyCustomBehaviour>();
// OR
var firstBHVOfType = gizmo.GetFirstBehaviourOfType(typeof(MyCustomBehaviour));

However, it is actually much simpler to use the predefined properties inside the Gizmo class. Whenever a behaviour is added to a gizmo, the gizmo will cache a reference to that behaviour so that it can easily be accessed later. This is the recommended way of accessing gizmo behaviours.

MoveGizmo moveGizmoBhv = gizmo.MoveGizmo;
RotationGizmo rotationGizmoBhv = gizmo.RotationGizmo;
ScaleGizmo scaleGizmoBhv = gizmo.ScaleGizmo;
UniversalGizmo universalGizmoBhv = gizmo.UniversalGizmo;
ObjectTransformGizmo objectTransformGizmoBhv = gizmo.ObjectTransformGizmo;
BoxGizmo boxGizmoBhv = gizmo.BoxGizmo;
ObjectEctrudeGizmo objectExtrudeGizmo = gizmo.ObjectExtrudeGizmo;
SceneGizmo sceneGizmoBhv = gizmo.SceneGizmo;