| | 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 | |
|
| 701 | 13 | | public UpdateEventHandler () |
| | 14 | | { |
| 701 | 15 | | var go = new GameObject("_UpdateDispatcher"); |
| 701 | 16 | | dispatcher = go.AddComponent<UpdateDispatcher>(); |
| 701 | 17 | | } |
| | 18 | |
|
| | 19 | | public void AddListener( IUpdateEventHandler.EventType eventType, Action action ) |
| | 20 | | { |
| 21 | 21 | | Assert.IsTrue( dispatcher != null, "Dispatcher is null! This should never happen!"); |
| 21 | 22 | | dispatcher.eventCollections[eventType].Add(action); |
| 21 | 23 | | } |
| | 24 | |
|
| | 25 | | public void RemoveListener( IUpdateEventHandler.EventType eventType, Action action ) |
| | 26 | | { |
| 21 | 27 | | Assert.IsTrue( dispatcher != null, "Dispatcher is null! This should never happen!"); |
| 21 | 28 | | dispatcher.eventCollections[eventType].Remove(action); |
| 21 | 29 | | } |
| | 30 | |
|
| | 31 | | public void Dispose() |
| | 32 | | { |
| 727 | 33 | | if ( dispatcher != null ) |
| | 34 | | { |
| 701 | 35 | | UnityEngine.Object.Destroy( dispatcher.gameObject ); |
| 701 | 36 | | dispatcher = null; |
| | 37 | | } |
| 727 | 38 | | } |
| | 39 | | } |
| | 40 | | } |