So I wanted to get some opinions on how I'm going about using events to control two classes from a button UI click. I don't feel its entirely "right" as in the sense it's breaking some SOLID rules. I don't believe the button itself should be checking if an allocation can happen, and adding instances of the Subsystem and WarpCore classes to it seem wrong too, just unsure of a better way.
using UnityEngine;
using System;
using System.Collections;
public class ControlButton : MonoBehaviour
{
private EventButton eventButton = null;
private Subsystem subsystem = null;
private WarpCore warpCore = null;
public void Initialize(Subsystem subsystem, WarpCore warpCore)
{
eventButton = this.gameObject.ValidateComponent<EventButton>();
eventButton.onLeftClick += Allocate;
eventButton.onRightClick += Deallocate;
this.subsystem = subsystem;
this.warpCore = warpCore;
}
private void Allocate(object sender, EventArgs e)
{
if (warpCore.CanAllocate() == true && subsystem.CanAllocate() == true)
{
warpCore.Allocate(subsystem);
subsystem.Allocate();
}
}
private void Deallocate(object sender, EventArgs e)
{
// TODO: Remove the allocation from the subsystem and free up an allocation on the warp core.
}
}