87 lines
2.2 KiB
C#
87 lines
2.2 KiB
C#
using UnityEngine;
|
|
|
|
public static class MapDatabase {
|
|
private static MapDefinition[] maps;
|
|
|
|
public static MapDefinition[] AllMaps {
|
|
get {
|
|
EnsureMaps();
|
|
return maps;
|
|
}
|
|
}
|
|
|
|
public static MapDefinition GetMap(MapId mapId) {
|
|
EnsureMaps();
|
|
|
|
for(int i = 0; i < maps.Length; i++)
|
|
{
|
|
if(maps[i].mapId == mapId)
|
|
{
|
|
return CloneMap(maps[i]);
|
|
}
|
|
}
|
|
|
|
return CloneMap(maps[0]);
|
|
}
|
|
|
|
public static MapDefinition GetMapByIndex(int mapIndex) {
|
|
EnsureMaps();
|
|
int clampedIndex = Mathf.Clamp(mapIndex, 0, maps.Length - 1);
|
|
return CloneMap(maps[clampedIndex]);
|
|
}
|
|
|
|
public static int GetIndex(MapId mapId) {
|
|
EnsureMaps();
|
|
|
|
for(int i = 0; i < maps.Length; i++)
|
|
{
|
|
if(maps[i].mapId == mapId)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
public static int LastMapIndex {
|
|
get {
|
|
EnsureMaps();
|
|
return maps.Length - 1;
|
|
}
|
|
}
|
|
|
|
private static void EnsureMaps() {
|
|
if(maps != null && maps.Length > 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
maps = new MapDefinition[] {
|
|
TutorialIncheonMap.Create(),
|
|
JapanMap.Create(),
|
|
ChinaMap.Create(),
|
|
AmericaMap.Create()
|
|
};
|
|
}
|
|
|
|
private static MapDefinition CloneMap(MapDefinition source) {
|
|
return new MapDefinition {
|
|
mapId = source.mapId,
|
|
displayName = source.displayName,
|
|
routeName = source.routeName,
|
|
isTutorial = source.isTutorial,
|
|
platformSkin = source.platformSkin,
|
|
backgroundResourcePath = source.backgroundResourcePath,
|
|
finishGateStyle = source.finishGateStyle,
|
|
targetDistance = source.targetDistance,
|
|
timeLimit = source.timeLimit,
|
|
clearMileageReward = source.clearMileageReward,
|
|
hasNextMap = source.hasNextMap,
|
|
nextMapId = source.nextMapId,
|
|
openingSteps = CourseStepFactory.CloneSteps(source.openingSteps),
|
|
loopSteps = CourseStepFactory.CloneSteps(source.loopSteps)
|
|
};
|
|
}
|
|
}
|