| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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<TrainEventType, TrainEvent> m_TrainEvents = new Dictionary<TrainEventType, TrainEvent>();
- 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;
- }
- }
- }
- }
|