Hi all,
I am trying to do a couple of Components on my GameObjects to communicate using the UI Event System (ExecuteEvents.Execute(…)).
Now I’m having trouble understanding when the events are actually firing.
I was hoping that the order of the Components in the Inspector was the actual order of execution, but it ain’t so.
If I have a Component A that fires an IMyNiceEventHandler : IEventSystemHandler interface event, and there is a Component B and a Component C that implement it, how can I make sure that Component B is executed before Component C, or (if I want it) Component C before Component B, just on that specific GameObject?
Basically I want to have a pool of Behaviours that can be applied AFTER a certain event happened. For example, if the event handler was
public interface IWaterEnteredHandler : IEventSystemHandler
{
void OnWaterEntered();
}
Then my main component would be
public class MyClass: MonoBehaviour
{
public void Update()
{
if(Input.GetMouseDown(0))
{
EventSystems.Execute<IWaterEnteredHandler>(gameObject, null, (x, y) => x.OnWaterEntered());
}
}
}
I want the following components
public class Drown : MonoBehaviour, IEnteredWaterEventHandler { ... }
public class Swim : MonoBehaviour, IEnteredWaterEventHandler { ... }
public class Walk: MonoBehaviour, IEnteredWaterEventHandler { ... }
public class GetsWet: MonoBehaviour, IEnteredWaterEventHandler { ... }
But if I have, for some reason, both Components on the same GameObject, I want to be able to say that Swim overrides Drown, or Walk overrides Swim or Drown. AND I want that GetsWet coexists with all three other components. So basically, if the character can swim, he doesn’t drown, and if he can walk, he doesn’t swim. But if he hits the water, he gets wet regardless.
If the component order was clear, it would be easy. Then GetsWet would come first. Then Walk, which would set all other IEnteredWaterEventHandlers to enabled = false. Then the rest wouldn’t even receive the event.
Thanks for your patience,
Wavy