using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace ShotSimulator.Train { public delegate void TrainEvent(BaseTrainHandle trainHandle); public enum TrainEventType { OnPrepare, OnStartTrain, OnPauseTrain, OnContinueTrain, OnCompleteTrain, OnExitTrain } public class BaseTrainCallBack { private Dictionary m_TrainEvents = new Dictionary(); public void AddTrainCallBack(TrainEventType type, TrainEvent callback) { if (m_TrainEvents.TryGetValue(type, out var trainEvent)) { trainEvent += callback; } else { m_TrainEvents.Add(type, callback); } } public void TriggerTrainEvent(TrainEventType type, BaseTrainHandle handle) { if (m_TrainEvents.TryGetValue(type, out var trainEvent)) { if (trainEvent != null) { trainEvent(handle); } } } public void RemoveTrainCallBack(TrainEventType type, TrainEvent callback) { if (m_TrainEvents.TryGetValue(type, out var trainEvent)) { trainEvent -= callback; } } } }