| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL |
| | 7 | | { |
| | 8 | | public class WorldState : IWorldState |
| | 9 | | { |
| 1123 | 10 | | public HashSet<string> readyScenes { get; set; } = new HashSet<string>(); |
| 5659 | 11 | | public Dictionary<string, IParcelScene> loadedScenes { get; set; } = new Dictionary<string, IParcelScene>(); |
| 4093 | 12 | | public List<IParcelScene> scenesSortedByDistance { get; set; } = new List<IParcelScene>(); |
| 1177 | 13 | | public List<string> globalSceneIds { get; set; } = new List<string>(); |
| 3103 | 14 | | public string currentSceneId { get; set; } = null; |
| | 15 | |
|
| | 16 | | public IParcelScene GetScene(string id) |
| | 17 | | { |
| 17 | 18 | | if (!Contains(id)) |
| 0 | 19 | | return null; |
| | 20 | |
|
| 17 | 21 | | return loadedScenes[id]; |
| | 22 | | } |
| | 23 | |
|
| | 24 | | public bool Contains(string id) |
| | 25 | | { |
| 430 | 26 | | if (string.IsNullOrEmpty(id) || !loadedScenes.ContainsKey(id)) |
| 0 | 27 | | return false; |
| | 28 | |
|
| 430 | 29 | | return true; |
| | 30 | | } |
| | 31 | |
|
| | 32 | | public bool TryGetScene(string id, out IParcelScene scene) |
| | 33 | | { |
| 15 | 34 | | scene = null; |
| | 35 | |
|
| 15 | 36 | | if (string.IsNullOrEmpty(id) || !loadedScenes.ContainsKey(id)) |
| 7 | 37 | | return false; |
| | 38 | |
|
| 8 | 39 | | scene = loadedScenes[id]; |
| 8 | 40 | | return true; |
| | 41 | | } |
| | 42 | |
|
| | 43 | | public bool TryGetScene<T>(string id, out T scene) |
| | 44 | | where T : class, IParcelScene |
| | 45 | | { |
| 0 | 46 | | scene = default(T); |
| 0 | 47 | | bool result = TryGetScene(id, out IParcelScene baseScene); |
| | 48 | |
|
| 0 | 49 | | if (result) |
| 0 | 50 | | scene = baseScene as T; |
| | 51 | |
|
| 0 | 52 | | if (scene == null) |
| 0 | 53 | | result = false; |
| | 54 | |
|
| 0 | 55 | | return result; |
| | 56 | | } |
| | 57 | |
|
| | 58 | | public HashSet<Vector2Int> GetAllLoadedScenesCoords() |
| | 59 | | { |
| 744 | 60 | | HashSet<Vector2Int> allLoadedParcelCoords = new HashSet<Vector2Int>(); |
| | 61 | |
|
| | 62 | | // Create fast (hashset) collection of loaded parcels coords |
| 1742 | 63 | | foreach (var element in loadedScenes) |
| | 64 | | { |
| 127 | 65 | | ParcelScene scene = element.Value as ParcelScene; |
| | 66 | |
|
| 127 | 67 | | if (!scene.sceneLifecycleHandler.isReady) |
| | 68 | | continue; |
| | 69 | |
|
| 2 | 70 | | allLoadedParcelCoords.UnionWith(scene.parcels); |
| | 71 | | } |
| | 72 | |
|
| 744 | 73 | | return allLoadedParcelCoords; |
| | 74 | | } |
| | 75 | |
|
| | 76 | | public void Dispose() |
| | 77 | | { |
| 734 | 78 | | } |
| | 79 | |
|
| | 80 | | public void Initialize() |
| | 81 | | { |
| 734 | 82 | | } |
| | 83 | | } |
| | 84 | | } |