I am using Unity3D for this question, but this is a general software engineering question.
Entities (interactive objects) in Unity3D are built with components or behaviors. By putting together behaviors together, you define the exact behavior of the object.
I am pondering how to have different objects react differently, when clicked, based a global state. For example, I have a tool that targets only affect circles in the scene; if I select that tool, and click on an object, and if it is a circle I will change it to a square. If it is not a circle, I will just ignore it.
Using the component-based entity design, I would define a behavior called IsCircle, and when it is clicked, I will check whether what should happen to it. However, what is the best way for it to access the global state of the entire application? Let's say I wish to avoid any switch, if-else and want the solution to be decoupled
(The problem is that the OnMouseDown() event handler does not pass in any parameters).
I would appreciate if the answer keeps in mind the environment I am using enforces the composite pattern.