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

The interface is defined as follows:

public interface IRTObjectSelectionListener
{   
    bool OnCanBeSelected(ObjectSelectEventArgs selectArgs);
    void OnSelected(ObjectSelectEventArgs selectArgs);
    void OnDeselected(ObjectDeselectEventArgs deselectArgs);
}
bool OnCanBeSelected(ObjectSelectEventArgs selectArgs);

Called by the selection module when the object is about to be selected. If the object wants to be selected, then this function should return true. Otherwise, it should return false.

void OnSelected(ObjectSelectEventArgs selectArgs);

Called by the selection module after the object has been selected.

void OnDeselected(ObjectDeselectEventArgs deselectArgs);

Called by the selection module after the object has been deselected.

All these functions receieve an instance of either ObjectSelectEventArgs or ObjectDeselectEventArgs. These are defined like so:

public class ObjectSelectEventArgs
{
    public ObjectSelectReason SelectReason;
}

public class ObjectDeselectEventArgs
{
    public ObjectDeselectReason DeselectReason;
}

As you can see each class is used to simply inform the object about the select/deselect reasons. Please see Object Select/Deselect Reasons for more details.

Implementing the Interface

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

// Note: Must always derive from MonoBehaviour
public class MyObjectSelectionListener : MonoBehaviour, IRTObjectSelectionListener
{
    public bool OnCanBeSelected(ObjectSelectEventArgs selectArgs)
    {   
        // Only select the object if the object was selected via a left click
        return selectArgs.SelectReason == ObjectSelectReason.Click;
    }

    public void OnSelected(ObjectSelectEventArgs selectArgs)
    {
        // Write code to be executed after the object was selected
    }

    public void OnSelected(ObjectDeselectEventArgs deselectArgs)
    {
        // Write code to be executed after the object was deselected
    }
}

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.