As we are going to see, the Facade pattern is straightforward, so we will keep the following code example simple and straight to the point. To start, we will write the classes for each of the core components that make up the bike's engine, as follows:
- We will start with the fuel pump; the purpose of this component is to simulate the consumption of fuel so that it knows the amount remaining and shuts down the engine when it runs out. Here's the code you'll need:
using UnityEngine;
using System.Collections;
namespace Chapter.Facade
{
public class FuelPump : MonoBehaviour
{
public BikeEngine engine;
public IEnumerator burnFuel;
void Start()
{
burnFuel = BurnFuel();
}
IEnumerator BurnFuel()
{
while (true)
{
yield return new WaitForSeconds(1);
engine.fuelAmount -= engine.burnRate;
if (engine.fuelAmount <=...