37 lines
958 B
C#
37 lines
958 B
C#
using System.Collections.Generic;
|
|
|
|
namespace Game.Room;
|
|
|
|
public interface IRoomManager
|
|
{
|
|
IRoom CreateRoom(RoomType roomType);
|
|
IRoom GetRoom(RoomType roomType);
|
|
void DeleteRoom(RoomType roomType);
|
|
}
|
|
|
|
public class RoomManager : ManagerBase, IRoomManager
|
|
{
|
|
private Dictionary<RoomType, IRoom> _rooms = new Dictionary<RoomType, IRoom>();
|
|
|
|
public IRoom CreateRoom(RoomType roomType)
|
|
{
|
|
if (this._rooms.TryGetValue(roomType, out var room))
|
|
return room;
|
|
|
|
var gameObject = Game.resourceManager.LoadGameObjectSync(roomType.ToString());
|
|
room = new Room(roomType, gameObject);
|
|
this._rooms.Add(roomType, room);
|
|
return room;
|
|
}
|
|
|
|
public IRoom GetRoom(RoomType roomType)
|
|
{
|
|
return this._rooms.GetValueOrDefault(roomType);
|
|
}
|
|
|
|
public void DeleteRoom(RoomType roomType)
|
|
{
|
|
if (this._rooms.TryGetValue(roomType, out var room))
|
|
room.Dispose();
|
|
}
|
|
} |