| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Linq; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.Assertions; |
| | 6 | |
|
| | 7 | | namespace DCL |
| | 8 | | { |
| | 9 | | public class UpdateEventHandler : IUpdateEventHandler |
| | 10 | | { |
| | 11 | | private UpdateDispatcher dispatcher; |
| | 12 | |
|
| 673 | 13 | | public UpdateEventHandler () |
| | 14 | | { |
| 673 | 15 | | var go = new GameObject("_UpdateDispatcher"); |
| 673 | 16 | | dispatcher = go.AddComponent<UpdateDispatcher>(); |
| 673 | 17 | | } |
| | 18 | |
|
| | 19 | | public void AddListener( IUpdateEventHandler.EventType eventType, Action action ) |
| | 20 | | { |
| 3204 | 21 | | Assert.IsTrue( dispatcher != null, $"Dispatcher is null! Listener for event {eventType} couldn't be added!") |
| 3204 | 22 | | dispatcher.eventCollections[eventType].Add(action); |
| 3204 | 23 | | } |
| | 24 | |
|
| | 25 | | public void RemoveListener( IUpdateEventHandler.EventType eventType, Action action ) |
| | 26 | | { |
| 3204 | 27 | | if ( dispatcher == null ) |
| 3183 | 28 | | return; |
| | 29 | |
|
| 21 | 30 | | dispatcher.eventCollections[eventType].Remove(action); |
| 21 | 31 | | } |
| | 32 | |
|
| | 33 | | public void Dispose() |
| | 34 | | { |
| 673 | 35 | | if ( dispatcher != null ) |
| | 36 | | { |
| 673 | 37 | | UnityEngine.Object.Destroy( dispatcher.gameObject ); |
| 673 | 38 | | dispatcher = null; |
| | 39 | | } |
| 673 | 40 | | } |
| | 41 | |
|
| | 42 | | public void Initialize() |
| | 43 | | { |
| 673 | 44 | | } |
| | 45 | | } |
| | 46 | | } |