Events System
The toolkit has a few ways to make things happen when you interact with objects. You can play sounds, spawn effects, or load new scenes.
There are two main ways to do this:
- The Central Way (Logic Window). This is best for gameplay rules. It keeps everything in one spot so you dont have to hunt through every object to find your events.
- The Local Way (Components). This is good for quick, simple stuff on just one object.
The Central Way: Logic Window
This is the best way to handle events for your game. Instead of adding components to every single chair or table, you manage everything from one window. This stops your objects from getting a huge stack of components that are hard to manage.
[VIDEO: Show opening the Logic Window and adding a simple rule to a group of objects] Video description: Show clicking Tools, then DecoratingToolkit, then Logic Window. Select a few objects in the scene and add a DragStarted rule to them.
You can find this at Tools, then DecoratingToolkit, then Logic Window.
When you add a rule here, it gets saved to the SceneLogic object in your scene. You can see all your rules in a list and change them whenever you want. This keeps the logic in a central place.
See the Simple Logic page for more details on how to use it.
The Local Way: Components
If you just have one thing that needs a hover effect or a click sound, you can use these components.
Hover Feedback
Add HoverUnityEventFeedback to an object if you want it to react when the mouse moves over it. It gives you two spots to hook up events: * On Hover Enter: When the mouse starts touching the object. * On Hover Exit: When the mouse leaves the object.
[IMAGE: HoverUnityEventFeedback component in the inspector] Image description: A screenshot of the HoverUnityEventFeedback component showing the UnityEvents for Enter and Exit.
Click Feedback
Add UnityEventInteractable to handle clicks. * On Primary Interact: Usually the left mouse button. * On Secondary Interact: Usually the right mouse button.
[IMAGE: UnityEventInteractable component in the inspector] Image description: A screenshot of the UnityEventInteractable component showing the Primary and Secondary interact events.
The Global Way: Event Relay
Sometimes you want something to happen every time any object is moved or clicked. For example, if you want a UI message to show up whenever you start dragging something.
The DecoratingEventRelay is a central hub. You put it in your scene and link it to your controller. Then, other scripts can listen to it to know what is happening in the whole system.
[IMAGE: DecoratingEventRelay on a GameObject and linked to the Controller] Image description: Show a SceneLogic or a separate object with the DecoratingEventRelay component. Show it being assigned to the Event Relay field on the PlayerDecoratingController.
What it can tell you
The relay can broadcast these events for everything in the scene: * When an object is hovered or unhovered. * When an object is clicked (Primary or Secondary). * When you start or stop dragging. * When you move or rotate an object. * When the placement validity changes (like if an object is stuck in a wall).
For Coders: Interfaces
If you are writing your own scripts, you can implement these interfaces to get direct control.
IHoverable
Use this to make an object react to the mouse hovering over it.
public interface IHoverable
{
bool CanHover(in InteractionContext context);
void HoverEnter(in InteractionContext context);
void HoverExit(in InteractionContext context);
}
IInteractable
Use this for custom logic when an object is clicked.
public interface IInteractable
{
bool CanInteract(in InteractionContext context);
InteractionResult PrimaryInteract(in InteractionContext context);
InteractionResult SecondaryInteract(in InteractionContext context);
}
Note: If you use ObjectLogic (which is what the Logic Window uses), it already handles IInteractable. You should not stack it with UnityEventInteractable on the same object because you dont want the user to navigate through the list of components. The controller picks the first one it finds.