Wraping input in events

I have been wrapping input recognition in events for quite some time. The main reason was that I had to process the mouse data quite heavily and I decided to do it once for all instances instead of making each instance do its own calculations. In that case it seems obvious to me that events are going to be more efficient, but now I wonder if they can improve code more generally.

The idea is:

public class Events : MonoBehaviour
{
	public event Action KeyA;
	public event Action<Vector3> TouchUp;

	Events() {}

	public static Events Instance {get; private set;}

	void Start() {
		Instance = this;
	}

	void Update() {
		if (Input.GetKey(KeyCode.A)) 
			if (KeyA != null) 
				KeyA();

		if (Input.GetMouseButtonUp(0))
			if (TouchUp != null)
				TouchUp(Input.mousePosition);
	}
}

So what do you think? Is this a good or bad practice? I am thinking of performance, architecture, readability… I imagine Update is very heavily optimized in Unity so maybe this event madness of mine is just not worth it.

As far as the performance on device is concerned I don’t think it will affect much of it.

But if you consider the efficiency of coding efforts then this architecture would be a preferred way since you are creating a controller to handle the input events which provides you with a flexibility to handle the structure of your code in much simpler way.

In long run it will certainly help you with the working efficiently when you need to make the update to your code wherein since you have a structured code it will allow you to work efficiently. You now don’t have to hunt down through each update loop to find the code that handles each event separately and update them each time a small change is required.

Plus this also gives you a reusable script that allows you to leverage the code re-use which is one another positive aspect of it.