| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using SoftReferenceableAssets; |
| using SoftReferenceableAssets; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class DungeonDB : MonoBehaviour |
| public class DungeonDB : MonoBehaviour |
| { |
| { |
| public static DungeonDB instance |
| public static DungeonDB instance |
| { |
| { |
| get |
| get |
| { |
| { |
| return DungeonDB.m_instance; |
| return DungeonDB.m_instance; |
| } |
| } |
| } |
| } |
| |
| |
| private void Awake() |
| private void Awake() |
| { |
| { |
| DungeonDB.m_instance = this; |
| DungeonDB.m_instance = this; |
| ZLog.Log("DungeonDB Awake " + Time.frameCount.ToString()); |
| ZLog.Log("DungeonDB Awake " + Time.frameCount.ToString()); |
| } |
| } |
| |
| |
| public bool SkipSaving() |
| public bool SkipSaving() |
| { |
| { |
| return this.m_error; |
| return this.m_error; |
| } |
| } |
| |
| |
| private void Start() |
| private void Start() |
| { |
| { |
| ZLog.Log("DungeonDB Start " + Time.frameCount.ToString()); |
| ZLog.Log("DungeonDB Start " + Time.frameCount.ToString()); |
| . | |
| this.SetupRooms(); |
| this.GenerateHashList(); |
| this.GenerateHashList(); |
| this.LoadRooms(); |
| this.LoadRooms(); |
| } |
| } |
| |
| |
| . | |
| private void SetupRooms() |
| |
| { |
| |
| foreach (GameObject gameObject in this.m_roomLists) |
| |
| { |
| |
| UnityEngine.Object.Instantiate<GameObject>(gameObject); |
| |
| } |
| |
| foreach (RoomList roomList in RoomList.GetAllRoomLists()) |
| |
| { |
| |
| this.m_rooms.AddRange(roomList.m_rooms); |
| |
| } |
| |
| } |
| |
| |
| public static List<DungeonDB.RoomData> GetRooms() |
| public static List<DungeonDB.RoomData> GetRooms() |
| { |
| { |
| return DungeonDB.m_instance.m_rooms; |
| return DungeonDB.m_instance.m_rooms; |
| } |
| } |
| |
| |
| public DungeonDB.RoomData GetRoom(int hash) |
| public DungeonDB.RoomData GetRoom(int hash) |
| { |
| { |
| DungeonDB.RoomData roomData; |
| DungeonDB.RoomData roomData; |
| if (this.m_roomByHash.TryGetValue(hash, out roomData)) |
| if (this.m_roomByHash.TryGetValue(hash, out roomData)) |
| { |
| { |
| return roomData; |
| return roomData; |
| } |
| } |
| return null; |
| return null; |
| } |
| } |
| |
| |
| private void GenerateHashList() |
| private void GenerateHashList() |
| { |
| { |
| this.m_roomByHash.Clear(); |
| this.m_roomByHash.Clear(); |
| foreach (DungeonDB.RoomData roomData in this.m_rooms) |
| foreach (DungeonDB.RoomData roomData in this.m_rooms) |
| { |
| { |
| int hash = roomData.Hash; |
| int hash = roomData.Hash; |
| if (this.m_roomByHash.ContainsKey(hash)) |
| if (this.m_roomByHash.ContainsKey(hash)) |
| { |
| { |
| ZLog.LogError("Room with name " + roomData.m_prefab.Name + " already registered"); |
| ZLog.LogError("Room with name " + roomData.m_prefab.Name + " already registered"); |
| } |
| } |
| else |
| else |
| { |
| { |
| this.m_roomByHash.Add(hash, roomData); |
| this.m_roomByHash.Add(hash, roomData); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void LoadRooms() |
| private void LoadRooms() |
| { |
| { |
| if (Settings.AssetMemoryUsagePolicy.HasFlag(AssetMemoryUsagePolicy.KeepAsynchronousLoadedBit)) |
| if (Settings.AssetMemoryUsagePolicy.HasFlag(AssetMemoryUsagePolicy.KeepAsynchronousLoadedBit)) |
| { |
| { |
| ReferenceHolder referenceHolder = base.gameObject.AddComponent<ReferenceHolder>(); |
| ReferenceHolder referenceHolder = base.gameObject.AddComponent<ReferenceHolder>(); |
| foreach (DungeonDB.RoomData roomData in this.m_rooms) |
| foreach (DungeonDB.RoomData roomData in this.m_rooms) |
| { |
| { |
| . | if (roomData.m_prefabData.m_enabled) |
| if (roomData.m_enabled) |
| { |
| { |
| roomData.m_prefab.Load(); |
| roomData.m_prefab.Load(); |
| referenceHolder.HoldReferenceTo(roomData.m_prefab); |
| referenceHolder.HoldReferenceTo(roomData.m_prefab); |
| roomData.m_prefab.Release(); |
| roomData.m_prefab.Release(); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private static DungeonDB m_instance; |
| private static DungeonDB m_instance; |
| |
| |
| public List<string> m_roomScenes = new List<string>(); |
| public List<string> m_roomScenes = new List<string>(); |
| |
| |
| . | public List<DungeonDB.RoomData> m_rooms = new List<DungeonDB.RoomData>(); |
| public List<GameObject> m_roomLists = new List<GameObject>(); |
| |
| |
| |
| private List<DungeonDB.RoomData> m_rooms = new List<DungeonDB.RoomData>(); |
| |
| |
| private Dictionary<int, DungeonDB.RoomData> m_roomByHash = new Dictionary<int, DungeonDB.RoomData>(); |
| private Dictionary<int, DungeonDB.RoomData> m_roomByHash = new Dictionary<int, DungeonDB.RoomData>(); |
| |
| |
| private bool m_error; |
| private bool m_error; |
| |
| |
| [Serializable] |
| [Serializable] |
| public class RoomData |
| public class RoomData |
| { |
| { |
| public Room RoomInPrefab |
| public Room RoomInPrefab |
| { |
| { |
| get |
| get |
| { |
| { |
| if (this.m_loadedRoom == null) |
| if (this.m_loadedRoom == null) |
| { |
| { |
| if (this.m_prefab.Asset != null) |
| if (this.m_prefab.Asset != null) |
| { |
| { |
| this.m_loadedRoom = this.m_prefab.Asset.GetComponent<Room>(); |
| this.m_loadedRoom = this.m_prefab.Asset.GetComponent<Room>(); |
| } |
| } |
| else |
| else |
| { |
| { |
| Debug.LogError(string.Format("Room {0} wasn't loaded!", this.m_prefab)); |
| Debug.LogError(string.Format("Room {0} wasn't loaded!", this.m_prefab)); |
| } |
| } |
| } |
| } |
| return this.m_loadedRoom; |
| return this.m_loadedRoom; |
| } |
| } |
| } |
| } |
| |
| |
| public int Hash |
| public int Hash |
| { |
| { |
| get |
| get |
| { |
| { |
| return this.m_prefab.Name.GetStableHashCode(); |
| return this.m_prefab.Name.GetStableHashCode(); |
| } |
| } |
| } |
| } |
| |
| |
| . | public RoomPrefabData m_prefabData; |
| |
| |
| |
| public SoftReference<GameObject> m_prefab; |
| public SoftReference<GameObject> m_prefab; |
| . | |
| |
| |
| public bool m_enabled; |
| |
| |
| |
| [BitMask(typeof(Room.Theme))] |
| |
| public Room.Theme m_theme; |
| |
| |
| [NonSerialized] |
| [NonSerialized] |
| private Room m_loadedRoom; |
| private Room m_loadedRoom; |
| } |
| } |
| } |
| } |
| |
| |