Hi!
- Can you elaborate on the trade offs between using a singleton vs using C# events here? Couldn’t this have been done in a more decoupled way via a C# event that the LevelGrid processes, which takes the Unit and its world position?
Is it better to couple the LevelGrid and Unit via the singleton as mentioned here? If writing the game with unit tests, wouldn’t the use of C# events for this functionality also make the code more easily testable?
- I’ve noticed that you tend to opt to store local variables for each call, avoiding method chaining. What’s the reasoning behind this? And is there any performance difference when creating all these extra local variables throughout the code vs using method chaining?
For example:
public void AddUnitAtGridPosition(GridPosition gridPosition, Unit unit)
{
_gridSystem.GetGridObject(gridPosition).AddUnit(unit);
}
VS
public void AddUnitAtGridPosition(GridPosition gridPosition, Unit unit)
{
GridObject gridObject = _gridSystem.GetGridObject(gridPosition);
gridObject.AddUnit(unit);
}