Sometimes it may be useful to listen to object transform events that are fired for a specific object. RLD uses the IRTTransformGizmoListener interface for this purpose.

The following gizmos recognize this interface:

  • Move Gizmo;
  • Rotation Gizmo;
  • Scale Gizmo;
  • Box Scale Gizmo;
  • Universal Gizmo;

The IRTTransformGizmoListener is defined like so:

public interface IRTTransformGizmoListener
{   
    bool OnCanBeTransformed(Gizmo transformGizmo);
    void OnTransformed(Gizmo transformGizmo);
}
bool OnCanBeTransformed(Gizmo transformGizmo);

This function is called before an object is about to be transformed and it can be used as a means to restrict certain objects from being transformed. If the function returns true, the object can be transformed. Otherwise, no transform will be applied to the object. The frunction accepts the reference to the gizmo which is about to transform the object.

void OnTransformed(Gizmo transformGizmo);

This function is called after the object has been transformed. The frunction accepts the reference to the gizmo which was used to transform the object.

Implementing the Interface

Here is an example of you can implement the IRTTransformGizmoListener interface:

// Note: Must always derive from MonoBehaviour
public class MyTransformGizmoListener : MonoBehaviour, IRTTransformGizmoListener
{
    public bool OnCanBeTransformed(Gizmo transformGizmo)
    {
        // Only transform the object if the gizmo is changing its position or rotation.
        // Ignore scale.
        return transformGizmo.ActiveDragChannel == GizmoDragChannel.Offset || 
               trasnformGizmo.ActiveDragChannel == GizmoDragChannel.Rotation;

        /* Other examples:
        return true;                                    // Always trasnform the object
        return gameObject.name != "NonTransformable";   // Only transform if the name is NOT "NonTransformable"
        return gameObject.layer != 0;                   // Only transform if the object layer is not the default layer
        // Or any other condition that needs to be met :)
        */      
    }

    public void OnTransformed(Gizmo transformGizmo)
    {
        // Write code to be executed after the object was transformed
    }
}

In order for the interface to actually be used, you need to attach it to a game object. It would actually be a good idea to attach it to a prefab instead. That way, all objects which will be spawned from that prefab will have the script attached automatically.